diff options
Diffstat (limited to 'sampleclient/ConnectionController.m')
| -rwxr-xr-x | sampleclient/ConnectionController.m | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/sampleclient/ConnectionController.m b/sampleclient/ConnectionController.m new file mode 100755 index 0000000..170b0a0 --- /dev/null +++ b/sampleclient/ConnectionController.m @@ -0,0 +1,180 @@ +// +// ConnectionController.m +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import "ConnectionController.h" + +//Make this number larger or smaller to see more or less output in the textview +#define MAX_TEXT_VIEW_CHARACTERS 800 + +@implementation ConnectionController + +#pragma mark waydioDelegate + +- (void)waydio:(Waydio*)waydio OpenStatusChanged:(BOOL)isOpen { + +} +/** + Called when the measured weight changes + @param waydio The Waydio object generating this event + @param weight + */ +- (void)waydio:(Waydio*)waydio WeightChanged:(Float32)weight { + +} +/** + Called when the battery level changes + @param waydio The Waydio object generating this event + @param batteryPercent + */ +- (void)waydio:(Waydio*)waydio BatteryChanged:(Float32)batteryPercent { + +} +/** + Called when the isSending changes + @param waydio The Waydio object generating this event + @param isOpen YES == Pressed + */ +- (void)waydio:(Waydio*)waydio ButtonChanged:(BOOL)isPressed { + +} + +#pragma mark CBCentralManagerDelegate +- (void)centralManagerDidUpdateState:(CBCentralManager *)central { + +} + +- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { + //call the open function to prepare the brsp service + //[self.brspObject open]; +} + +- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { + //[self.brspObject close]; + [self.navigationController popViewControllerAnimated:YES]; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.navigationItem.title = [AppDelegate app].activePeripheral.name; + [_inputText setDelegate:self]; + _allCommands = [NSMutableArray new]; + [self loadCommandArray]; + //_lastMode = BrspModeData; //Default brsp mode +} + +-(void)loadCommandArray { + _allCommands = [NSArray arrayWithObjects: + @"ATMT?", + @"ATV?", + @"ATA?", + @"ATSN?", + @"ATSZ?", + @"ATSFC?", + @"ATSCL?", + @"ATSRM?", + @"ATSDIF?", + @"ATSPL?", + @"ATSUART?", + @"ATSPIO?,0", + @"ATSPIO?,1", + @"ATSPIO?,2", + @"ATSPIO?,3", + @"ATSPIO?,4", + @"ATSPIO?,5", + @"ATSPIO?,6", + @"ATSPIO?,7", + @"ATSPIO?,8", + @"ATSPIO?,9", + @"ATSPIO?,10", + @"ATSPIO?,11", + @"ATSPIO?,12", + @"ATSPIO?,13", + @"ATSPIO?,14", + @"ATSLED?,0", + @"ATSLED?,1", + @"ATSSP?", + @"ATSPK?", + @"ATSDBLE?", + @"ATSBRSP?", + @"ATSDSLE?", + @"ATSDSTLE?", + @"ATSDILE?", + @"ATSDITLE?", + @"ATSDMTLE?", + @"ATSDCP?", + @"ATSPLE?", + //D2 Modules only +// @"ATS?", +// @"ATLCA?", +// @"ATSP?", +// @"ATSCOD?", + nil]; +} + +- (void)viewWillAppear:(BOOL)animated { + [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; + //[self disableButtons]; + [AppDelegate app].cbCentral.delegate = self; + + //init the object with default buffer sizes of 1024 bytes +// 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]; + + //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]; + _outputText = [NSMutableString stringWithCapacity:MAX_TEXT_VIEW_CHARACTERS]; + [super viewWillAppear:animated]; + + //_presses=0; +} + +- (void)viewDidUnload { + [super viewDidUnload]; +} + +- (void)viewWillDisappear:(BOOL)animated { + //call close to disable notifications etc (Not required) + //[brspObject close]; + //Use CBCentralManager to close the connection to this peripheral + [[AppDelegate app].cbCentral cancelPeripheralConnection:[AppDelegate app].activePeripheral]; + [super viewWillDisappear:animated]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + switch(interfaceOrientation) + { + case UIInterfaceOrientationLandscapeLeft: + return NO; + case UIInterfaceOrientationLandscapeRight: + return NO; + default: + return YES; + } +} + + +#pragma mark - UI +- (IBAction)disconnectButton:(id)sender { + /* + //Save the brsp mode so it can be switched back when this process is complete + _lastMode = self.brspObject.brspMode; + if (brspObject.brspMode != BrspModeData) + [self.brspObject changeBrspMode:BrspModeData]; //change brsp mode to data + for (int i=1; i <= 10; i++) { + //Write numbers 1-10 to the device + NSError *error = [self.brspObject writeString:[NSString stringWithFormat:@"%i\r\n", i%10]]; + if (error) + NSLog(@"%@", error.description); + } + */ +} + +@end |
