diff --git a/Brokenithm-iOS.xcodeproj/project.pbxproj b/Brokenithm-iOS.xcodeproj/project.pbxproj index cea0107..a78244c 100644 --- a/Brokenithm-iOS.xcodeproj/project.pbxproj +++ b/Brokenithm-iOS.xcodeproj/project.pbxproj @@ -334,7 +334,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = K9CP5766XY; INFOPLIST_FILE = "Brokenithm-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -357,7 +357,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = K9CP5766XY; INFOPLIST_FILE = "Brokenithm-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/Brokenithm-iOS/SocketDelegate.m b/Brokenithm-iOS/SocketDelegate.m index f2fee2d..c5b71c7 100644 --- a/Brokenithm-iOS/SocketDelegate.m +++ b/Brokenithm-iOS/SocketDelegate.m @@ -38,6 +38,7 @@ NSData *initResp = [initResponse dataUsingEncoding:NSASCIIStringEncoding]; [newSocket writeData:initResp withTimeout:-1 tag:0]; [newSocket readDataToLength:1 withTimeout:5 tag:0]; + [self.parentVc connected]; } - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag {} - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { @@ -72,6 +73,7 @@ { [connectedSockets removeObject:sock]; } + [self.parentVc disconnected]; } } diff --git a/Brokenithm-iOS/ViewController.h b/Brokenithm-iOS/ViewController.h index 0717fde..65001e5 100644 --- a/Brokenithm-iOS/ViewController.h +++ b/Brokenithm-iOS/ViewController.h @@ -23,10 +23,13 @@ } @property UIView *airIOView; @property UIView *sliderIOView; +@property UILabel *connectStatusView; @property CAGradientLayer *ledBackground; -(void)updateLed:(NSData*)rgbData; -(void)updateTouches:(UIEvent *)event; +-(void)connected; +-(void)disconnected; @end diff --git a/Brokenithm-iOS/ViewController.m b/Brokenithm-iOS/ViewController.m index 2f635b2..e0bd7c2 100644 --- a/Brokenithm-iOS/ViewController.m +++ b/Brokenithm-iOS/ViewController.m @@ -8,7 +8,9 @@ #import "ViewController.h" -@interface ViewController () +@interface ViewController () { + BOOL pendingHideStatus; +} @end @@ -16,6 +18,7 @@ - (void)viewDidLoad { [super viewDidLoad]; + pendingHideStatus = NO; // network permission /* @@ -41,6 +44,17 @@ [self.view addSubview:self.airIOView]; [self.view addSubview:self.sliderIOView]; + self.connectStatusView = [[UILabel alloc] initWithFrame:CGRectMake(screenWidth - 200.0, screenHeight * 0.1, 200.0, 50.0)]; + self.connectStatusView.userInteractionEnabled = false; + self.connectStatusView.text = @"Not connected"; + self.connectStatusView.textAlignment = NSTextAlignmentCenter; + self.connectStatusView.textColor = [UIColor whiteColor]; + self.connectStatusView.numberOfLines = 1; + self.connectStatusView.backgroundColor = [UIColor blackColor]; + self.connectStatusView.layer.borderColor = [UIColor whiteColor].CGColor; + self.connectStatusView.layer.borderWidth = 1.0; + [self.view addSubview:self.connectStatusView]; + self.ledBackground = [CAGradientLayer layer]; self.ledBackground.frame = CGRectMake(0, 0, screenWidth, sliderHeight); [self.sliderIOView.layer addSublayer:self.ledBackground]; @@ -164,4 +178,25 @@ [server updateIO:io]; } +-(void)hideStatus { + pendingHideStatus = NO; + [UIView animateWithDuration:0.5 animations:^{ + self.connectStatusView.frame = CGRectMake(self->screenWidth, self->screenHeight * 0.1, 200.0, 50.0); + }]; +} +-(void)connected { + self.connectStatusView.text = @"Connected"; + [self performSelector:@selector(hideStatus) withObject:nil afterDelay:3]; + pendingHideStatus = YES; +} +-(void)disconnected { + if (pendingHideStatus) { + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideStatus) object:nil]; + } + self.connectStatusView.text = @"Not connected"; + [UIView animateWithDuration:0.3 animations:^{ + self.connectStatusView.frame = CGRectMake(self->screenWidth - 200.0, self->screenHeight * 0.1, 200.0, 50.0); + }]; +} + @end