From 31b03c8a1234b966ec56f5da316d93a9259c5d71 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 18 Sep 2013 17:28:16 +0100 Subject: initial commit --- sampleclient/.DS_Store | Bin 0 -> 6148 bytes sampleclient/AppDelegate.h | 21 ++++ sampleclient/AppDelegate.m | 66 ++++++++++ sampleclient/ConnectionController.h | 32 +++++ sampleclient/ConnectionController.m | 180 +++++++++++++++++++++++++++ sampleclient/MainStoryboard.storyboard | 195 ++++++++++++++++++++++++++++++ sampleclient/ScanController.h | 27 +++++ sampleclient/ScanController.m | 158 ++++++++++++++++++++++++ sampleclient/en.lproj/InfoPlist.strings | 2 + sampleclient/main.m | 15 +++ sampleclient/waydio_comms_demo-Info.plist | 58 +++++++++ sampleclient/waydio_comms_demo-Prefix.pch | 15 +++ 12 files changed, 769 insertions(+) create mode 100755 sampleclient/.DS_Store create mode 100755 sampleclient/AppDelegate.h create mode 100755 sampleclient/AppDelegate.m create mode 100755 sampleclient/ConnectionController.h create mode 100755 sampleclient/ConnectionController.m create mode 100755 sampleclient/MainStoryboard.storyboard create mode 100755 sampleclient/ScanController.h create mode 100755 sampleclient/ScanController.m create mode 100755 sampleclient/en.lproj/InfoPlist.strings create mode 100755 sampleclient/main.m create mode 100644 sampleclient/waydio_comms_demo-Info.plist create mode 100644 sampleclient/waydio_comms_demo-Prefix.pch (limited to 'sampleclient') diff --git a/sampleclient/.DS_Store b/sampleclient/.DS_Store new file mode 100755 index 0000000..5008ddf Binary files /dev/null and b/sampleclient/.DS_Store differ diff --git a/sampleclient/AppDelegate.h b/sampleclient/AppDelegate.h new file mode 100755 index 0000000..262717d --- /dev/null +++ b/sampleclient/AppDelegate.h @@ -0,0 +1,21 @@ +// +// AppDelegate.h +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; +@property (strong, nonatomic) CBCentralManager *cbCentral; +@property (strong, nonatomic) CBPeripheral *activePeripheral; + +//Returns a pointer to the shared AppDelegate ++(AppDelegate*)app; + +@end diff --git a/sampleclient/AppDelegate.m b/sampleclient/AppDelegate.m new file mode 100755 index 0000000..1e46e92 --- /dev/null +++ b/sampleclient/AppDelegate.m @@ -0,0 +1,66 @@ +// +// AppDelegate.m +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import "AppDelegate.h" + +@implementation AppDelegate + +@synthesize window = _window; +@synthesize cbCentral; +@synthesize activePeripheral; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + /* + Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + */ +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + /* + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + */ +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + /* + Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + */ +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + /* + Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + */ +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + /* + Called when the application is about to terminate. + Save data if appropriate. + See also applicationDidEnterBackground:. + */ +} + ++(AppDelegate*)app { + return (AppDelegate*)[[UIApplication sharedApplication] delegate]; +} + + +@end diff --git a/sampleclient/ConnectionController.h b/sampleclient/ConnectionController.h new file mode 100755 index 0000000..d8a7755 --- /dev/null +++ b/sampleclient/ConnectionController.h @@ -0,0 +1,32 @@ +// +// ConnectionController.h +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import +#import "AppDelegate.h" +#import "Waydio.h" + +@interface ConnectionController : UIViewController { + UITextField *_inputText; + NSMutableString *_outputText; //used as string data for textView to make string concatenations more efficient + NSArray *_allCommands; //All commands sent by the get settings button + NSMutableArray *_commandQueue; //An array of commands queued for sending +} + +@property (strong, nonatomic) Waydio *waydioObject; +@property (strong, nonatomic) IBOutlet UITextView *textView; + +@property (strong, nonatomic) IBOutlet UIButton *disconnectButton; + +@property (weak, nonatomic) IBOutlet UILabel *weightLabel; +@property (weak, nonatomic) IBOutlet UILabel *weightReading; +@property (weak, nonatomic) IBOutlet UILabel *batteryLabel; +@property (weak, nonatomic) IBOutlet UILabel *batteryReading; + +@property (weak, nonatomic) IBOutlet UILabel *buttonReading; + +@end 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 diff --git a/sampleclient/MainStoryboard.storyboard b/sampleclient/MainStoryboard.storyboard new file mode 100755 index 0000000..908994a --- /dev/null +++ b/sampleclient/MainStoryboard.storyboard @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampleclient/ScanController.h b/sampleclient/ScanController.h new file mode 100755 index 0000000..4d3538b --- /dev/null +++ b/sampleclient/ScanController.h @@ -0,0 +1,27 @@ +// +// ScanController.h +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import +#import "AppDelegate.h" +#import "ConnectionController.h" +#import "Waydio.h" + +@interface ScanController : UIViewController { + IBOutlet UITableView *_deviceTableView; + IBOutlet UIButton *_scanButton; + NSMutableArray *_peripherals; +} + +@property (strong, nonatomic) UITableView* deviceTableView; + +//UI Elements +- (IBAction)startScanButton:(id)sender; +- (IBAction)stopScanButton:(id)sender; +- (void)enableButton:(UIButton*)butt; +- (void)disableButton:(UIButton*)butt; +@end diff --git a/sampleclient/ScanController.m b/sampleclient/ScanController.m new file mode 100755 index 0000000..7d59c2e --- /dev/null +++ b/sampleclient/ScanController.m @@ -0,0 +1,158 @@ +// +// ScanController.m +// sampleterm +// +// Created by Michael Testa on 11/1/12. +// Copyright (c) Blueradios, Inc. All rights reserved. +// + +#import "ScanController.h" + +@implementation ScanController + +@synthesize deviceTableView = _deviceTableView; + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; +} + +#pragma mark - View lifecycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + _peripherals = [NSMutableArray new]; + self.navigationItem.title = @"Select Device"; + [self disableButton:_scanButton]; + [AppDelegate app].cbCentral = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [AppDelegate app].cbCentral.delegate = self; + [super viewWillAppear:animated]; +} + +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; +} + +- (void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; +} + +#pragma mark - Table options + +//********************************************************************************************************************************************************** +//Table Options +//********************************************************************************************************************************************************** +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)TableView numberOfRowsInSection:(NSInteger)section { + return _peripherals.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *CellIdentifier = @"Cell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + } + // Configure the cell. + + CBPeripheral *peripheral = [_peripherals objectAtIndex:indexPath.row]; + + cell.textLabel.text = peripheral.name; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [self performSegueWithIdentifier:@"cellSegue" sender:self]; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + if ([[segue identifier] isEqualToString:@"cellSegue"]) { + [self stopScanButton:nil]; + NSIndexPath *indexPath = [self.deviceTableView indexPathForSelectedRow]; + + [AppDelegate app].activePeripheral = [_peripherals objectAtIndex:indexPath.row]; + [self.deviceTableView deselectRowAtIndexPath:indexPath animated:YES]; + } +} +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {return NO;} + +#pragma mark - UI + +- (void) startScanButton:(id)sender { + [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; + [_peripherals removeAllObjects]; + [self.deviceTableView reloadData]; + [self disableButton:_scanButton]; + [[AppDelegate app].cbCentral scanForPeripheralsWithServices:[NSArray arrayWithObject:[Waydio brspServiceUUID]] options:nil]; +} + +- (void) stopScanButton:(id)sender { + [[AppDelegate app].cbCentral stopScan]; + [self enableButton:_scanButton]; + [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; +} + +- (void)enableButton:(UIButton*)butt { + butt.enabled = YES; + butt.alpha = 1.0; +} + +- (void)disableButton:(UIButton*)butt { + butt.enabled = NO; + butt.alpha = 0.5; +} + +#pragma mark - CBCentralManagerDelegate + +- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { +} +- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { +} +- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { +} +- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { + if (![_peripherals containsObject:peripheral]) { + [_peripherals addObject:peripheral]; + [self.deviceTableView reloadData]; + } +} +-(void)retrieveConnectedPeripherals { +} + +- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripheralslist { +} + +- (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals { +} + +- (void)centralManagerDidUpdateState:(CBCentralManager *)central { + printf("Status of CoreBluetooth central manager changed %d \r\n",central.state); + if (central.state==CBCentralManagerStatePoweredOn) { + [self enableButton:_scanButton]; + } +} +@end diff --git a/sampleclient/en.lproj/InfoPlist.strings b/sampleclient/en.lproj/InfoPlist.strings new file mode 100755 index 0000000..477b28f --- /dev/null +++ b/sampleclient/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/sampleclient/main.m b/sampleclient/main.m new file mode 100755 index 0000000..1f1654c --- /dev/null +++ b/sampleclient/main.m @@ -0,0 +1,15 @@ +// +// main.m +// sampleclient + + +#import + +#import "AppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/sampleclient/waydio_comms_demo-Info.plist b/sampleclient/waydio_comms_demo-Info.plist new file mode 100644 index 0000000..9ad6ac8 --- /dev/null +++ b/sampleclient/waydio_comms_demo-Info.plist @@ -0,0 +1,58 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + waydio + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFiles + + icon.png + icon@2x.png + + CFBundleIcons + + CFBundlePrimaryIcon + + CFBundleIconFiles + + icon.png + icon@2x.png + + UIPrerenderedIcon + + + + CFBundleIdentifier + ${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIMainStoryboardFile + MainStoryboard + UIRequiredDeviceCapabilities + + armv7 + bluetooth-le + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + + + diff --git a/sampleclient/waydio_comms_demo-Prefix.pch b/sampleclient/waydio_comms_demo-Prefix.pch new file mode 100644 index 0000000..e172fd8 --- /dev/null +++ b/sampleclient/waydio_comms_demo-Prefix.pch @@ -0,0 +1,15 @@ +// +// Prefix header for all source files of the 'sampleclient' target in the 'sampleclient' project +// + +#import + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif + -- cgit v1.2.3