From e89f9947ae51eee20902432c4758b2d8e24185ea Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 11 Oct 2013 17:46:32 -0700 Subject: talking to the device --- sampleclient/ConnectionController.m | 56 +++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'sampleclient/ConnectionController.m') diff --git a/sampleclient/ConnectionController.m b/sampleclient/ConnectionController.m index b56f898..c14ca97 100755 --- a/sampleclient/ConnectionController.m +++ b/sampleclient/ConnectionController.m @@ -13,6 +13,13 @@ @implementation ConnectionController +@synthesize textView; +//@synthesize inputText = _inputText; +//@synthesize buttonChangeMode; +//@synthesize buttonSend100; +//@synthesize buttonGetSettings; +@synthesize waydioObject; + #pragma mark waydioDelegate - (void)waydio:(Waydio*)waydio OpenStatusChanged:(BOOL)isOpen { @@ -42,7 +49,7 @@ - (void)waydio:(Waydio*)waydio ButtonChanged:(BOOL)isPressed { } - +/* #pragma mark CBCentralManagerDelegate - (void)centralManagerDidUpdateState:(CBCentralManager *)central { @@ -57,6 +64,7 @@ [self.waydioObject close]; [self.navigationController popViewControllerAnimated:YES]; } + */ - (void)viewDidLoad { [super viewDidLoad]; @@ -119,17 +127,20 @@ - (void)viewWillAppear:(BOOL)animated { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //[self disableButtons]; - [AppDelegate app].cbCentral.delegate = self; + //-------->[AppDelegate app].cbCentral.delegate = self; //init the object with default buffer sizes of 1024 bytes -// self.brspObject = [[Brsp alloc] initWithPeripheral:[AppDelegate app].activePeripheral]; + //self.brspObject = [[Brsp alloc] initWithPeripheral:[AppDelegate app].activePeripheral]; //init with custom buffer sizes //self.brspObject = [[Brsp alloc] initWithPeripheral:[AppDelegate app].activePeripheral InputBufferSize:512 OutputBufferSize:512]; + self.waydioObject = [[Waydio alloc] initWithPeripheral:[AppDelegate app].activePeripheral]; + //[self.waydioObject open]; + //It is important to set this delegate before calling [Brsp open] //self.brspObject.delegate = self; //Use CBCentral Manager to connect this peripheral - [[AppDelegate app].cbCentral connectPeripheral:[AppDelegate app].activePeripheral options:nil]; + //--------->[[AppDelegate app].cbCentral connectPeripheral:[AppDelegate app].activePeripheral options:nil]; _outputText = [NSMutableString stringWithCapacity:MAX_TEXT_VIEW_CHARACTERS]; [super viewWillAppear:animated]; @@ -142,9 +153,9 @@ - (void)viewWillDisappear:(BOOL)animated { //call close to disable notifications etc (Not required) - //[brspObject close]; + [waydioObject close]; //Use CBCentralManager to close the connection to this peripheral - [[AppDelegate app].cbCentral cancelPeripheralConnection:[AppDelegate app].activePeripheral]; + //[[AppDelegate app].cbCentral cancelPeripheralConnection:[AppDelegate app].activePeripheral]; [super viewWillDisappear:animated]; } @@ -160,6 +171,38 @@ } } +#pragma mark - UITextFieldDelegate methods +-(BOOL) textFieldShouldReturn:(UITextField *)textField { + //Write whatever user typed in textfield to brsp peripheral + //NSError *error = [self.brspObject writeString:[NSString stringWithFormat:@"%@\r", textField.text]]; + //if (error) + /// NSLog(@"%@", error.description); + //textField.text = @""; + //[textField resignFirstResponder]; + return YES; +} + +- (void)textFieldDidBeginEditing:(UITextField *)textField { + [self animateTextField:textField up: YES]; +} + +- (void)textFieldDidEndEditing:(UITextField *)textField { + [self animateTextField:textField up: NO]; +} + +- (void) animateTextField:(UITextField*)textField up:(BOOL)up { + const int movementDistance = 170; //will only work on iPhones + const float movementDuration = 0.3f; // + + int movement = (up ? -movementDistance : movementDistance); + + [UIView beginAnimations: @"anim" context: nil]; + [UIView setAnimationBeginsFromCurrentState: YES]; + [UIView setAnimationDuration: movementDuration]; + self.view.frame = CGRectOffset(self.view.frame, 0, movement); + [UIView commitAnimations]; +} + #pragma mark - UI - (IBAction)disconnectButton:(id)sender { @@ -175,6 +218,7 @@ NSLog(@"%@", error.description); } */ + NSLog(@"disconnecting"); } @end -- cgit v1.2.3