Skip to content

Commit 196eca2

Browse files
committed
Restructured, added BLEChat example for OSX 10.9.2.
1 parent 21170d3 commit 196eca2

File tree

49 files changed

+2395
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2395
-14
lines changed

Examples/BLEChat_Central_OSX/BLEChat_Central_OSX.xcodeproj/project.pbxproj

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>net.redbear.${PRODUCT_NAME:rfc1034identifier}</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>${PRODUCT_NAME}</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1</string>
25+
<key>LSMinimumSystemVersion</key>
26+
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
27+
<key>NSHumanReadableCopyright</key>
28+
<string>Copyright © 2014年 RedBear. All rights reserved.</string>
29+
<key>NSMainNibFile</key>
30+
<string>MainMenu</string>
31+
<key>NSPrincipalClass</key>
32+
<string>NSApplication</string>
33+
</dict>
34+
</plist>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Prefix header
3+
//
4+
// The contents of this file are implicitly included at the beginning of every source file.
5+
//
6+
7+
#ifdef __OBJC__
8+
#import <Cocoa/Cocoa.h>
9+
#endif

Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/Base.lproj/MainMenu.xib

Lines changed: 746 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"size" : "16x16",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"size" : "16x16",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"size" : "32x32",
16+
"scale" : "1x"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"size" : "32x32",
21+
"scale" : "2x"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"size" : "128x128",
26+
"scale" : "1x"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"size" : "128x128",
31+
"scale" : "2x"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"size" : "256x256",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"size" : "256x256",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"size" : "512x512",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"size" : "512x512",
51+
"scale" : "2x"
52+
}
53+
],
54+
"info" : {
55+
"version" : 1,
56+
"author" : "xcode"
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// RBLAppDelegate.h
3+
// BLEChat_Central_OSX
4+
//
5+
// Created by Cheong on 14-3-9.
6+
// Copyright (c) 2014年 RedBear. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "BLE.h"
11+
12+
@interface RBLAppDelegate : NSObject <NSApplicationDelegate, BLEDelegate>
13+
{
14+
IBOutlet NSButton *btnConnect;
15+
IBOutlet NSProgressIndicator *indConnect;
16+
IBOutlet NSTextField *lblRSSI;
17+
IBOutlet NSTextField *text;
18+
}
19+
20+
@property (assign) IBOutlet NSWindow *window;
21+
@property (assign) IBOutlet NSTextView *textView;
22+
@property (assign) IBOutlet NSButton *buttonSend;
23+
@property (strong, nonatomic) BLE *ble;
24+
25+
@end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// RBLAppDelegate.m
3+
// BLEChat_Central_OSX
4+
//
5+
// Created by Cheong on 14-3-9.
6+
// Copyright (c) 2014年 RedBear. All rights reserved.
7+
//
8+
9+
#import "RBLAppDelegate.h"
10+
11+
@implementation RBLAppDelegate
12+
13+
@synthesize ble;
14+
15+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
16+
{
17+
// Insert code here to initialize your application
18+
[self.textView setEditable:NO];
19+
20+
ble = [[BLE alloc] init];
21+
[ble controlSetup:1];
22+
ble.delegate = self;
23+
}
24+
25+
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application
26+
{
27+
return YES;
28+
}
29+
30+
-(void) bleDidConnect
31+
{
32+
NSLog(@"->Connected");
33+
34+
btnConnect.title = @"Disconnect";
35+
[indConnect stopAnimation:self];
36+
}
37+
38+
- (void)bleDidDisconnect
39+
{
40+
NSLog(@"->Disconnected");
41+
42+
btnConnect.title = @"Connect";
43+
44+
lblRSSI.stringValue = @"RSSI: -127";
45+
}
46+
47+
-(void) bleDidReceiveData:(unsigned char *)data length:(int)length
48+
{
49+
NSLog(@"Length: %d", length);
50+
51+
NSString *str = [NSString stringWithCString:data encoding:NSUTF8StringEncoding];
52+
53+
static NSMutableString *message;
54+
55+
if (message == nil)
56+
message = [[NSMutableString alloc] initWithString:@""];
57+
58+
[message appendString:str];
59+
[message appendString:@"\n"];
60+
61+
self.textView.string = message;
62+
[self.textView scrollRangeToVisible: NSMakeRange(self.textView.string.length, 0)];
63+
}
64+
65+
-(void) bleDidUpdateRSSI:(NSNumber *) rssi
66+
{
67+
lblRSSI.stringValue = [NSString stringWithFormat:@"RSSI: %@", rssi.stringValue];
68+
}
69+
70+
- (IBAction)btnConnect:(id)sender
71+
{
72+
if (ble.activePeripheral)
73+
if(ble.activePeripheral.isConnected)
74+
{
75+
[[ble CM] cancelPeripheralConnection:[ble activePeripheral]];
76+
return;
77+
}
78+
79+
if (ble.peripherals)
80+
ble.peripherals = nil;
81+
82+
[ble findBLEPeripherals:2];
83+
84+
[NSTimer scheduledTimerWithTimeInterval:(float)2.0 target:self selector:@selector(connectionTimer:) userInfo:nil repeats:NO];
85+
86+
[indConnect startAnimation:self];
87+
}
88+
89+
-(void) connectionTimer:(NSTimer *)timer
90+
{
91+
if (ble.peripherals.count > 0)
92+
{
93+
[ble connectPeripheral:[ble.peripherals objectAtIndex:0]];
94+
}
95+
else
96+
{
97+
[indConnect stopAnimation:self];
98+
}
99+
}
100+
101+
-(IBAction)sendTextOut:(id)sender
102+
{
103+
UInt8 buf[20];
104+
[text.stringValue getCString:buf maxLength:20 encoding:NSUTF8StringEncoding];
105+
106+
NSData *data = [[NSData alloc] initWithBytes:buf length:text.stringValue.length];
107+
[ble write:data];
108+
}
109+
110+
@end

0 commit comments

Comments
 (0)