Skip to content

Commit 06a0c6c

Browse files
committed
Fixed SimpleControls OSX App.
1 parent aba0858 commit 06a0c6c

File tree

6 files changed

+184
-155
lines changed

6 files changed

+184
-155
lines changed

Examples/SimpleControls_OSX/SimpleControls/AppDelegate.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
//
2-
// AppDelegate.h
3-
// SimpleControls
4-
//
5-
// Created by Cheong on 27/10/12.
6-
// Copyright (c) 2012 RedBearLab. All rights reserved.
7-
//
1+
2+
/*
3+
4+
Copyright (c) 2013-2014 RedBearLab
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
12+
*/
813

914
#import <Cocoa/Cocoa.h>
1015
#import "BLE.h"

Examples/SimpleControls_OSX/SimpleControls/AppDelegate.m

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
//
2-
// AppDelegate.m
3-
// SimpleControls
4-
//
5-
// Created by Cheong on 27/10/12.
6-
// Copyright (c) 2012 RedBearLab. All rights reserved.
7-
//
1+
2+
/*
3+
4+
Copyright (c) 2013-2014 RedBearLab
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
12+
*/
813

914
#import "AppDelegate.h"
1015

@@ -15,12 +20,16 @@ @implementation AppDelegate
1520
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
1621
{
1722
ble = [[BLE alloc] init];
18-
[ble controlSetup:1];
23+
[ble controlSetup];
1924
ble.delegate = self;
2025
}
2126

2227
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application
2328
{
29+
if (ble.activePeripheral)
30+
if(ble.activePeripheral.isConnected)
31+
[[ble CM] cancelPeripheralConnection:[ble activePeripheral]];
32+
2433
return YES;
2534
}
2635

@@ -72,14 +81,14 @@ -(void) bleDidReceiveData:(unsigned char *)data length:(int)length
7281
{
7382
NSLog(@"0x%02X, 0x%02X, 0x%02X", data[i], data[i+1], data[i+2]);
7483

75-
if (data[i] == 0x0A)
84+
if (data[i] == 0x0A) // Digital In data
7685
{
7786
if (data[i+1] == 0x01)
7887
lblDigitalIn.stringValue = @"HIGH";
7988
else
8089
lblDigitalIn.stringValue = @"LOW";
8190
}
82-
else if (data[i] == 0x0B)
91+
else if (data[i] == 0x0B) // Analog In data
8392
{
8493
UInt16 Value;
8594

@@ -96,6 +105,8 @@ -(void) bleDidUpdateRSSI:(NSNumber *) rssi
96105

97106
- (IBAction)btnConnect:(id)sender
98107
{
108+
NSLog(@"Clicked");
109+
99110
if (ble.activePeripheral)
100111
if(ble.activePeripheral.isConnected)
101112
{

Examples/SimpleControls_OSX/SimpleControls/BLE/BLE.h

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22
/*
33
4-
Copyright (c) 2012 RedBearLab
4+
Copyright (c) 2013-2014 RedBearLab
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
77
88
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
99
1010
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1111
12-
*/
12+
*/
1313

1414
#import <Foundation/Foundation.h>
1515
#if TARGET_OS_IPHONE
16-
#import <CoreBluetooth/CoreBluetooth.h>
16+
#import <CoreBluetooth/CoreBluetooth.h>
1717
#else
18-
#import <IOBluetooth/IOBluetooth.h>
18+
#import <IOBluetooth/IOBluetooth.h>
1919
#endif
2020

2121
@protocol BLEDelegate
@@ -40,19 +40,16 @@
4040
-(void) read;
4141
-(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data;
4242

43-
-(UInt16) readLibVer;
44-
-(UInt16) readFrameworkVersion;
45-
-(NSString *) readVendorName;
4643
-(BOOL) isConnected;
47-
-(int) readRSSI;
4844
-(void) write:(NSData *)d;
45+
-(void) readRSSI;
4946

50-
-(int) controlSetup:(int) s;
47+
-(void) controlSetup;
5148
-(int) findBLEPeripherals:(int) timeout;
5249
-(void) connectPeripheral:(CBPeripheral *)peripheral;
5350

5451
-(UInt16) swap:(UInt16) s;
55-
-(const char *) centralManagerStateToString:(long)state;
52+
-(const char *) centralManagerStateToString:(int)state;
5653
-(void) scanTimer:(NSTimer *)timer;
5754
-(void) printKnownPeripherals;
5855
-(void) printPeripheralInfo:(CBPeripheral*)peripheral;
@@ -61,11 +58,13 @@
6158
-(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p;
6259
-(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p;
6360
-(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service;
64-
-(const char *) UUIDToString:(CFUUIDRef) UUID;
65-
-(const char *) CBUUIDToString:(CBUUID *) UUID;
61+
62+
//-(NSString *) NSUUIDToString:(NSUUID *) UUID;
63+
-(NSString *) CBUUIDToString:(CBUUID *) UUID;
64+
6665
-(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2;
6766
-(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2;
6867
-(UInt16) CBUUIDToInt:(CBUUID *) UUID;
69-
-(int) UUIDSAreEqual:(CFUUIDRef)u1 u2:(CFUUIDRef)u2;
68+
-(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2;
7069

7170
@end

0 commit comments

Comments
 (0)