├── .gitattributes ├── .gitignore ├── BLEFramework.podspec ├── BLEFramework └── BLE │ ├── BLE.h │ ├── BLE.m │ ├── BLE.swift │ └── BLEDefines.h ├── Examples ├── BLE RGB │ ├── BLE RGB.xcodeproj │ │ └── project.pbxproj │ ├── BLE RGB │ │ ├── BLE RGB-Info.plist │ │ ├── BLE RGB-Prefix.pch │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── ColorPickerClasses │ │ │ ├── ANImageBitmapRep │ │ │ │ ├── ANImageBitmapRep.h │ │ │ │ ├── ANImageBitmapRep.m │ │ │ │ ├── BitmapContextRep.h │ │ │ │ ├── BitmapContextRep.m │ │ │ │ ├── Compatibility │ │ │ │ │ ├── NSImage+ANImageBitmapRep.h │ │ │ │ │ ├── NSImage+ANImageBitmapRep.m │ │ │ │ │ ├── OSCommonImage.h │ │ │ │ │ ├── OSCommonImage.m │ │ │ │ │ ├── UIImage+ANImageBitmapRep.h │ │ │ │ │ └── UIImage+ANImageBitmapRep.m │ │ │ │ ├── CoreGraphics │ │ │ │ │ ├── CGContextCreator.h │ │ │ │ │ ├── CGContextCreator.m │ │ │ │ │ ├── CGImageContainer.h │ │ │ │ │ └── CGImageContainer.m │ │ │ │ └── Manipulators │ │ │ │ │ ├── BitmapContextManipulator.h │ │ │ │ │ ├── BitmapContextManipulator.m │ │ │ │ │ ├── BitmapCropManipulator.h │ │ │ │ │ ├── BitmapCropManipulator.m │ │ │ │ │ ├── BitmapDrawManipulator.h │ │ │ │ │ ├── BitmapDrawManipulator.m │ │ │ │ │ ├── BitmapRotationManipulator.h │ │ │ │ │ ├── BitmapRotationManipulator.m │ │ │ │ │ ├── BitmapScaleManipulator.h │ │ │ │ │ └── BitmapScaleManipulator.m │ │ │ ├── BGRSLoupeLayer.h │ │ │ ├── BGRSLoupeLayer.m │ │ │ ├── RSBrightnessSlider.h │ │ │ ├── RSBrightnessSlider.m │ │ │ ├── RSColorFunctions.h │ │ │ ├── RSColorFunctions.m │ │ │ ├── RSColorPickerView.h │ │ │ ├── RSColorPickerView.m │ │ │ ├── RSGenerateOperation.h │ │ │ ├── RSGenerateOperation.m │ │ │ ├── RSOpacitySlider.h │ │ │ ├── RSOpacitySlider.m │ │ │ ├── RSSelectionView.h │ │ │ └── RSSelectionView.m │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── RBLLightViewController.h │ │ ├── RBLLightViewController.m │ │ ├── RBLViewController.h │ │ ├── RBLViewController.m │ │ ├── RedBearLab.jpg │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ └── main.m │ └── BLE RGBTests │ │ ├── BLE RGBTests-Info.plist │ │ ├── BLE_RGBTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings ├── BLE Select │ ├── BLE Select.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── BLE Select │ │ ├── BLE Select-Info.plist │ │ ├── BLE Select-Prefix.pch │ │ ├── Default-568h@2x.png │ │ ├── Default.png │ │ ├── Default@2x.png │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── RBLDetailViewController.h │ │ ├── RBLDetailViewController.m │ │ ├── en.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── MainStoryboard.storyboard │ │ └── main.m │ ├── BLE │ │ ├── BLE.h │ │ ├── BLE.m │ │ └── BLEDefines.h │ ├── RBLMainViewController.h │ └── RBLMainViewController.m ├── BLEChat_Central_OSX │ ├── BLEChat_Central_OSX.xcodeproj │ │ └── project.pbxproj │ ├── BLEChat_Central_OSX │ │ ├── BLE │ │ │ ├── BLE.h │ │ │ ├── BLE.m │ │ │ └── BLEDefines.h │ │ ├── BLEChat_Central_OSX-Info.plist │ │ ├── BLEChat_Central_OSX-Prefix.pch │ │ ├── Base.lproj │ │ │ └── MainMenu.xib │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── en.lproj │ │ │ ├── Credits.rtf │ │ │ └── InfoPlist.strings │ │ └── main.m │ └── BLEChat_Central_OSXTests │ │ ├── BLEChat_Central_OSXTests-Info.plist │ │ ├── BLEChat_Central_OSXTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings ├── BLEChat_Central_iOS │ ├── BLE │ │ ├── BLE.h │ │ ├── BLE.m │ │ └── BLEDefines.h │ ├── SimpleChat.xcodeproj │ │ └── project.pbxproj │ ├── SimpleChat │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ ├── BrandAsset.launchimage │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── RBLCellTableViewCell.h │ │ ├── RBLCellTableViewCell.m │ │ ├── RBLViewController.h │ │ ├── RBLViewController.m │ │ ├── SimpleChat-Info.plist │ │ ├── SimpleChat-Prefix.pch │ │ ├── apple.png │ │ ├── arduino.png │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ └── main.m │ └── SimpleChatTests │ │ ├── SimpleChatTests-Info.plist │ │ ├── SimpleChatTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings ├── BLEChat_Peripheral_iOS │ ├── BLEChat_Peripheral.xcodeproj │ │ └── project.pbxproj │ ├── BLEChat_Peripheral │ │ ├── BLEChat_Peripheral-Info.plist │ │ ├── BLEChat_Peripheral-Prefix.pch │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── RBLViewController.h │ │ ├── RBLViewController.m │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ └── main.m │ └── BLEChat_PeripheralTests │ │ ├── BLEChat_PeripheralTests-Info.plist │ │ ├── BLEChat_PeripheralTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings ├── BLEController │ ├── BLE │ │ ├── BLE.h │ │ ├── BLE.m │ │ └── BLEDefines.h │ ├── BLEController.xcodeproj │ │ └── project.pbxproj │ ├── BLEController │ │ ├── BLEController-Info.plist │ │ ├── BLEController-Prefix.pch │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── CellPin.h │ │ ├── CellPin.m │ │ ├── CellUuid.h │ │ ├── CellUuid.m │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── BLEController.png │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ ├── BLEController.launch.png │ │ │ │ ├── BLEController.launch.short.png │ │ │ │ └── Contents.json │ │ ├── RBLAppDelegate.h │ │ ├── RBLAppDelegate.m │ │ ├── RBLControlViewController.h │ │ ├── RBLControlViewController.m │ │ ├── RBLDetailViewController.h │ │ ├── RBLDetailViewController.m │ │ ├── RBLMainViewController.h │ │ ├── RBLMainViewController.m │ │ ├── RedBearLab.jpg │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── main.m │ │ └── title.png │ └── RBLProtocol │ │ ├── RBLProtocol.h │ │ └── RBLProtocol.m ├── Readme_Chat.txt ├── Readme_Select.txt ├── Readme_SimpleControls.txt ├── SimpleControls_OSX │ ├── SimpleControls.xcodeproj │ │ └── project.pbxproj │ └── SimpleControls │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── BLE │ │ ├── BLE.h │ │ ├── BLE.m │ │ └── BLEDefines.h │ │ ├── SimpleControls-Info.plist │ │ ├── SimpleControls-Prefix.pch │ │ ├── en.lproj │ │ ├── Credits.rtf │ │ ├── InfoPlist.strings │ │ └── MainMenu.xib │ │ └── main.m └── SimpleControls_iOS │ ├── SimpleControls.xcodeproj │ └── project.pbxproj │ └── SimpleControls │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── BLE │ ├── BLE.h │ ├── BLE.m │ └── BLEDefines.h │ ├── Default-568h@2x.png │ ├── Default.png │ ├── Default@2x.png │ ├── SimpleControls-Info.plist │ ├── SimpleControls-Prefix.pch │ ├── TableViewController.h │ ├── TableViewController.m │ ├── en.lproj │ ├── InfoPlist.strings │ └── MainStoryboard.storyboard │ └── main.m └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://help.github.com/articles/dealing-with-line-endings/ 2 | # Set the default behavior, in case people don't have core.autocrlf set. 3 | * text=auto 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | contents.xcworkspacedata 2 | Examples/BLE RGB/BLE RGB.xcodeproj/project.xcworkspace/xcuserdata 3 | xcuserdata 4 | project.xcworkspace 5 | -------------------------------------------------------------------------------- /BLEFramework.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "BLEFramework" 3 | s.version = "0.0.1" 4 | s.summary = "A framework for developing BLE App on various systems." 5 | s.homepage = "https://github.com/RedBearLab/BLEFramework" 6 | s.author = "RedBearLab" 7 | s.license = "MIT" 8 | s.source = { :git => "https://github.com/RedBearLab/BLEFramework.git", :commit => "master" } 9 | 10 | 11 | s.ios.deployment_target = '5.0' 12 | 13 | s.source_files = 'BLE', 'BLE/**/*.{h,m}' 14 | s.frameworks = 'CoreBluetooth' 15 | end 16 | -------------------------------------------------------------------------------- /BLEFramework/BLE/BLE.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | -(void) bleDidChangeState: (CBManagerState *) state; 28 | @required 29 | @end 30 | 31 | @interface BLE : NSObject { 32 | 33 | } 34 | 35 | @property (nonatomic,assign) id delegate; 36 | @property (strong, nonatomic) NSMutableArray *peripherals; 37 | @property (strong, nonatomic) CBCentralManager *CM; 38 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 39 | 40 | -(void) enableReadNotification:(CBPeripheral *)p; 41 | -(void) read; 42 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 43 | 44 | -(BOOL) isConnected; 45 | -(void) write:(NSData *)d; 46 | -(void) readRSSI; 47 | 48 | -(void) controlSetup; 49 | -(int) findBLEPeripherals:(int) timeout; 50 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 51 | 52 | -(UInt16) swap:(UInt16) s; 53 | -(const char *) centralManagerStateToString:(int)state; 54 | -(void) scanTimer:(NSTimer *)timer; 55 | -(void) printKnownPeripherals; 56 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 57 | 58 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 59 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 60 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 61 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 62 | 63 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 64 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 65 | 66 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 67 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 68 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 69 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /BLEFramework/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/BLE RGB-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/BLE RGB-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/ANImageBitmapRep.h: -------------------------------------------------------------------------------- 1 | // 2 | // ANImageBitmapRep.h 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "OSCommonImage.h" 10 | #import "BitmapScaleManipulator.h" 11 | #import "BitmapCropManipulator.h" 12 | #import "BitmapRotationManipulator.h" 13 | #import "BitmapDrawManipulator.h" 14 | #import "UIImage+ANImageBitmapRep.h" 15 | 16 | typedef struct { 17 | CGFloat red; 18 | CGFloat green; 19 | CGFloat blue; 20 | CGFloat alpha; 21 | } BMPixel; 22 | 23 | BMPixel BMPixelMake (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); 24 | #if TARGET_OS_IPHONE 25 | UIColor * UIColorFromBMPixel (BMPixel pixel); 26 | #elif TARGET_OS_MAC 27 | NSColor * NSColorFromBMPixel (BMPixel pixel); 28 | #endif 29 | 30 | @interface ANImageBitmapRep : BitmapContextRep { 31 | #if __has_feature(objc_arc) == 1 32 | __strong NSArray * baseClasses; 33 | #else 34 | NSArray * baseClasses; 35 | #endif 36 | } 37 | 38 | #if __has_feature(objc_arc) == 1 39 | + (ANImageBitmapRep *)imageBitmapRepWithCGSize:(CGSize)avgSize __attribute__((ns_returns_autoreleased)); 40 | + (ANImageBitmapRep *)imageBitmapRepWithImage:(ANImageObj *)anImage __attribute__((ns_returns_autoreleased)); 41 | #else 42 | + (ANImageBitmapRep *)imageBitmapRepWithCGSize:(CGSize)avgSize; 43 | + (ANImageBitmapRep *)imageBitmapRepWithImage:(ANImageObj *)anImage; 44 | #endif 45 | 46 | /** 47 | * Reverses the RGB values of all pixels in the bitmap. This causes 48 | * an "inverted" effect. 49 | */ 50 | - (void)invertColors; 51 | 52 | /** 53 | * Scales the image down, then back up again. Use this to blur an image. 54 | * @param quality A percentage from 0 to 1, 0 being horrible quality, 1 being 55 | * perfect quality. 56 | */ 57 | - (void)setQuality:(CGFloat)quality; 58 | 59 | /** 60 | * Darken or brighten the image. 61 | * @param brightness A percentage from 0 to 2. In this case, 0 is the darkest 62 | * and 2 is the brightest. If this is 1, no change will be made. 63 | */ 64 | - (void)setBrightness:(CGFloat)brightness; 65 | 66 | /** 67 | * Returns a pixel at a given location. 68 | * @param point The point from which a pixel will be taken. For all points 69 | * in a BitmapContextRep, the x and y values start at 0 and end at 70 | * width - 1 and height - 1 respectively. 71 | * @return The pixel with values taken from the specified point. 72 | */ 73 | - (BMPixel)getPixelAtPoint:(BMPoint)point; 74 | 75 | /** 76 | * Sets a pixel at a specific location. 77 | * @param pixel An RGBA pixel represented by an array of four floats. 78 | * Each component is one float long, and goes from 0 to 1. 79 | * In this case, 0 is black and 1 is white. 80 | * @param point The location of the pixel to change. For all points 81 | * in a BitmapContextRep, the x and y values start at 0 and end at 82 | * width - 1 and height - 1 respectively. 83 | */ 84 | - (void)setPixel:(BMPixel)pixel atPoint:(BMPoint)point; 85 | 86 | /** 87 | * Creates a new UIImage or NSImage from the bitmap context. 88 | */ 89 | #if __has_feature(objc_arc) == 1 90 | - (ANImageObj *)image __attribute__((ns_returns_autoreleased)); 91 | #else 92 | - (ANImageObj *)image; 93 | #endif 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/BitmapContextRep.h: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapContextRep.h 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "OSCommonImage.h" 10 | #import "CGImageContainer.h" 11 | #import "CGContextCreator.h" 12 | 13 | /** 14 | * A structure that defines a point in bitmap space. 15 | * This is similar to the CGPoint structure, but it 16 | * does not use floating points, making it more accurate. 17 | */ 18 | typedef struct { 19 | long x; 20 | long y; 21 | } BMPoint; 22 | 23 | BMPoint BMPointMake (long x, long y); 24 | BMPoint BMPointFromSize (CGSize size); 25 | BMPoint BMPointFromPoint (CGPoint point); 26 | 27 | /** 28 | * BitmapContextRep is a concrete subclass of NSObject that provides a basic 29 | * class for mutating image's bitmaps. This class is very barebones, 30 | * and generally will not be enough for most image manipulation. 31 | */ 32 | @interface BitmapContextRep : NSObject { 33 | CGContextRef context; 34 | CGImageRef lastImage; 35 | unsigned char * bitmapData; 36 | BOOL needsUpdate; 37 | } 38 | 39 | /** 40 | * Creates a bitmap context with pixels and dimensions from an image. 41 | * @param image The image to wrap in a bitmap context. 42 | */ 43 | - (id)initWithImage:(ANImageObj *)image; 44 | 45 | /** 46 | * Creates a blank bitmap context with specified dimensions. 47 | * @param sizePoint The size to use for the new bitmap. The x value 48 | * of this is used for the width, and the y value is used for height. 49 | */ 50 | - (id)initWithSize:(BMPoint)sizePoint; 51 | 52 | /** 53 | * Returns the bitmap context underlying the image. 54 | */ 55 | - (CGContextRef)context; 56 | 57 | /** 58 | * Replaces the current context with a new one. 59 | * @param aContext The new bitmap context for the image which will be retained 60 | * and released automatically by the BitmapContextRep. 61 | */ 62 | - (void)setContext:(CGContextRef)aContext; 63 | 64 | /** 65 | * Returns the current size of the bitmap. 66 | */ 67 | - (BMPoint)bitmapSize; 68 | 69 | /** 70 | * Tells the BitmapContext that a new image should be generated when 71 | * one is requested because the internal context has been externally 72 | * modified. 73 | * @param needsUpdate This should almost always be YES. If this is no, 74 | * a new CGImageRef will not be generated when one is requested. 75 | */ 76 | - (void)setNeedsUpdate:(BOOL)flag; 77 | 78 | /** 79 | * Returns by reference a 4-byte RGBA pixel at a certain point. 80 | * @param rgba A pointer to a 4-byte or more pixel buffer. 81 | * @param point The point from which a pixel will be read. For all 82 | * points in a BitmapContextRep, the x and y values start at 0 and end 83 | * at width - 1 and height - 1 respectively. 84 | */ 85 | - (void)getRawPixel:(UInt8 *)rgba atPoint:(BMPoint)point; 86 | 87 | /** 88 | * Sets a 4-byte ARGB pixel at a specified point. 89 | * @param rgba The pixel buffer containing at least 4 bytes. 90 | * @param point The point at which the pixel will be set. For all 91 | * points in a BitmapContextRep, the x and y values start at 0 and end 92 | * at width - 1 and height - 1 respectively. 93 | * @discussion Since alpha is premultiplied, it is important to remember to multiply 94 | * the alpha as a percentage by the RGB values. This means that a white pixel 95 | * with 50% alpha would become rgba(128, 128, 128, 128). 96 | */ 97 | - (void)setRawPixel:(const UInt8 *)rgba atPoint:(BMPoint)point; 98 | 99 | /** 100 | * Returns an autoreleased CGImageRef of the current BitmapContext. 101 | */ 102 | - (CGImageRef)CGImage; 103 | 104 | @end 105 | 106 | @protocol BitmapContextRep 107 | 108 | @optional 109 | - (CGContextRef)context; 110 | - (void)setContext:(CGContextRef)aContext; 111 | - (BMPoint)bitmapSize; 112 | - (void)setNeedsUpdate:(BOOL)flag; 113 | - (void)getRawPixel:(UInt8 *)rgba atPoint:(BMPoint)point; 114 | - (void)setRawPixel:(const UInt8 *)rgba atPoint:(BMPoint)point; 115 | - (CGImageRef)CGImage; 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/BitmapContextRep.m: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapContextRep.m 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "BitmapContextRep.h" 10 | 11 | BMPoint BMPointMake (long x, long y) { 12 | BMPoint p; 13 | p.x = x; 14 | p.y = y; 15 | return p; 16 | } 17 | 18 | BMPoint BMPointFromSize (CGSize size) { 19 | return BMPointMake(round(size.width), round(size.height)); 20 | } 21 | 22 | BMPoint BMPointFromPoint (CGPoint point) { 23 | return BMPointMake(round(point.x), round(point.y)); 24 | } 25 | 26 | @implementation BitmapContextRep 27 | 28 | - (id)initWithImage:(ANImageObj *)image { 29 | if ((self = [super init])) { 30 | context = [CGContextCreator newARGBBitmapContextWithImage:CGImageFromANImage(image)]; 31 | bitmapData = CGBitmapContextGetData(context); 32 | lastImage = CGBitmapContextCreateImage(context); 33 | } 34 | return self; 35 | } 36 | 37 | - (id)initWithSize:(BMPoint)sizePoint { 38 | if ((self = [super init])) { 39 | if (sizePoint.x == 0 || sizePoint.y == 0) { 40 | #if __has_feature(objc_arc) 41 | return nil; 42 | #else 43 | [super dealloc]; 44 | return nil; 45 | #endif 46 | } 47 | context = [CGContextCreator newARGBBitmapContextWithSize:CGSizeMake(sizePoint.x, sizePoint.y)]; 48 | bitmapData = CGBitmapContextGetData(context); 49 | lastImage = CGBitmapContextCreateImage(context); 50 | } 51 | return self; 52 | } 53 | 54 | - (CGContextRef)context { 55 | return context; 56 | } 57 | 58 | - (void)setContext:(CGContextRef)aContext { 59 | if (context == aContext) return; 60 | // free previous. 61 | CGContextRelease(context); 62 | free(bitmapData); 63 | // create new. 64 | context = CGContextRetain(aContext); 65 | bitmapData = CGBitmapContextGetData(aContext); 66 | [self setNeedsUpdate:YES]; 67 | } 68 | 69 | - (BMPoint)bitmapSize { 70 | BMPoint point; 71 | point.x = (long)CGBitmapContextGetWidth(context); 72 | point.y = (long)CGBitmapContextGetHeight(context); 73 | return point; 74 | } 75 | 76 | - (void)setNeedsUpdate:(BOOL)flag { 77 | needsUpdate = flag; 78 | } 79 | 80 | - (void)getRawPixel:(UInt8 *)rgba atPoint:(BMPoint)point { 81 | size_t width = CGBitmapContextGetWidth(context); 82 | size_t height = CGBitmapContextGetHeight(context); 83 | NSAssert(point.x >= 0 && point.x < width, @"Point must be within bitmap."); 84 | NSAssert(point.y >= 0 && point.y < height, @"Point must be within bitmap."); 85 | unsigned char * argbData = &bitmapData[((point.y * width) + point.x) * 4]; 86 | rgba[0] = argbData[1]; // red 87 | rgba[1] = argbData[2]; // green 88 | rgba[2] = argbData[3]; // blue 89 | rgba[3] = argbData[0]; // alpha 90 | [self setNeedsUpdate:YES]; 91 | } 92 | 93 | - (void)setRawPixel:(const UInt8 *)rgba atPoint:(BMPoint)point { 94 | size_t width = CGBitmapContextGetWidth(context); 95 | size_t height = CGBitmapContextGetHeight(context); 96 | NSAssert(point.x >= 0 && point.x < width, @"Point must be within bitmap."); 97 | NSAssert(point.y >= 0 && point.y < height, @"Point must be within bitmap."); 98 | unsigned char * argbData = &bitmapData[((point.y * width) + point.x) * 4]; 99 | argbData[1] = rgba[0]; // red 100 | argbData[2] = rgba[1]; // green 101 | argbData[3] = rgba[2]; // blue 102 | argbData[0] = rgba[3]; // alpha 103 | [self setNeedsUpdate:YES]; 104 | } 105 | 106 | - (CGImageRef)CGImage { 107 | if (needsUpdate) { 108 | CGImageRelease(lastImage); 109 | lastImage = CGBitmapContextCreateImage(context); 110 | needsUpdate = NO; 111 | } 112 | #if __has_feature(objc_arc) == 1 113 | return (__bridge CGImageRef)CGImageReturnAutoreleased(lastImage); 114 | #else 115 | return (CGImageRef)[[CGImageContainer imageContainerWithImage:lastImage] image]; 116 | #endif 117 | } 118 | 119 | - (void)dealloc { 120 | CGContextRelease(context); 121 | free(bitmapData); 122 | if (lastImage != NULL) { 123 | CGImageRelease(lastImage); 124 | } 125 | #if __has_feature(objc_arc) != 1 126 | [super dealloc]; 127 | #endif 128 | } 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/NSImage+ANImageBitmapRep.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSImage+ANImageBitmapRep.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/23/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE != 1 10 | 11 | #import 12 | 13 | @class ANImageBitmapRep; 14 | 15 | @interface NSImage (ANImageBitmapRep) 16 | 17 | #if __has_feature(objc_arc) == 1 18 | + (NSImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr __attribute__((ns_returns_autoreleased)); 19 | - (ANImageBitmapRep *)imageBitmapRep __attribute__((ns_returns_autoreleased)); 20 | - (NSImage *)imageByScalingToSize:(CGSize)sz __attribute__((ns_returns_autoreleased)); 21 | - (NSImage *)imageFittingFrame:(CGSize)sz __attribute__((ns_returns_autoreleased)); 22 | - (NSImage *)imageFillingFrame:(CGSize)sz __attribute__((ns_returns_autoreleased)); 23 | #else 24 | + (NSImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr; 25 | - (ANImageBitmapRep *)imageBitmapRep; 26 | - (NSImage *)imageByScalingToSize:(CGSize)sz; 27 | - (NSImage *)imageFittingFrame:(CGSize)sz; 28 | - (NSImage *)imageFillingFrame:(CGSize)sz; 29 | #endif 30 | 31 | @end 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/NSImage+ANImageBitmapRep.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSImage+ANImageBitmapRep.m 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/23/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE != 1 10 | 11 | #import "NSImage+ANImageBitmapRep.h" 12 | #import "ANImageBitmapRep.h" 13 | 14 | @implementation NSImage (ANImageBitmapRep) 15 | 16 | 17 | + (NSImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr { 18 | return [ibr image]; 19 | } 20 | 21 | - (ANImageBitmapRep *)imageBitmapRep { 22 | #if __has_feature(objc_arc) == 1 23 | return [[ANImageBitmapRep alloc] initWithImage:self]; 24 | #else 25 | return [[[ANImageBitmapRep alloc] initWithImage:self] autorelease]; 26 | #endif 27 | } 28 | 29 | - (NSImage *)imageByScalingToSize:(CGSize)sz { 30 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 31 | [imageBitmap setSize:BMPointMake(round(sz.width), round(sz.height))]; 32 | NSImage * scaled = [imageBitmap image]; 33 | #if __has_feature(objc_arc) != 1 34 | [imageBitmap release]; 35 | #endif 36 | return scaled; 37 | } 38 | 39 | - (NSImage *)imageFittingFrame:(CGSize)sz { 40 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 41 | [imageBitmap setSizeFittingFrame:BMPointMake(round(sz.width), round(sz.height))]; 42 | NSImage * scaled = [imageBitmap image]; 43 | #if __has_feature(objc_arc) != 1 44 | [imageBitmap release]; 45 | #endif 46 | return scaled; 47 | } 48 | 49 | - (NSImage *)imageFillingFrame:(CGSize)sz { 50 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 51 | [imageBitmap setSizeFillingFrame:BMPointMake(round(sz.width), round(sz.height))]; 52 | NSImage * scaled = [imageBitmap image]; 53 | #if __has_feature(objc_arc) != 1 54 | [imageBitmap release]; 55 | #endif 56 | return scaled; 57 | } 58 | 59 | @end 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/OSCommonImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSCommonImage.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/23/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #ifndef ImageBitmapRep_OSCommonImage_h 10 | #define ImageBitmapRep_OSCommonImage_h 11 | 12 | #import "CGImageContainer.h" 13 | 14 | #if TARGET_OS_IPHONE 15 | #import 16 | typedef UIImage ANImageObj; 17 | #elif TARGET_OS_MAC 18 | #import 19 | typedef NSImage ANImageObj; 20 | #endif 21 | 22 | CGImageRef CGImageFromANImage (ANImageObj * anImageObj); 23 | ANImageObj * ANImageFromCGImage (CGImageRef imageRef); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/OSCommonImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSCommonImage.c 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/23/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include "OSCommonImage.h" 10 | 11 | CGImageRef CGImageFromANImage (ANImageObj * anImageObj) { 12 | #if TARGET_OS_IPHONE 13 | return [anImageObj CGImage]; 14 | #elif TARGET_OS_MAC 15 | CGImageSourceRef source; 16 | #if __has_feature(objc_arc) == 1 17 | source = CGImageSourceCreateWithData((__bridge CFDataRef)[anImageObj TIFFRepresentation], NULL); 18 | #else 19 | source = CGImageSourceCreateWithData((CFDataRef)[anImageObj TIFFRepresentation], NULL); 20 | #endif 21 | CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); 22 | CFRelease(source); 23 | #if __has_feature(objc_arc) == 1 24 | CGImageRef autoreleased = (__bridge CGImageRef)CGImageReturnAutoreleased(maskRef); 25 | CGImageRelease(maskRef); 26 | return autoreleased; 27 | #else 28 | CGImageContainer * container = [CGImageContainer imageContainerWithImage:maskRef]; 29 | CGImageRelease(maskRef); 30 | return [container image]; 31 | #endif 32 | #endif 33 | } 34 | 35 | ANImageObj * ANImageFromCGImage (CGImageRef imageRef) { 36 | #if TARGET_OS_IPHONE 37 | return [UIImage imageWithCGImage:imageRef]; 38 | #elif TARGET_OS_MAC 39 | NSImage * image = [[NSImage alloc] initWithCGImage:imageRef size:NSZeroSize]; 40 | #if __has_feature(objc_arc) == 1 41 | return image; 42 | #else 43 | return [image autorelease]; 44 | #endif 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/UIImage+ANImageBitmapRep.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+ANImageBitmapRep.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 8/11/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | 11 | @class ANImageBitmapRep; 12 | 13 | #import 14 | 15 | @interface UIImage (ANImageBitmapRep) 16 | 17 | #if __has_feature(objc_arc) == 1 18 | + (UIImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr __attribute__((ns_returns_autoreleased)); 19 | - (ANImageBitmapRep *)imageBitmapRep __attribute__((ns_returns_autoreleased)); 20 | - (UIImage *)imageByScalingToSize:(CGSize)sz __attribute__((ns_returns_autoreleased)); 21 | - (UIImage *)imageFittingFrame:(CGSize)sz __attribute__((ns_returns_autoreleased)); 22 | - (UIImage *)imageFillingFrame:(CGSize)sz __attribute__((ns_returns_autoreleased)); 23 | #else 24 | + (UIImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr; 25 | - (ANImageBitmapRep *)imageBitmapRep; 26 | - (UIImage *)imageByScalingToSize:(CGSize)sz; 27 | - (UIImage *)imageFittingFrame:(CGSize)sz; 28 | - (UIImage *)imageFillingFrame:(CGSize)sz; 29 | #endif 30 | 31 | @end 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Compatibility/UIImage+ANImageBitmapRep.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+ANImageBitmapRep.m 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 8/11/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | 11 | #import "UIImage+ANImageBitmapRep.h" 12 | #import "ANImageBitmapRep.h" 13 | 14 | @implementation UIImage (ANImageBitmapRep) 15 | 16 | 17 | + (UIImage *)imageFromImageBitmapRep:(ANImageBitmapRep *)ibr { 18 | return [ibr image]; 19 | } 20 | 21 | - (ANImageBitmapRep *)imageBitmapRep { 22 | #if __has_feature(objc_arc) == 1 23 | return [[ANImageBitmapRep alloc] initWithImage:self]; 24 | #else 25 | return [[[ANImageBitmapRep alloc] initWithImage:self] autorelease]; 26 | #endif 27 | } 28 | 29 | - (UIImage *)imageByScalingToSize:(CGSize)sz { 30 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 31 | [imageBitmap setSize:BMPointMake(round(sz.width), round(sz.height))]; 32 | UIImage * scaled = [imageBitmap image]; 33 | #if __has_feature(objc_arc) != 1 34 | [imageBitmap release]; 35 | #endif 36 | return scaled; 37 | } 38 | 39 | - (UIImage *)imageFittingFrame:(CGSize)sz { 40 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 41 | [imageBitmap setSizeFittingFrame:BMPointMake(round(sz.width), round(sz.height))]; 42 | UIImage * scaled = [imageBitmap image]; 43 | #if __has_feature(objc_arc) != 1 44 | [imageBitmap release]; 45 | #endif 46 | return scaled; 47 | } 48 | 49 | - (UIImage *)imageFillingFrame:(CGSize)sz { 50 | ANImageBitmapRep * imageBitmap = [[ANImageBitmapRep alloc] initWithImage:self]; 51 | [imageBitmap setSizeFillingFrame:BMPointMake(round(sz.width), round(sz.height))]; 52 | UIImage * scaled = [imageBitmap image]; 53 | #if __has_feature(objc_arc) != 1 54 | [imageBitmap release]; 55 | #endif 56 | return scaled; 57 | } 58 | 59 | @end 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGContextCreator.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGContextCreator.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 7/4/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * This class has several static methods for creating bitmap contexts. 13 | * These methods are pretty much only called when creating a new 14 | * ANImageBitmapRep. 15 | */ 16 | @interface CGContextCreator : NSObject { 17 | 18 | } 19 | 20 | + (CGContextRef)newARGBBitmapContextWithSize:(CGSize)size; 21 | + (CGContextRef)newARGBBitmapContextWithImage:(CGImageRef)image; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGContextCreator.m: -------------------------------------------------------------------------------- 1 | // 2 | // CGContextCreator.m 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 7/4/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "CGContextCreator.h" 10 | 11 | 12 | @implementation CGContextCreator 13 | 14 | - (id)init { 15 | if ((self = [super init])) { 16 | // Initialization code here. 17 | } 18 | 19 | return self; 20 | } 21 | 22 | + (CGContextRef)newARGBBitmapContextWithSize:(CGSize)size { 23 | CGContextRef context = NULL; 24 | CGColorSpaceRef colorSpace; 25 | void * bitmapData; 26 | int bitmapByteCount; 27 | int bitmapBytesPerRow; 28 | 29 | // Get image width, height. We'll use the entire image. 30 | size_t pixelsWide = round(size.width); 31 | size_t pixelsHigh = round(size.height); 32 | 33 | bitmapBytesPerRow = (int)(pixelsWide * 4); 34 | bitmapByteCount = (int)(bitmapBytesPerRow * pixelsHigh); 35 | 36 | // Use the generic RGB color space. 37 | colorSpace = CGColorSpaceCreateDeviceRGB(); 38 | if (colorSpace == NULL) { 39 | fprintf(stderr, "Error allocating color space\n"); 40 | return NULL; 41 | } 42 | 43 | // allocate 44 | bitmapData = malloc(bitmapByteCount); 45 | if (bitmapData == NULL) { 46 | NSLog(@"Malloc failed which is too bad. I was hoping to use this memory."); 47 | CGColorSpaceRelease(colorSpace); 48 | // even though CGContextRef technically is not a pointer, 49 | // it's typedef probably is and it is a scalar anyway. 50 | return NULL; 51 | } 52 | 53 | // Create the bitmap context. We are 54 | // setting up the image as an ARGB (0-255 per component) 55 | // 4-byte per/pixel. 56 | context = CGBitmapContextCreate (bitmapData, 57 | pixelsWide, 58 | pixelsHigh, 59 | 8, 60 | bitmapBytesPerRow, 61 | colorSpace, 62 | kCGImageAlphaPremultipliedFirst); 63 | if (context == NULL) { 64 | free (bitmapData); 65 | NSLog(@"Failed to create bitmap!"); 66 | } 67 | 68 | CGContextClearRect(context, CGRectMake(0, 0, size.width, size.height)); 69 | CGColorSpaceRelease(colorSpace); 70 | 71 | return context; 72 | } 73 | 74 | + (CGContextRef)newARGBBitmapContextWithImage:(CGImageRef)image { 75 | CGContextRef context = NULL; 76 | CGColorSpaceRef colorSpace; 77 | void * bitmapData; 78 | int bitmapByteCount; 79 | int bitmapBytesPerRow; 80 | 81 | // Get image width, height. We'll use the entire image. 82 | size_t pixelsWide = CGImageGetWidth(image); 83 | size_t pixelsHigh = CGImageGetHeight(image); 84 | 85 | bitmapBytesPerRow = (int)(pixelsWide * 4); 86 | bitmapByteCount = (int)(bitmapBytesPerRow * pixelsHigh); 87 | 88 | // Use the generic RGB color space. 89 | colorSpace = CGColorSpaceCreateDeviceRGB(); 90 | if (colorSpace == NULL) { 91 | fprintf(stderr, "Error allocating color space\n"); 92 | return NULL; 93 | } 94 | 95 | // allocate 96 | bitmapData = malloc(bitmapByteCount); 97 | if (bitmapData == NULL) { 98 | NSLog(@"Malloc failed which is too bad. I was hoping to use this memory."); 99 | CGColorSpaceRelease(colorSpace); 100 | // even though CGContextRef technically is not a pointer, 101 | // it's typedef probably is and it is a scalar anyway. 102 | return NULL; 103 | } 104 | 105 | // Create the bitmap context. We are 106 | // setting up the image as an ARGB (0-255 per component) 107 | // 4-byte per/pixel. 108 | context = CGBitmapContextCreate (bitmapData, 109 | pixelsWide, 110 | pixelsHigh, 111 | 8, // bits per component 112 | bitmapBytesPerRow, 113 | colorSpace, 114 | kCGImageAlphaPremultipliedFirst); 115 | if (context == NULL) { 116 | free (bitmapData); 117 | NSLog(@"Failed to create bitmap!"); 118 | } 119 | 120 | // draw the image on the context. 121 | // CGContextTranslateCTM(context, 0, CGImageGetHeight(image)); 122 | // CGContextScaleCTM(context, 1.0, -1.0); 123 | CGContextClearRect(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image))); 124 | CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image); 125 | 126 | CGColorSpaceRelease(colorSpace); 127 | 128 | return context; 129 | } 130 | 131 | #if __has_feature(objc_arc) != 1 132 | - (void)dealloc { 133 | [super dealloc]; 134 | } 135 | #endif 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGImageContainer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGImageContainer.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 5/3/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | 10 | #if __has_feature(objc_arc) != 1 11 | 12 | #import 13 | 14 | #if TARGET_OS_IPHONE 15 | #import 16 | #elif TARGET_OS_MAC 17 | #import 18 | #endif 19 | 20 | 21 | @interface CGImageContainer : NSObject { 22 | CGImageRef image; 23 | } 24 | 25 | /** 26 | * The image that this container encloses. 27 | */ 28 | @property (readonly) CGImageRef image; 29 | 30 | /** 31 | * Create a new image container with an image. 32 | * @param anImage Will be retained and enclosed in this class. 33 | * This object will be released when the CGImageContainer is 34 | * deallocated. This can be nil. 35 | * @return The new image container, or nil if anImage is nil. 36 | */ 37 | - (id)initWithImage:(CGImageRef)anImage; 38 | 39 | /** 40 | * Create a new image container with an image. 41 | * @param anImage Will be retained and enclosed in this class. 42 | * This object will be released when the CGImageContainer is 43 | * deallocated. This can be nil. 44 | * @return The new image container, or nil if anImage is nil. 45 | * The image container returned will be autoreleased. 46 | */ 47 | + (CGImageContainer *)imageContainerWithImage:(CGImageRef)anImage; 48 | 49 | @end 50 | 51 | #else 52 | 53 | id CGImageReturnAutoreleased (CGImageRef original) __attribute__((ns_returns_autoreleased)); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGImageContainer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CGImageContainer.m 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 5/3/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "CGImageContainer.h" 10 | 11 | #if __has_feature(objc_arc) != 1 12 | 13 | @implementation CGImageContainer 14 | 15 | @synthesize image; 16 | 17 | - (id)initWithImage:(CGImageRef)anImage { 18 | if ((self = [super init])) { 19 | image = CGImageRetain(anImage); 20 | } 21 | return self; 22 | } 23 | 24 | + (CGImageContainer *)imageContainerWithImage:(CGImageRef)anImage { 25 | CGImageContainer * container = [(CGImageContainer *)[CGImageContainer alloc] initWithImage:anImage]; 26 | return [container autorelease]; 27 | } 28 | 29 | - (void)dealloc { 30 | CGImageRelease(image); 31 | [super dealloc]; 32 | } 33 | 34 | @end 35 | 36 | #else 37 | 38 | __attribute__((ns_returns_autoreleased)) 39 | id CGImageReturnAutoreleased (CGImageRef original) { 40 | // CGImageRetain(original); 41 | return (__bridge id)original; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapContextManipulator.h: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapContextManip.h 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/14/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BitmapContextRep.h" 11 | 12 | @interface BitmapContextManipulator : NSObject { 13 | #if __has_feature(objc_arc) == 1 14 | __unsafe_unretained BitmapContextRep * bitmapContext; 15 | #else 16 | BitmapContextRep * bitmapContext; 17 | #endif 18 | } 19 | 20 | #if __has_feature(objc_arc) == 1 21 | @property (nonatomic, assign) BitmapContextRep * bitmapContext; 22 | #else 23 | @property (nonatomic, assign) BitmapContextRep * bitmapContext; 24 | #endif 25 | 26 | - (id)initWithContext:(BitmapContextRep *)aContext; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapContextManipulator.m: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapContextManip.m 3 | // ImageBitmapRep 4 | // 5 | // Created by Alex Nichol on 10/14/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "BitmapContextManipulator.h" 10 | 11 | @implementation BitmapContextManipulator 12 | 13 | @synthesize bitmapContext; 14 | 15 | - (id)initWithContext:(BitmapContextRep *)aContext { 16 | if ((self = [super init])) { 17 | self.bitmapContext = aContext; 18 | } 19 | return self; 20 | } 21 | 22 | - (void)forwardInvocation:(NSInvocation *)anInvocation { 23 | [anInvocation invokeWithTarget:bitmapContext]; 24 | } 25 | 26 | #if __has_feature(objc_arc) != 1 27 | 28 | - (void)dealloc { 29 | self.bitmapContext = nil; 30 | [super dealloc]; 31 | } 32 | 33 | #endif 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapCropManipulator.h: -------------------------------------------------------------------------------- 1 | // 2 | // CroppableBitmapRep.h 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BitmapContextManipulator.h" 11 | 12 | @protocol BitmapCropManipulator 13 | 14 | @optional 15 | - (void)cropFrame:(CGRect)frame; 16 | - (void)cropTopFrame:(CGRect)frame; 17 | - (void)cropTopEllipse:(CGRect)frame; 18 | - (CGImageRef)croppedImageWithFrame:(CGRect)frame; 19 | 20 | @end 21 | 22 | @interface BitmapCropManipulator : BitmapContextManipulator { 23 | 24 | } 25 | 26 | /** 27 | * Cuts a part of the bitmap out for a new bitmap. 28 | * @param frame The rectangle from which a portion of the image will 29 | * be cut. 30 | * The coordinates for this start at (0,0). 31 | * @discussion The coordinates for this method begin in the bottom 32 | * left corner. For a coordinate system starting from the top 33 | * left corner, use cropTopFrame: instead. 34 | */ 35 | - (void)cropFrame:(CGRect)frame; 36 | 37 | /** 38 | * Cuts a part of the bitmap out for a new bitmap. 39 | * @param frame The rectangle from which a portion of the image will 40 | * be cut. 41 | * The coordinates for this start at (0,0). 42 | * @discussion The coordinates for this method begin in the top 43 | * left corner. For a coordinate system starting from the bottom 44 | * left corner, use cropFrame: instead. 45 | */ 46 | - (void)cropTopFrame:(CGRect)frame; 47 | 48 | /** 49 | * Cuts an ellipse of the bitmap out for a new bitmap. 50 | * @param frame The rectangle around the ellipse to be cut. The 51 | * coordinates for this start at (0,0). 52 | * @discussion The coordinates for this method begin in the top 53 | * left corner. There is no alternative. 54 | */ 55 | - (void)cropTopEllipse:(CGRect)frame; 56 | 57 | /** 58 | * Creates a new CGImageRef by cutting out a portion of this one. 59 | * This takes its behavoir from cropFrame. 60 | * @return An autoreleased CGImageRef that has been cropped from this 61 | * image. 62 | */ 63 | - (CGImageRef)croppedImageWithFrame:(CGRect)frame; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapCropManipulator.m: -------------------------------------------------------------------------------- 1 | // 2 | // CroppableBitmapRep.m 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "BitmapCropManipulator.h" 10 | 11 | 12 | @implementation BitmapCropManipulator 13 | 14 | - (void)cropFrame:(CGRect)frame { 15 | BMPoint size = [bitmapContext bitmapSize]; 16 | // It's kind of rude to prevent them from doing something kind of cool, so let's not. 17 | // NSAssert(frame.origin.x >= 0 && frame.origin.x + frame.size.width <= size.x, @"Cropping frame must be within the bitmap."); 18 | // NSAssert(frame.origin.y >= 0 && frame.origin.y + frame.size.height <= size.y, @"Cropping frame must be within the bitmap."); 19 | 20 | CGContextRef newBitmap = [CGContextCreator newARGBBitmapContextWithSize:frame.size]; 21 | CGPoint offset = CGPointMake(-frame.origin.x, -frame.origin.y); 22 | CGContextDrawImage(newBitmap, CGRectMake(offset.x, offset.y, size.x, size.y), [bitmapContext CGImage]); 23 | [bitmapContext setContext:newBitmap]; 24 | CGContextRelease(newBitmap); 25 | } 26 | 27 | - (void)cropTopFrame:(CGRect)frame { 28 | BMPoint size = [bitmapContext bitmapSize]; 29 | // It's kind of rude to prevent them from doing something kind of cool, so let's not. 30 | // NSAssert(frame.origin.x >= 0 && frame.origin.x + frame.size.width <= size.x, @"Cropping frame must be within the bitmap."); 31 | // NSAssert(frame.origin.y >= 0 && frame.origin.y + frame.size.height <= size.y, @"Cropping frame must be within the bitmap."); 32 | 33 | CGContextRef newBitmap = [CGContextCreator newARGBBitmapContextWithSize:frame.size]; 34 | CGPoint offset = CGPointMake(-frame.origin.x, -(size.y - (frame.origin.y + frame.size.height))); 35 | CGContextDrawImage(newBitmap, CGRectMake(offset.x, offset.y, size.x, size.y), [bitmapContext CGImage]); 36 | [bitmapContext setContext:newBitmap]; 37 | CGContextRelease(newBitmap); 38 | } 39 | 40 | - (void)cropTopEllipse:(CGRect)frame { 41 | frame.origin.x = round(frame.origin.x); 42 | frame.origin.y = round(frame.origin.y); 43 | frame.size.width = round(frame.size.width); 44 | frame.size.height = round(frame.size.height); 45 | 46 | BMPoint size = [bitmapContext bitmapSize]; 47 | // It's kind of rude to prevent them from doing something kind of cool, so let's not. 48 | // NSAssert(frame.origin.x >= 0 && frame.origin.x + frame.size.width <= size.x, @"Cropping frame must be within the bitmap."); 49 | // NSAssert(frame.origin.y >= 0 && frame.origin.y + frame.size.height <= size.y, @"Cropping frame must be within the bitmap."); 50 | 51 | CGContextRef newBitmap = [CGContextCreator newARGBBitmapContextWithSize:frame.size]; 52 | CGPoint offset = CGPointMake(-frame.origin.x, -(size.y - (frame.origin.y + frame.size.height))); 53 | 54 | CGContextSaveGState(newBitmap); 55 | CGContextBeginPath(newBitmap); 56 | CGContextAddEllipseInRect(newBitmap, CGRectMake(0, 0, frame.size.width, frame.size.height)); 57 | CGContextClip(newBitmap); 58 | CGContextDrawImage(newBitmap, CGRectMake(offset.x, offset.y, size.x, size.y), [bitmapContext CGImage]); 59 | CGContextRestoreGState(newBitmap); 60 | 61 | [bitmapContext setContext:newBitmap]; 62 | CGContextRelease(newBitmap); 63 | } 64 | 65 | - (CGImageRef)croppedImageWithFrame:(CGRect)frame { 66 | BMPoint size = [bitmapContext bitmapSize]; 67 | // It's kind of rude to prevent them from doing something kind of cool, so let's not. 68 | // NSAssert(frame.origin.x >= 0 && frame.origin.x + frame.size.width <= size.x, @"Cropping frame must be within the bitmap."); 69 | // NSAssert(frame.origin.y >= 0 && frame.origin.y + frame.size.height <= size.y, @"Cropping frame must be within the bitmap."); 70 | 71 | CGContextRef newBitmap = [CGContextCreator newARGBBitmapContextWithSize:frame.size]; 72 | CGPoint offset = CGPointMake(-frame.origin.x, -frame.origin.y); 73 | CGContextDrawImage(newBitmap, CGRectMake(offset.x, offset.y, size.x, size.y), [bitmapContext CGImage]); 74 | CGImageRef image = CGBitmapContextCreateImage(newBitmap); 75 | CGContextRelease(newBitmap); 76 | #if __has_feature(objc_arc) == 1 77 | CGImageRef retainedAutorelease = (__bridge CGImageRef)CGImageReturnAutoreleased(image); 78 | CGImageRelease(image); 79 | return retainedAutorelease; 80 | #else 81 | CGImageContainer * container = [CGImageContainer imageContainerWithImage:image]; 82 | CGImageRelease(image); 83 | return [container image]; 84 | #endif 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapDrawManipulator.h: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapDrawManipulator.h 3 | // FaceBlur 4 | // 5 | // Created by Alex Nichol on 7/1/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BitmapContextManipulator.h" 11 | 12 | @protocol BitmapDrawManipulator 13 | 14 | @optional 15 | - (void)drawImage:(CGImageRef)image inRect:(CGRect)rect; 16 | - (void)drawEllipseInFrame:(CGRect)frame color:(CGColorRef)color; 17 | 18 | @end 19 | 20 | @interface BitmapDrawManipulator : BitmapContextManipulator 21 | 22 | /** 23 | * Overlays an image on the existing bitmap. 24 | * @param image The image to be overlayed. 25 | * @param rect The frame in which the image will be drawn. 26 | * The coordinates for this begin at the top-left hand 27 | * corner of the view. 28 | */ 29 | - (void)drawImage:(CGImageRef)image inRect:(CGRect)rect; 30 | 31 | /** 32 | * Draws a colored ellipse in a given rectangle. 33 | * @param frame The rectangle in which to draw the ellipse 34 | * @param color The fill color for the ellipse. The coordinates 35 | * for this begin at the top-left hand corner of the view. 36 | */ 37 | - (void)drawEllipseInFrame:(CGRect)frame color:(CGColorRef)color; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapDrawManipulator.m: -------------------------------------------------------------------------------- 1 | // 2 | // BitmapDrawManipulator.m 3 | // FaceBlur 4 | // 5 | // Created by Alex Nichol on 7/1/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "BitmapDrawManipulator.h" 10 | 11 | @implementation BitmapDrawManipulator 12 | 13 | - (void)drawImage:(CGImageRef)image inRect:(CGRect)rect { 14 | BMPoint size = [bitmapContext bitmapSize]; 15 | // It's kind of rude to prevent them from doing something kind of cool, so let's not. 16 | // NSAssert(frame.origin.x >= 0 && frame.origin.x + frame.size.width <= size.x, @"Cropping frame must be within the bitmap."); 17 | // NSAssert(frame.origin.y >= 0 && frame.origin.y + frame.size.height <= size.y, @"Cropping frame must be within the bitmap."); 18 | 19 | CGPoint offset = CGPointMake(rect.origin.x, (size.y - (rect.origin.y + rect.size.height))); 20 | 21 | CGContextRef context = [[self bitmapContext] context]; 22 | CGContextSaveGState(context); 23 | CGContextDrawImage(context, CGRectMake(offset.x, offset.y, rect.size.width, rect.size.height), image); 24 | CGContextRestoreGState(context); 25 | [self.bitmapContext setNeedsUpdate:YES]; 26 | } 27 | 28 | - (void)drawEllipseInFrame:(CGRect)frame color:(CGColorRef)color { 29 | CGContextRef context = [[self bitmapContext] context]; 30 | CGContextSaveGState(context); 31 | CGContextScaleCTM(context, 1, -1); 32 | CGContextTranslateCTM(context, 0, -[bitmapContext bitmapSize].y); 33 | CGContextSetFillColorWithColor(context, color); 34 | CGContextFillEllipseInRect(context, frame); 35 | CGContextRestoreGState(context); 36 | [self.bitmapContext setNeedsUpdate:YES]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapRotationManipulator.h: -------------------------------------------------------------------------------- 1 | // 2 | // RotatableBitmapRep.h 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BitmapContextManipulator.h" 11 | 12 | @protocol BitmapRotationManipulator 13 | 14 | @optional 15 | - (void)rotate:(CGFloat)degrees; 16 | - (CGImageRef)imageByRotating:(CGFloat)degrees; 17 | 18 | @end 19 | 20 | @interface BitmapRotationManipulator : BitmapContextManipulator { 21 | 22 | } 23 | 24 | /** 25 | * Rotate the image bitmap around its center by a certain number of degrees. 26 | * @param degrees The degrees from 0 to 360. This is not measured in radians. 27 | * @discussion This will resize the image if needed. 28 | */ 29 | - (void)rotate:(CGFloat)degrees; 30 | 31 | /** 32 | * Create a new image by rotating this image bitmap around its center by a specified 33 | * number of degrees. 34 | * @param degrees The degrees (not in radians) by which the image should be rotated. 35 | * @discussion This will resize the image if needed. 36 | */ 37 | - (CGImageRef)imageByRotating:(CGFloat)degrees; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapScaleManipulator.h: -------------------------------------------------------------------------------- 1 | // 2 | // ScalableBitmapRep.h 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BitmapContextManipulator.h" 11 | 12 | @protocol BitmapScaleManipulator 13 | 14 | @optional 15 | - (void)setSize:(BMPoint)aSize; 16 | - (void)setSizeFittingFrame:(BMPoint)aSize; 17 | - (void)setSizeFillingFrame:(BMPoint)aSize; 18 | 19 | @end 20 | 21 | @interface BitmapScaleManipulator : BitmapContextManipulator { 22 | 23 | } 24 | 25 | /** 26 | * Stretches the bitmap context to a specified size. 27 | * @param aSize The new size to make the bitmap. 28 | * If this is the same as the current size, the bitmap 29 | * will not be changed. 30 | */ 31 | - (void)setSize:(BMPoint)aSize; 32 | 33 | /** 34 | * Scales the image to fit a particular frame without stretching (bringing out of scale). 35 | * @param aSize The size to which the image scaled. 36 | * @discussion The actual image itself will most likely be smaller than the specified 37 | * size, leaving transparent edges to make the image fit the exact size. 38 | */ 39 | - (void)setSizeFittingFrame:(BMPoint)aSize; 40 | 41 | /** 42 | * Scales the image to fill a particular frame without stretching. 43 | * This will most likely cause the left and right or top and bottom 44 | * edges of the image to be cut off. 45 | * @param aSize The size that the image will be forced to fill. 46 | */ 47 | - (void)setSizeFillingFrame:(BMPoint)aSize; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/ANImageBitmapRep/Manipulators/BitmapScaleManipulator.m: -------------------------------------------------------------------------------- 1 | // 2 | // ScalableBitmapRep.m 3 | // ImageManip 4 | // 5 | // Created by Alex Nichol on 7/12/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "BitmapScaleManipulator.h" 10 | 11 | 12 | @implementation BitmapScaleManipulator 13 | 14 | - (void)setSize:(BMPoint)aSize { 15 | CGContextRef newContext = [CGContextCreator newARGBBitmapContextWithSize:CGSizeMake(aSize.x, aSize.y)]; 16 | CGImageRef image = [bitmapContext CGImage]; 17 | CGContextDrawImage(newContext, CGRectMake(0, 0, aSize.x, aSize.y), image); 18 | [bitmapContext setContext:newContext]; 19 | CGContextRelease(newContext); 20 | } 21 | 22 | - (void)setSizeFittingFrame:(BMPoint)aSize { 23 | CGSize oldSize = CGSizeMake([bitmapContext bitmapSize].x, [bitmapContext bitmapSize].y); 24 | CGSize newSize = CGSizeMake(aSize.x, aSize.y); 25 | 26 | float wratio = newSize.width / oldSize.width; 27 | float hratio = newSize.height / oldSize.height; 28 | float scaleRatio; 29 | if (wratio < hratio) { 30 | scaleRatio = wratio; 31 | } else { 32 | scaleRatio = hratio; 33 | } 34 | scaleRatio = scaleRatio; 35 | 36 | CGSize newContentSize = CGSizeMake(oldSize.width * scaleRatio, oldSize.height * scaleRatio); 37 | CGImageRef image = [bitmapContext CGImage]; 38 | CGContextRef newContext = [CGContextCreator newARGBBitmapContextWithSize:CGSizeMake(aSize.x, aSize.y)]; 39 | CGContextDrawImage(newContext, CGRectMake(newSize.width / 2 - (newContentSize.width / 2), 40 | newSize.height / 2 - (newContentSize.height / 2), 41 | newContentSize.width, newContentSize.height), image); 42 | [bitmapContext setContext:newContext]; 43 | CGContextRelease(newContext); 44 | } 45 | 46 | - (void)setSizeFillingFrame:(BMPoint)aSize { 47 | CGSize oldSize = CGSizeMake([bitmapContext bitmapSize].x, [bitmapContext bitmapSize].y); 48 | CGSize newSize = CGSizeMake(aSize.x, aSize.y); 49 | 50 | float wratio = newSize.width / oldSize.width; 51 | float hratio = newSize.height / oldSize.height; 52 | float scaleRatio; 53 | if (wratio > hratio) { // only difference from -setSizeFittingFrame: 54 | scaleRatio = wratio; 55 | } else { 56 | scaleRatio = hratio; 57 | } 58 | scaleRatio = scaleRatio; 59 | 60 | CGSize newContentSize = CGSizeMake(oldSize.width * scaleRatio, oldSize.height * scaleRatio); 61 | CGImageRef image = [bitmapContext CGImage]; 62 | CGContextRef newContext = [CGContextCreator newARGBBitmapContextWithSize:CGSizeMake(aSize.x, aSize.y)]; 63 | CGContextDrawImage(newContext, CGRectMake(newSize.width / 2 - (newContentSize.width / 2), 64 | newSize.height / 2 - (newContentSize.height / 2), 65 | newContentSize.width, newContentSize.height), image); 66 | [bitmapContext setContext:newContext]; 67 | CGContextRelease(newContext); 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/BGRSLoupeLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * BGRSLoupeLayer.h 3 | * Copyright (c) 2011, Benjamin Guest. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * -Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * -Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * -Neither the name of Benjamin Guest nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #import 32 | #import 33 | 34 | @class RSColorPickerView; 35 | 36 | @interface BGRSLoupeLayer : CALayer { 37 | BOOL isReadyToDismiss; 38 | BOOL isRunningInitialAnimation; 39 | } 40 | 41 | @property (nonatomic) CGPoint loupeCenter; 42 | @property (nonatomic, weak) RSColorPickerView* colorPicker; 43 | 44 | #pragma mark - Drawing 45 | - (void)drawGridInContext:(CGContextRef)ctx; 46 | 47 | #pragma mark - Animation 48 | - (void)appearInColorPicker:(RSColorPickerView*)aColorPicker; 49 | - (void)disappear; 50 | - (void)disappearAnimated:(BOOL)anim; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSBrightnessSlider.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSBrightnessSlider.h 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 8/12/11. 6 | // Copyright 2011 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern CGContextRef RSBitmapContextCreateDefault(CGSize size); 12 | 13 | @class RSColorPickerView; 14 | 15 | @interface RSBrightnessSlider : UISlider 16 | 17 | @property (nonatomic) RSColorPickerView *colorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSColorFunctions.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSColorFunctions.h 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 3/12/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ANImageBitmapRep.h" 11 | 12 | BMPixel RSPixelFromHSV(CGFloat H, CGFloat S, CGFloat V); 13 | void RSHSVFromPixel(BMPixel pixel, CGFloat *h, CGFloat *s, CGFloat *v); 14 | 15 | void RSGetComponentsForColor(float components[3], UIColor *color); 16 | 17 | CGSize RSCGSizeWithScale(CGSize size, CGFloat scale); 18 | CGPoint RSCGPointWithScale(CGPoint point, CGFloat scale); 19 | UIImage* RSUIImageWithScale(UIImage *img, CGFloat scale); 20 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSColorFunctions.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSColorFunctions.m 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 3/12/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import "RSColorFunctions.h" 10 | 11 | BMPixel RSPixelFromHSV(CGFloat H, CGFloat S, CGFloat V) { 12 | if (S == 0) { 13 | return BMPixelMake(V, V, V, 1.0); 14 | } 15 | if (H == 1) { 16 | H = 0; 17 | } 18 | 19 | CGFloat var_h = H * 6.0; 20 | // Verified `H` is never <0 so (int) is OK: 21 | int var_i = (int)var_h; 22 | CGFloat var_1 = V * (1.0 - S); 23 | 24 | if (var_i == 0) { 25 | CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i))); 26 | return BMPixelMake(V, var_3, var_1, 1.0); 27 | } else if (var_i == 1) { 28 | CGFloat var_2 = V * (1.0 - S * (var_h - var_i)); 29 | return BMPixelMake(var_2, V, var_1, 1.0); 30 | } else if (var_i == 2) { 31 | CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i))); 32 | return BMPixelMake(var_1, V, var_3, 1.0); 33 | } else if (var_i == 3) { 34 | CGFloat var_2 = V * (1.0 - S * (var_h - var_i)); 35 | return BMPixelMake(var_1, var_2, V, 1.0); 36 | } else if (var_i == 4) { 37 | CGFloat var_3 = V * (1.0 - S * (1.0 - (var_h - var_i))); 38 | return BMPixelMake(var_3, var_1, V, 1.0); 39 | } 40 | CGFloat var_2 = V * (1.0 - S * (var_h - var_i)); 41 | return BMPixelMake(V, var_1, var_2, 1.0); 42 | } 43 | 44 | 45 | void RSHSVFromPixel(BMPixel pixel, CGFloat *h, CGFloat *s, CGFloat *v) { 46 | UIColor *color = [UIColor colorWithRed:pixel.red green:pixel.green blue:pixel.blue alpha:1]; 47 | [color getHue:h saturation:s brightness:v alpha:NULL]; 48 | } 49 | 50 | void RSGetComponentsForColor(float components[4], UIColor *color) { 51 | CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); 52 | unsigned char resultingPixel[4]; 53 | CGContextRef context = CGBitmapContextCreate(&resultingPixel, 1, 1, 8, 4, rgbColorSpace, kCGImageAlphaPremultipliedLast); 54 | CGContextSetFillColorWithColor(context, [color CGColor]); 55 | CGContextFillRect(context, CGRectMake(0, 0, 1, 1)); 56 | CGContextRelease(context); 57 | CGColorSpaceRelease(rgbColorSpace); 58 | 59 | for (int component = 0; component < 4; component++) { 60 | components[component] = resultingPixel[component] / 255.0f; 61 | } 62 | } 63 | 64 | CGSize RSCGSizeWithScale(CGSize size, CGFloat scale) { 65 | return CGSizeMake(size.width * scale, size.height * scale); 66 | } 67 | CGPoint RSCGPointWithScale(CGPoint point, CGFloat scale) { 68 | return CGPointMake(point.x * scale, point.y * scale); 69 | } 70 | 71 | UIImage* RSUIImageWithScale(UIImage *img, CGFloat scale) { 72 | return [UIImage imageWithCGImage:img.CGImage scale:scale orientation:UIImageOrientationUp]; 73 | } 74 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSColorPickerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSColorPickerView.h 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 8/12/11. 6 | // Copyright 2011 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import "ANImageBitmapRep.h" 13 | 14 | @class RSColorPickerView, BGRSLoupeLayer; 15 | 16 | @protocol RSColorPickerViewDelegate 17 | -(void)colorPickerDidChangeSelection:(RSColorPickerView*)cp; 18 | @end 19 | 20 | @interface RSColorPickerView : UIView 21 | 22 | @property (nonatomic) BOOL cropToCircle; 23 | @property (nonatomic) CGFloat brightness; 24 | @property (nonatomic) CGFloat opacity; 25 | @property (nonatomic) UIColor *selectionColor; 26 | @property (nonatomic, weak) id delegate; 27 | @property (nonatomic, readonly) CGPoint selection; 28 | 29 | @property (nonatomic) int vRed; 30 | @property (nonatomic) int vGreen; 31 | @property (nonatomic) int vBlue; 32 | 33 | -(UIColor*)colorAtPoint:(CGPoint)point; // Returns UIColor at a point in the RSColorPickerView 34 | 35 | +(void)prepareForDiameter:(CGFloat)diameter; 36 | +(void)prepareForDiameter:(CGFloat)diameter padding:(CGFloat)padding; 37 | +(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale; 38 | +(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale padding:(CGFloat)padding; 39 | +(void)prepareForDiameter:(CGFloat)diameter scale:(CGFloat)scale padding:(CGFloat)padding inBackground:(BOOL)bg; 40 | @end 41 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSGenerateOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // GenerateOperation.h 3 | // RSColorPicker 4 | // 5 | // Created by Ryan on 7/22/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class ANImageBitmapRep; 13 | 14 | @interface RSGenerateOperation : NSOperation 15 | 16 | -(id)initWithDiameter:(CGFloat)diameter andPadding:(CGFloat)padding; 17 | 18 | @property (readonly) CGFloat diameter; 19 | @property (readonly) CGFloat padding; 20 | 21 | @property ANImageBitmapRep *bitmap; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSGenerateOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // GenerateOperation.m 3 | // RSColorPicker 4 | // 5 | // Created by Ryan on 7/22/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import "RSGenerateOperation.h" 10 | #import "ANImageBitmapRep.h" 11 | #import "RSColorFunctions.h" 12 | 13 | @implementation RSGenerateOperation 14 | 15 | -(id)init { 16 | if ((self = [super init])) {} 17 | return self; 18 | } 19 | 20 | -(id)initWithDiameter:(CGFloat)diameter andPadding:(CGFloat)padding { 21 | if ((self = [self init])) { 22 | _diameter = diameter; 23 | _padding = padding; 24 | } 25 | return self; 26 | } 27 | 28 | -(void)main { 29 | BMPoint repSize = BMPointMake(_diameter, _diameter); 30 | 31 | // Create fresh 32 | ANImageBitmapRep *rep = [[ANImageBitmapRep alloc] initWithSize:repSize]; 33 | 34 | CGFloat radius = _diameter / 2.0; 35 | CGFloat relRadius = radius - _padding; 36 | CGFloat relX, relY; 37 | 38 | int i, x, y; 39 | int arrSize = powf(_diameter, 2); 40 | size_t arrDataSize = sizeof(float) * arrSize; 41 | 42 | // data 43 | float *preComputeX = (float *)malloc(arrDataSize); 44 | float *preComputeY = (float *)malloc(arrDataSize); 45 | // output 46 | float *atan2Vals = (float *)malloc(arrDataSize); 47 | float *distVals = (float *)malloc(arrDataSize); 48 | 49 | i = 0; 50 | for (x = 0; x < _diameter; x++) { 51 | relX = x - radius; 52 | for (y = 0; y < _diameter; y++) { 53 | relY = radius - y; 54 | 55 | preComputeY[i] = relY; 56 | preComputeX[i] = relX; 57 | i++; 58 | } 59 | } 60 | 61 | // Use Accelerate.framework to compute 62 | vvatan2f(atan2Vals, preComputeY, preComputeX, &arrSize); 63 | vDSP_vdist(preComputeX, 1, preComputeY, 1, distVals, 1, arrSize); 64 | 65 | // Compution done, free these 66 | free(preComputeX); 67 | free(preComputeY); 68 | 69 | i = 0; 70 | for (x = 0; x < _diameter; x++) { 71 | for (y = 0; y < _diameter; y++) { 72 | CGFloat r_distance = fmin(distVals[i], relRadius); 73 | 74 | CGFloat angle = atan2Vals[i]; 75 | if (angle < 0.0) angle = (2.0 * M_PI) + angle; 76 | 77 | CGFloat perc_angle = angle / (2.0 * M_PI); 78 | BMPixel thisPixel = RSPixelFromHSV(perc_angle, r_distance/relRadius, 1); // full brightness 79 | [rep setPixel:thisPixel atPoint:BMPointMake(x, y)]; 80 | 81 | i++; 82 | } 83 | } 84 | 85 | // Bitmap generated, free these 86 | free(atan2Vals); 87 | free(distVals); 88 | 89 | self.bitmap = rep; 90 | } 91 | 92 | -(BOOL)isConcurrent { 93 | return YES; 94 | } 95 | 96 | -(BOOL)isExecuting { 97 | return self.bitmap == nil; 98 | } 99 | -(BOOL)isFinished { 100 | return !self.isExecuting; 101 | } 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSOpacitySlider.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSOpacitySlider.h 3 | // RSColorPicker 4 | // 5 | // Created by Jared Allen on 5/16/13. 6 | // Copyright (c) 2013 Red Cactus LLC. All rights reserved. 7 | // 8 | 9 | #import "RSColorPickerView.h" 10 | 11 | extern UIImage* RSOpacityBackgroundImage(CGFloat length, UIColor *color); 12 | 13 | @interface RSOpacitySlider : UISlider 14 | 15 | @property (nonatomic) RSColorPickerView *colorPicker; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSOpacitySlider.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSOpacitySlider.m 3 | // RSColorPicker 4 | // 5 | // Created by Jared Allen on 5/16/13. 6 | // Copyright (c) 2013 Red Cactus LLC. All rights reserved. 7 | // 8 | 9 | #import "RSOpacitySlider.h" 10 | 11 | /** 12 | * Returns image that looks like a checkered background. 13 | */ 14 | UIImage* RSOpacityBackgroundImage(CGFloat length, UIColor *color) { 15 | UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(0, 0, length*0.5, length*0.5)]; 16 | UIBezierPath* rectangle2Path = [UIBezierPath bezierPathWithRect: CGRectMake(length*0.5, length*0.5, length*0.5, length*0.5)]; 17 | UIBezierPath* rectangle3Path = [UIBezierPath bezierPathWithRect: CGRectMake(0, length*0.5, length*0.5, length*0.5)]; 18 | UIBezierPath* rectangle4Path = [UIBezierPath bezierPathWithRect: CGRectMake(length*0.5, 0, length*0.5, length*0.5)]; 19 | 20 | UIGraphicsBeginImageContext(CGSizeMake(length, length)); 21 | 22 | [color setFill]; 23 | [rectanglePath fill]; 24 | [rectangle2Path fill]; 25 | 26 | [[UIColor whiteColor] setFill]; 27 | [rectangle3Path fill]; 28 | [rectangle4Path fill]; 29 | 30 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 31 | UIGraphicsEndImageContext(); 32 | 33 | return image; 34 | } 35 | 36 | @implementation RSOpacitySlider 37 | 38 | -(id)initWithFrame:(CGRect)frame { 39 | self = [super initWithFrame:frame]; 40 | if (self) { 41 | [self initRoutine]; 42 | } 43 | return self; 44 | } 45 | 46 | - (id)initWithCoder:(NSCoder *)aDecoder { 47 | self = [super initWithCoder:aDecoder]; 48 | if (self) { 49 | [self initRoutine]; 50 | } 51 | return self; 52 | } 53 | 54 | -(void)initRoutine { 55 | self.minimumValue = 0.0; 56 | self.maximumValue = 1.0; 57 | self.continuous = YES; 58 | 59 | self.enabled = YES; 60 | self.userInteractionEnabled = YES; 61 | 62 | UIImage *backgroundImage = RSOpacityBackgroundImage(16.f, [UIColor colorWithWhite:0.5 alpha:1.0]); 63 | self.backgroundColor = [UIColor colorWithPatternImage:backgroundImage]; 64 | [self addTarget:self action:@selector(myValueChanged:) forControlEvents:UIControlEventValueChanged]; 65 | } 66 | 67 | - (CGRect)trackRectForBounds:(CGRect)bounds 68 | { 69 | //to hide the track view 70 | return CGRectMake(0, ceilf(bounds.size.height / 2), bounds.size.width, 0); 71 | } 72 | 73 | -(void)myValueChanged:(id)notif { 74 | _colorPicker.opacity = self.value; 75 | } 76 | 77 | - (void)drawRect:(CGRect)rect 78 | { 79 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 80 | CGColorSpaceRef space = CGColorSpaceCreateDeviceGray(); 81 | NSArray* colors = [[NSArray alloc] initWithObjects: 82 | (id)[UIColor colorWithWhite:0 alpha:0].CGColor, 83 | (id)[UIColor colorWithWhite:1 alpha:1].CGColor,nil]; 84 | 85 | CGGradientRef myGradient = CGGradientCreateWithColors(space, (__bridge CFArrayRef)colors, NULL); 86 | 87 | CGContextDrawLinearGradient(ctx, myGradient, CGPointZero, CGPointMake(rect.size.width, 0), 0); 88 | CGGradientRelease(myGradient); 89 | CGColorSpaceRelease(space); 90 | } 91 | 92 | -(void)setColorPicker:(RSColorPickerView*)cp { 93 | _colorPicker = cp; 94 | if (!_colorPicker) { return; } 95 | self.value = [_colorPicker brightness]; 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSSelectionView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSSelectionView.h 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 3/12/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RSSelectionView : UIView 12 | 13 | @property (nonatomic) UIColor *selectedColor; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/ColorPickerClasses/RSSelectionView.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSSelectionView.m 3 | // RSColorPicker 4 | // 5 | // Created by Ryan Sullivan on 3/12/13. 6 | // Copyright (c) 2013 Freelance Web Developer. All rights reserved. 7 | // 8 | 9 | #import "RSSelectionView.h" 10 | 11 | @interface RSSelectionView () 12 | 13 | @property (nonatomic) UIColor *outerRingColor; 14 | @property (nonatomic) UIColor *innerRingColor; 15 | 16 | @end 17 | 18 | @implementation RSSelectionView 19 | 20 | - (id)initWithFrame:(CGRect)frame 21 | { 22 | self = [super initWithFrame:frame]; 23 | if (self) { 24 | self.opaque = NO; 25 | self.exclusiveTouch = YES; 26 | _outerRingColor = [UIColor colorWithWhite:1 alpha:0.4]; 27 | _innerRingColor = [UIColor colorWithWhite:0 alpha:1]; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)setSelectedColor:(UIColor *)selectedColor 33 | { 34 | _selectedColor = selectedColor; 35 | [self setNeedsDisplay]; 36 | } 37 | 38 | - (void)drawRect:(CGRect)rect 39 | { 40 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 41 | 42 | CGContextSetFillColorWithColor(ctx, _selectedColor.CGColor); 43 | CGContextFillEllipseInRect(ctx, CGRectInset(rect, 2, 2)); 44 | CGContextSetLineWidth(ctx, 3); 45 | CGContextSetStrokeColorWithColor(ctx, _outerRingColor.CGColor); 46 | CGContextStrokeEllipseInRect(ctx, CGRectInset(rect, 1.5, 1.5)); 47 | CGContextSetLineWidth(ctx, 2); 48 | CGContextSetStrokeColorWithColor(ctx, _innerRingColor.CGColor); 49 | CGContextStrokeEllipseInRect(ctx, CGRectInset(rect, 3, 3)); 50 | } 51 | 52 | @end 53 | 54 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RBLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.h 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RBLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RBLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.m 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLAppDelegate.h" 10 | 11 | @implementation RBLAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RBLLightViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLLightViewController.h 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RBLViewController.h" 11 | #import "ColorPickerClasses/RSColorPickerView.h" 12 | 13 | @interface RBLLightViewController : UIViewController 14 | { 15 | UILabel *label; 16 | } 17 | 18 | @property (nonatomic, strong) RBLViewController *vc; 19 | @property (nonatomic) RSColorPickerView *colorPicker; 20 | @property (nonatomic) UIView *colorPatch; 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RBLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLViewController.h 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface RBLViewController : UIViewController 13 | 14 | @property (nonatomic, strong) CBCentralManager *centralManager; 15 | @property (nonatomic, strong) CBPeripheral *peripheral; 16 | @property (nonatomic, strong) CBCharacteristic *txCharacteristic; 17 | 18 | @property (strong, nonatomic) IBOutlet UIButton *connBtn; 19 | @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner; 20 | 21 | - (IBAction)doConnBtn:(id)sender; 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RBLViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLViewController.m 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLViewController.h" 10 | #import "RBLLightViewController.h" 11 | 12 | #define RBL_SERVICE_UUID @"713d0000-503e-4c75-ba94-3148f18d941e" 13 | #define RBL_TX_UUID @"713d0003-503e-4c75-ba94-3148f18d941e" 14 | 15 | @interface RBLViewController () 16 | 17 | @end 18 | 19 | @implementation RBLViewController 20 | 21 | - (void)viewDidLoad 22 | { 23 | [super viewDidLoad]; 24 | // Do any additional setup after loading the view, typically from a nib. 25 | 26 | self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning 30 | { 31 | [super didReceiveMemoryWarning]; 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | - (IBAction)doConnBtn:(id)sender 36 | { 37 | if (self.peripheral.state == CBPeripheralStateConnected) { 38 | [self.centralManager cancelPeripheralConnection:self.peripheral]; 39 | } else { 40 | [self.centralManager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:RBL_SERVICE_UUID]] options:nil]; 41 | [self.connBtn setTitle:@"Connecting" forState:UIControlStateNormal]; 42 | [self.connBtn setEnabled:NO]; 43 | [self.spinner startAnimating]; 44 | } 45 | } 46 | 47 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 48 | { 49 | if ([segue.identifier isEqualToString:@"gotoLight"]) { 50 | NSLog(@"gotoLight"); 51 | RBLLightViewController *lightView = [segue destinationViewController]; 52 | lightView.vc = self; 53 | } 54 | } 55 | 56 | #pragma mark - delegate 57 | - (void)centralManagerDidUpdateState:(CBCentralManager *)central 58 | { 59 | 60 | } 61 | 62 | - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI 63 | { 64 | NSLog(@"discover peripheral"); 65 | 66 | [self.centralManager stopScan]; 67 | 68 | if (self.peripheral != peripheral) { 69 | self.peripheral = peripheral; 70 | 71 | [self.centralManager connectPeripheral:self.peripheral options:nil]; 72 | } 73 | 74 | } 75 | 76 | - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral 77 | { 78 | NSLog(@"connect peripheral"); 79 | 80 | self.peripheral.delegate = self; 81 | 82 | [self.peripheral discoverServices:nil]; 83 | } 84 | 85 | - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error 86 | { 87 | NSLog(@"disconnect"); 88 | 89 | self.peripheral = nil; 90 | self.txCharacteristic = nil; 91 | 92 | [self.connBtn setTitle:@"Connect" forState:UIControlStateNormal]; 93 | [self.connBtn setEnabled:YES]; 94 | [self.spinner stopAnimating]; 95 | 96 | [[self navigationController] popToRootViewControllerAnimated:(TRUE)]; 97 | } 98 | 99 | - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error 100 | { 101 | NSLog(@"discover service"); 102 | 103 | for (int i = 0; i < peripheral.services.count; i++) { 104 | [self.peripheral discoverCharacteristics:nil forService:[peripheral.services objectAtIndex:i]]; 105 | } 106 | } 107 | 108 | - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error 109 | { 110 | NSLog(@"discover characteristic"); 111 | 112 | for (CBCharacteristic *c in service.characteristics) { 113 | if ([c.UUID isEqual:[CBUUID UUIDWithString:RBL_TX_UUID]]) { 114 | [self.connBtn setTitle:@"Disconnect" forState:UIControlStateNormal]; 115 | [self.connBtn setEnabled:YES]; 116 | [self.spinner stopAnimating]; 117 | 118 | self.txCharacteristic = c; 119 | 120 | [self performSegueWithIdentifier:@"gotoLight" sender:self]; 121 | } 122 | } 123 | } 124 | 125 | - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error 126 | { 127 | 128 | } 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/RedBearLab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLE RGB/BLE RGB/RedBearLab.jpg -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGB/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BLE RGB 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "RBLAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([RBLAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGBTests/BLE RGBTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGBTests/BLE_RGBTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BLE_RGBTests.m 3 | // BLE RGBTests 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BLE_RGBTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation BLE_RGBTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLE RGB/BLE RGBTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/BLE Select-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.redbearlab.SDK.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/BLE Select-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'BLE Select' target in the 'BLE Select' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLE Select/BLE Select/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLE Select/BLE Select/Default.png -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLE Select/BLE Select/Default@2x.png -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/RBLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.h 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RBLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/RBLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.m 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | #import "RBLAppDelegate.h" 10 | 11 | @implementation RBLAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/RBLDetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLDetailViewController.h 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol RBLDetailViewControllerDelegate 12 | 13 | // recipe == nil on cancel 14 | - (void) didSelected:(NSInteger)selected; 15 | 16 | @end 17 | 18 | @interface RBLDetailViewController : UITableViewController 19 | { 20 | int selected; 21 | } 22 | 23 | @property (strong,nonatomic) NSArray *BLEDevices; 24 | 25 | @property (nonatomic, weak) id delegate; 26 | 27 | 28 | @end 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/RBLDetailViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLDetailViewController.m 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | 10 | #import "RBLDetailViewController.h" 11 | #import "RBLMainViewController.h" 12 | 13 | @interface RBLDetailViewController () { 14 | //NSMutableArray *_objects; 15 | } 16 | @end 17 | 18 | @implementation RBLDetailViewController 19 | 20 | /* 21 | - (void)awakeFromNib 22 | { 23 | [super awakeFromNib]; 24 | } 25 | */ 26 | 27 | - (void)viewDidLoad 28 | { 29 | [super viewDidLoad]; 30 | // Do any additional setup after loading the view, typically from a nib. 31 | //self.navigationItem.leftBarButtonItem = self.editButtonItem; 32 | 33 | //UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; 34 | //self.navigationItem.rightBarButtonItem = addButton; 35 | } 36 | 37 | - (void)didReceiveMemoryWarning 38 | { 39 | [super didReceiveMemoryWarning]; 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | /* 44 | - (void)insertNewObject:(id)sender 45 | { 46 | if (!_objects) { 47 | _objects = [[NSMutableArray alloc] init]; 48 | } 49 | [_objects insertObject:[NSDate date] atIndex:0]; 50 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 51 | [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 52 | } 53 | */ 54 | 55 | #pragma mark - Table View 56 | 57 | /* 58 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 59 | { 60 | return 1; 61 | } 62 | */ 63 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 64 | { 65 | return self.BLEDevices.count; 66 | } 67 | 68 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 69 | { 70 | /* 71 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 72 | 73 | NSDate *object = _objects[indexPath.row]; 74 | cell.textLabel.text = [object description]; 75 | return cell; 76 | */ 77 | 78 | static NSString *tableIdentifier = @"Cell"; 79 | 80 | //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 81 | 82 | 83 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier forIndexPath:indexPath]; 84 | 85 | /* 86 | if (cell == nil) { 87 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 88 | } 89 | */ 90 | cell.textLabel.text = [self.BLEDevices objectAtIndex:indexPath.row]; 91 | return cell; 92 | 93 | 94 | } 95 | 96 | 97 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 98 | 99 | //NSLog(@"Selected > %d", indexPath.row); 100 | // RBLMainViewController *vc = [segue sourceViewController]; 101 | //selected = indexPath.row; 102 | //[self performSegueWithIdentifier:@"showDevice" sender:self]; 103 | 104 | 105 | // [self.navigationController popViewControllerAnimated:YES]; 106 | 107 | [self.delegate didSelected:indexPath.row]; 108 | 109 | [self.navigationController popViewControllerAnimated:YES]; 110 | } 111 | 112 | /* 113 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 114 | { 115 | if ([[segue identifier] isEqualToString:@"showDevice"]) { 116 | RBLMainViewController *vc =[segue sourceViewController] ; 117 | vc.selected = selected; } 118 | } 119 | */ 120 | 121 | /* 122 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 123 | { 124 | // Return NO if you do not want the specified item to be editable. 125 | return YES; 126 | } 127 | 128 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 129 | { 130 | if (editingStyle == UITableViewCellEditingStyleDelete) { 131 | [_objects removeObjectAtIndex:indexPath.row]; 132 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 133 | } else if (editingStyle == UITableViewCellEditingStyleInsert) { 134 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 135 | } 136 | } 137 | */ 138 | /* 139 | // Override to support rearranging the table view. 140 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 141 | { 142 | } 143 | */ 144 | 145 | /* 146 | // Override to support conditional rearranging of the table view. 147 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 148 | { 149 | // Return NO if you do not want the item to be re-orderable. 150 | return YES; 151 | } 152 | */ 153 | /* 154 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 155 | { 156 | if ([[segue identifier] isEqualToString:@"showDetail"]) { 157 | NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 158 | NSDate *object = _objects[indexPath.row]; 159 | [[segue destinationViewController] setDetailItem:object]; 160 | } 161 | } 162 | */ 163 | @end 164 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE Select/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "RBLAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([RBLAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE/BLE.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) CBCentralManager *CM; 37 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 38 | 39 | -(void) enableReadNotification:(CBPeripheral *)p; 40 | -(void) read; 41 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 42 | 43 | -(BOOL) isConnected; 44 | -(void) write:(NSData *)d; 45 | -(void) readRSSI; 46 | 47 | -(void) controlSetup; 48 | -(int) findBLEPeripherals:(int) timeout; 49 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 50 | 51 | -(UInt16) swap:(UInt16) s; 52 | -(const char *) centralManagerStateToString:(int)state; 53 | -(void) scanTimer:(NSTimer *)timer; 54 | -(void) printKnownPeripherals; 55 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 56 | 57 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 58 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 59 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 60 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 61 | 62 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 63 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 64 | 65 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 66 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 67 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 68 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Examples/BLE Select/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/BLE Select/RBLMainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLMainViewController.h 3 | // BLE Select 4 | // 5 | // Created by Chi-Hung Ma on 4/24/13. 6 | // Copyright (c) 2013 RedBearlab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BLE.h" 11 | #import "RBLDetailViewController.h" 12 | 13 | @interface RBLMainViewController : UIViewController 14 | { 15 | BLE *bleShield; 16 | bool isFindingLast; 17 | } 18 | 19 | @property (strong,nonatomic) NSMutableArray *mDevices; 20 | @property (strong,nonatomic) NSString *lastUUID; 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/BLE/BLE.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) CBCentralManager *CM; 37 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 38 | 39 | -(void) enableReadNotification:(CBPeripheral *)p; 40 | -(void) read; 41 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 42 | 43 | -(BOOL) isConnected; 44 | -(void) write:(NSData *)d; 45 | -(void) readRSSI; 46 | 47 | -(void) controlSetup; 48 | -(int) findBLEPeripherals:(int) timeout; 49 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 50 | 51 | -(UInt16) swap:(UInt16) s; 52 | -(const char *) centralManagerStateToString:(int)state; 53 | -(void) scanTimer:(NSTimer *)timer; 54 | -(void) printKnownPeripherals; 55 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 56 | 57 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 58 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 59 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 60 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 61 | 62 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 63 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 64 | 65 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 66 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 67 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 68 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/BLEChat_Central_OSX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | net.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2014年 RedBear. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/BLEChat_Central_OSX-Prefix.pch: -------------------------------------------------------------------------------- 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 9 | #endif 10 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/RBLAppDelegate.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "BLE.h" 16 | 17 | @interface RBLAppDelegate : NSObject 18 | { 19 | IBOutlet NSButton *btnConnect; 20 | IBOutlet NSProgressIndicator *indConnect; 21 | IBOutlet NSTextField *lblRSSI; 22 | IBOutlet NSTextField *text; 23 | } 24 | 25 | @property (assign) IBOutlet NSWindow *window; 26 | @property (assign) IBOutlet NSTextView *textView; 27 | @property (assign) IBOutlet NSButton *buttonSend; 28 | @property (strong, nonatomic) BLE *ble; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/RBLAppDelegate.m: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import "RBLAppDelegate.h" 15 | 16 | @implementation RBLAppDelegate 17 | 18 | @synthesize ble; 19 | 20 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 21 | { 22 | // Insert code here to initialize your application 23 | [self.textView setEditable:NO]; 24 | 25 | ble = [[BLE alloc] init]; 26 | [ble controlSetup]; 27 | ble.delegate = self; 28 | } 29 | 30 | - (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application 31 | { 32 | return YES; 33 | } 34 | 35 | -(void) bleDidConnect 36 | { 37 | NSLog(@"->Connected"); 38 | 39 | btnConnect.title = @"Disconnect"; 40 | [indConnect stopAnimation:self]; 41 | 42 | [ble readRSSI]; 43 | } 44 | 45 | - (void)bleDidDisconnect 46 | { 47 | NSLog(@"->Disconnected"); 48 | 49 | btnConnect.title = @"Connect"; 50 | 51 | lblRSSI.stringValue = @"RSSI: -127"; 52 | } 53 | 54 | -(void) bleDidReceiveData:(unsigned char *)data length:(int)length 55 | { 56 | NSLog(@"Length: %d", length); 57 | 58 | data[length] = 0; 59 | NSString *str = [NSString stringWithCString:data encoding:NSUTF8StringEncoding]; 60 | 61 | 62 | NSLog(@"%@", str); 63 | 64 | static NSMutableString *message; 65 | 66 | if (message == nil) 67 | message = [[NSMutableString alloc] initWithString:@""]; 68 | 69 | [message appendString:str]; 70 | [message appendString:@"\n"]; 71 | 72 | self.textView.string = message; 73 | [self.textView scrollRangeToVisible: NSMakeRange(self.textView.string.length, 0)]; 74 | } 75 | 76 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi 77 | { 78 | lblRSSI.stringValue = [NSString stringWithFormat:@"RSSI: %@", rssi.stringValue]; 79 | } 80 | 81 | - (IBAction)btnConnect:(id)sender 82 | { 83 | if (ble.activePeripheral) 84 | if(ble.activePeripheral.isConnected) 85 | { 86 | [[ble CM] cancelPeripheralConnection:[ble activePeripheral]]; 87 | return; 88 | } 89 | 90 | if (ble.peripherals) 91 | ble.peripherals = nil; 92 | 93 | [ble findBLEPeripherals:2]; 94 | 95 | [NSTimer scheduledTimerWithTimeInterval:(float)2.0 target:self selector:@selector(connectionTimer:) userInfo:nil repeats:NO]; 96 | 97 | [indConnect startAnimation:self]; 98 | } 99 | 100 | -(void) connectionTimer:(NSTimer *)timer 101 | { 102 | if (ble.peripherals.count > 0) 103 | { 104 | [ble connectPeripheral:[ble.peripherals objectAtIndex:0]]; 105 | } 106 | else 107 | { 108 | [indConnect stopAnimation:self]; 109 | } 110 | } 111 | 112 | -(IBAction)sendTextOut:(id)sender 113 | { 114 | UInt8 buf[20]; 115 | [text.stringValue getCString:buf maxLength:20 encoding:NSUTF8StringEncoding]; 116 | 117 | NSData *data = [[NSData alloc] initWithBytes:buf length:text.stringValue.length]; 118 | [ble write:data]; 119 | } 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSX/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.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 10 | 11 | int main(int argc, const char * argv[]) 12 | { 13 | return NSApplicationMain(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSXTests/BLEChat_Central_OSXTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | net.redbear.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSXTests/BLEChat_Central_OSXTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BLEChat_Central_OSXTests.m 3 | // BLEChat_Central_OSXTests 4 | // 5 | // Created by Cheong on 14-3-9. 6 | // Copyright (c) 2014年 RedBear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BLEChat_Central_OSXTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation BLEChat_Central_OSXTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_OSX/BLEChat_Central_OSXTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/BLE/BLE.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) NSMutableArray *peripheralsRssi; 37 | @property (strong, nonatomic) CBCentralManager *CM; 38 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 39 | 40 | -(void) enableReadNotification:(CBPeripheral *)p; 41 | -(void) read; 42 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 43 | 44 | -(BOOL) isConnected; 45 | -(void) write:(NSData *)d; 46 | -(void) readRSSI; 47 | 48 | -(void) controlSetup; 49 | -(int) findBLEPeripherals:(int) timeout; 50 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 51 | 52 | -(UInt16) swap:(UInt16) s; 53 | -(const char *) centralManagerStateToString:(int)state; 54 | -(void) scanTimer:(NSTimer *)timer; 55 | -(void) printKnownPeripherals; 56 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 57 | 58 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 59 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 60 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 61 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 62 | 63 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 64 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 65 | 66 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 67 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 68 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 69 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/Images.xcassets/BrandAsset.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "minimum-system-version" : "7.0", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "orientation" : "portrait", 11 | "idiom" : "iphone", 12 | "minimum-system-version" : "7.0", 13 | "subtype" : "retina4", 14 | "scale" : "2x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/RBLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.h 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RBLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/RBLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.m 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLAppDelegate.h" 10 | 11 | @implementation RBLAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/RBLCellTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLCellTableViewCell.h 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RBLCellTableViewCell : UITableViewCell 12 | 13 | @property (weak, nonatomic) IBOutlet UIImageView *send; 14 | @property (weak, nonatomic) IBOutlet UIImageView *receive; 15 | @property (weak, nonatomic) IBOutlet UILabel *text; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/RBLCellTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLCellTableViewCell.m 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLCellTableViewCell.h" 10 | 11 | @implementation RBLCellTableViewCell 12 | 13 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 14 | { 15 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 16 | if (self) { 17 | // Initialization code 18 | } 19 | return self; 20 | } 21 | 22 | - (void)awakeFromNib 23 | { 24 | // Initialization code 25 | } 26 | 27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 28 | { 29 | [super setSelected:selected animated:animated]; 30 | 31 | // Configure the view for the selected state 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/RBLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLViewController.h 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BLE.h" 11 | 12 | @interface RBLViewController : UIViewController 13 | { 14 | BLE *bleShield; 15 | UIActivityIndicatorView *activityIndicator; 16 | } 17 | 18 | @property (nonatomic, weak) IBOutlet UITableView *tableView; 19 | @property (nonatomic, weak) IBOutlet UITextField *text; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/SimpleChat-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/SimpleChat-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEChat_Central_iOS/SimpleChat/apple.png -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEChat_Central_iOS/SimpleChat/arduino.png -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChat/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleChat 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "RBLAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([RBLAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChatTests/SimpleChatTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChatTests/SimpleChatTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SimpleChatTests.m 3 | // SimpleChatTests 4 | // 5 | // Created by redbear on 14-4-8. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SimpleChatTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SimpleChatTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEChat_Central_iOS/SimpleChatTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/BLEChat_Peripheral-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/BLEChat_Peripheral-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/RBLAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.h 3 | // BLE peripheral mode 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RBLAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/RBLAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLAppDelegate.m 3 | // BLE peripheral mode 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLAppDelegate.h" 10 | 11 | @implementation RBLAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/RBLViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBLViewController.h 3 | // BLE peripheral mode 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface RBLViewController : UIViewController 13 | { 14 | CBMutableCharacteristic *rx; 15 | NSMutableString *str; 16 | } 17 | 18 | @property (nonatomic, strong) CBPeripheralManager *peripheralManager; 19 | 20 | @property (nonatomic, strong) UITextView *textView; 21 | @property (nonatomic, strong) IBOutlet UITextField *textField; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/RBLViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBLViewController.m 3 | // BLE peripheral mode 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import "RBLViewController.h" 10 | 11 | @interface RBLViewController () 12 | 13 | #define RBL_SERVICE_UUID @"713d0000-503e-4c75-ba94-3148f18d941e" 14 | #define RBL_TX_UUID @"713d0003-503e-4c75-ba94-3148f18d941e" 15 | #define RBL_RX_UUID @"713d0002-503e-4c75-ba94-3148f18d941e" 16 | 17 | @end 18 | 19 | @implementation RBLViewController 20 | 21 | - (void)viewDidLoad 22 | { 23 | [super viewDidLoad]; 24 | // Do any additional setup after loading the view, typically from a nib. 25 | 26 | self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; 27 | self.textField.delegate = self; 28 | [self.textField becomeFirstResponder]; 29 | 30 | NSString *reqSysVer = @"7.0"; 31 | NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; 32 | BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); 33 | 34 | if (osVersionSupported) { 35 | NSTextStorage* textStorage = [[NSTextStorage alloc] init]; 36 | NSLayoutManager* layoutManager = [NSLayoutManager new]; 37 | [textStorage addLayoutManager:layoutManager]; 38 | NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:self.view.bounds.size]; 39 | [layoutManager addTextContainer:textContainer]; 40 | self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 20, 320, 203) textContainer:textContainer]; 41 | } 42 | else 43 | self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 20, 320, 203)]; 44 | 45 | self.textView.editable = NO; 46 | self.textView.selectable = NO; 47 | self.textView.font = [UIFont fontWithName:@"Arial" size:20.0f]; 48 | [self.view addSubview:self.textView]; 49 | } 50 | 51 | - (void)didReceiveMemoryWarning 52 | { 53 | [super didReceiveMemoryWarning]; 54 | // Dispose of any resources that can be recreated. 55 | } 56 | 57 | - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral 58 | { 59 | if (peripheral.state != CBPeripheralManagerStatePoweredOn) { 60 | return; 61 | } 62 | 63 | NSLog(@"self.peripheralManager powered on."); 64 | 65 | CBMutableCharacteristic *tx = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:RBL_TX_UUID] properties:CBCharacteristicPropertyWriteWithoutResponse value:nil permissions:CBAttributePermissionsWriteable]; 66 | rx = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:RBL_RX_UUID] properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable]; 67 | 68 | CBMutableService *s = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:RBL_SERVICE_UUID] primary:YES]; 69 | s.characteristics = @[tx, rx]; 70 | 71 | [self.peripheralManager addService:s]; 72 | 73 | NSDictionary *advertisingData = @{CBAdvertisementDataLocalNameKey : @"iPhone", CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:RBL_SERVICE_UUID]]}; 74 | [self.peripheralManager startAdvertising:advertisingData]; 75 | } 76 | 77 | - (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests 78 | { 79 | NSLog(@"didReceiveWriteRequests"); 80 | 81 | CBATTRequest* request = [requests objectAtIndex: 0]; 82 | NSData* request_data = request.value; 83 | CBCharacteristic* write_char = request.characteristic; 84 | 85 | uint8_t buf[request_data.length]; 86 | [request_data getBytes:buf length:request_data.length]; 87 | 88 | NSMutableString *temp = [[NSMutableString alloc] init]; 89 | for (int i = 0; i < request_data.length; i++) { 90 | [temp appendFormat:@"%c", buf[i]]; 91 | } 92 | 93 | if (str == nil) { 94 | str = [NSMutableString stringWithFormat:@"%@\n", temp]; 95 | } else { 96 | [str appendFormat:@"%@\n", temp]; 97 | } 98 | 99 | self.textView.text = str; 100 | [self scrollOutputToBottom]; 101 | 102 | //[peripheral respondToRequest:request withResult:CBATTErrorSuccess]; 103 | } 104 | 105 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 106 | { 107 | NSString *text = self.textField.text; 108 | 109 | NSData *data = [text dataUsingEncoding:NSUTF8StringEncoding]; 110 | 111 | [self.peripheralManager updateValue:data forCharacteristic:rx onSubscribedCentrals:nil]; 112 | 113 | return YES; 114 | } 115 | 116 | - (void)scrollOutputToBottom { 117 | CGPoint p = [self.textView contentOffset]; 118 | [self.textView setContentOffset:p animated:NO]; 119 | [self.textView scrollRangeToVisible:NSMakeRange([self.textView.text length], 0)]; 120 | } 121 | 122 | @end 123 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_Peripheral/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BLE peripheral mode 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "RBLAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([RBLAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_PeripheralTests/BLEChat_PeripheralTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.redbear.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_PeripheralTests/BLEChat_PeripheralTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BLE_peripheral_modeTests.m 3 | // BLE peripheral modeTests 4 | // 5 | // Created by redbear on 14-2-20. 6 | // Copyright (c) 2014年 redbear. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BLE_peripheral_modeTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation BLE_peripheral_modeTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEChat_Peripheral_iOS/BLEChat_PeripheralTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEController/BLE/BLE.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) NSMutableArray *peripheralsRssi; 37 | @property (strong, nonatomic) CBCentralManager *CM; 38 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 39 | 40 | -(void) enableReadNotification:(CBPeripheral *)p; 41 | -(void) read; 42 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 43 | 44 | -(BOOL) isConnected; 45 | -(void) write:(NSData *)d; 46 | -(void) readRSSI; 47 | 48 | -(void) controlSetup; 49 | -(int) findBLEPeripherals:(int) timeout; 50 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 51 | 52 | -(UInt16) swap:(UInt16) s; 53 | -(const char *) centralManagerStateToString:(int)state; 54 | -(void) scanTimer:(NSTimer *)timer; 55 | -(void) printKnownPeripherals; 56 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 57 | 58 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 59 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 60 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 61 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 62 | 63 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 64 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 65 | 66 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 67 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 68 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 69 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Examples/BLEController/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/BLEController-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.redbearlab.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 20140423 25 | LSRequiresIPhoneOS 26 | 27 | UIBackgroundModes 28 | 29 | bluetooth-central 30 | 31 | UIMainStoryboardFile 32 | Main 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UIStatusBarTintParameters 38 | 39 | UINavigationBar 40 | 41 | Style 42 | UIBarStyleDefault 43 | Translucent 44 | 45 | 46 | 47 | UISupportedInterfaceOrientations 48 | 49 | UIInterfaceOrientationPortrait 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/BLEController-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/CellPin.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | 15 | #import 16 | 17 | @interface CellPin : UITableViewCell 18 | { 19 | } 20 | @property (strong, nonatomic) UILabel *lblPin; 21 | @property (strong, nonatomic) UIButton *btnMode; 22 | @property (strong, nonatomic) UISegmentedControl *sgmHL; 23 | @property (strong, nonatomic) UILabel *lblAnalog; 24 | @property (strong, nonatomic) UISlider *sldPWM; 25 | @end 26 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/CellPin.m: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import "CellPin.h" 15 | 16 | @implementation CellPin 17 | 18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 19 | { 20 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 21 | if (self) { 22 | // Initialization code 23 | } 24 | return self; 25 | } 26 | 27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 28 | { 29 | [super setSelected:selected animated:animated]; 30 | 31 | // Configure the view for the selected state 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/CellUuid.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | 16 | @interface CellUuid : UITableViewCell { 17 | IBOutlet UILabel *lblUuid; 18 | IBOutlet UILabel *lblRssi; 19 | IBOutlet UILabel *lblName; 20 | } 21 | 22 | @property (strong, nonatomic) UILabel *lblUuid; 23 | @property (strong, nonatomic) UILabel *lblRssi; 24 | @property (strong, nonatomic) UILabel *lblName; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/CellUuid.m: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import "CellUuid.h" 15 | 16 | @implementation CellUuid 17 | 18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 19 | { 20 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 21 | if (self) { 22 | // Initialization code 23 | } 24 | return self; 25 | } 26 | 27 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 28 | { 29 | [super setSelected:selected animated:animated]; 30 | 31 | // Configure the view for the selected state 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/Images.xcassets/AppIcon.appiconset/BLEController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEController/BLEController/Images.xcassets/AppIcon.appiconset/BLEController.png -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "size" : "60x60", 15 | "idiom" : "iphone", 16 | "filename" : "BLEController.png", 17 | "scale" : "2x" 18 | } 19 | ], 20 | "info" : { 21 | "version" : 1, 22 | "author" : "xcode" 23 | } 24 | } -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/Images.xcassets/LaunchImage.launchimage/BLEController.launch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEController/BLEController/Images.xcassets/LaunchImage.launchimage/BLEController.launch.png -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/Images.xcassets/LaunchImage.launchimage/BLEController.launch.short.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEController/BLEController/Images.xcassets/LaunchImage.launchimage/BLEController.launch.short.png -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "filename" : "BLEController.launch.short.png", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "extent" : "full-screen", 13 | "idiom" : "iphone", 14 | "subtype" : "retina4", 15 | "filename" : "BLEController.launch.png", 16 | "minimum-system-version" : "7.0", 17 | "orientation" : "portrait", 18 | "scale" : "2x" 19 | } 20 | ], 21 | "info" : { 22 | "version" : 1, 23 | "author" : "xcode" 24 | } 25 | } -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RBLAppDelegate.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | 16 | @interface RBLAppDelegate : UIResponder 17 | 18 | @property (strong, nonatomic) UIWindow *window; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RBLAppDelegate.m: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import "RBLAppDelegate.h" 15 | 16 | @implementation RBLAppDelegate 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | // Override point for customization after application launch. 21 | 22 | if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) 23 | { 24 | [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"]; 25 | [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"]; 26 | } 27 | else 28 | { 29 | [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"]; 30 | } 31 | 32 | return YES; 33 | } 34 | 35 | - (void)applicationWillResignActive:(UIApplication *)application 36 | { 37 | // 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. 38 | // 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. 39 | } 40 | 41 | - (void)applicationDidEnterBackground:(UIApplication *)application 42 | { 43 | // 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. 44 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 45 | } 46 | 47 | - (void)applicationWillEnterForeground:(UIApplication *)application 48 | { 49 | // 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. 50 | } 51 | 52 | - (void)applicationDidBecomeActive:(UIApplication *)application 53 | { 54 | // 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. 55 | } 56 | 57 | - (void)applicationWillTerminate:(UIApplication *)application 58 | { 59 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RBLControlViewController.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "RBLProtocol.h" 16 | #import "BLE.h" 17 | 18 | @interface RBLControlViewController : UITableViewController 19 | { 20 | IBOutlet UITableView *tv; 21 | } 22 | 23 | @property (strong, nonatomic) BLE *ble; 24 | @property (strong, nonatomic) RBLProtocol *protocol; 25 | 26 | -(void) processData:(uint8_t *) data length:(uint8_t) length; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RBLDetailViewController.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "CellUuid.h" 16 | #import "BLE.h" 17 | 18 | @protocol RBLDetailViewControllerDelegate 19 | 20 | - (void) didSelected:(NSInteger)selected; 21 | 22 | @end 23 | 24 | @interface RBLDetailViewController : UITableViewController 25 | { 26 | } 27 | 28 | @property (strong, nonatomic) BLE *ble; 29 | @property (strong, nonatomic) NSMutableArray *BLEDevices; 30 | @property (strong, nonatomic) NSMutableArray *BLEDevicesRssi; 31 | @property (strong, nonatomic) NSMutableArray *BLEDevicesName; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RBLMainViewController.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "RBLDetailViewController.h" 16 | #import "BLE.h" 17 | 18 | @interface RBLMainViewController : UIViewController 19 | { 20 | IBOutlet UIActivityIndicatorView *activityScanning; 21 | IBOutlet UIButton *btnConnect; 22 | IBOutlet UIButton *btnConnectLast; 23 | IBOutlet UILabel *lblVersion; 24 | BOOL showAlert; 25 | bool isFindingLast; 26 | } 27 | 28 | @property (strong, nonatomic) BLE *ble; 29 | @property (strong, nonatomic) NSMutableArray *mDevices; 30 | @property (strong, nonatomic) NSMutableArray *mDevicesName; 31 | @property (strong,nonatomic) NSString *lastUUID; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/RedBearLab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEController/BLEController/RedBearLab.jpg -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/main.m: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | 16 | #import "RBLAppDelegate.h" 17 | 18 | int main(int argc, char * argv[]) 19 | { 20 | @autoreleasepool { 21 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([RBLAppDelegate class])); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/BLEController/BLEController/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/BLEController/BLEController/title.png -------------------------------------------------------------------------------- /Examples/BLEController/RBLProtocol/RBLProtocol.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "BLE.h" 16 | 17 | #define MESSAGE_TYPE_CUSTOM_DATA 'Z' 18 | #define MESSAGE_TYPE_PROTOCOL_VERSION 'V' 19 | #define MESSAGE_TYPE_PIN_COUNT 'C' 20 | #define MESSAGE_TYPE_PIN_CAPABILITY 'P' 21 | 22 | #define COMMAND_ANALOG_WRITE 'N' 23 | 24 | // Pin modes. 25 | // except from UNAVAILABLE taken from Firmata.h 26 | #define UNAVAILABLE 0xFF 27 | #define INPUT 0x00 28 | #define OUTPUT 0x01 29 | #define ANALOG 0x02 30 | #define PWM 0x03 31 | #define SERVO 0x04 32 | 33 | // Pin types 34 | #define DIGITAL = OUTPUT // same as OUTPUT below 35 | // ANALOG is already defined above 36 | 37 | #define HIGH 0x01 38 | #define LOW 0x00 39 | 40 | #define PIN_CAPABILITY_NONE 0x00 41 | #define PIN_CAPABILITY_DIGITAL 0x01 42 | #define PIN_CAPABILITY_ANALOG 0x02 43 | #define PIN_CAPABILITY_PWM 0x04 44 | #define PIN_CAPABILITY_SERVO 0x08 45 | #define PIN_CAPABILITY_I2C 0x10 46 | 47 | #define PIN_ERROR_INVALID_PIN 0x01 48 | #define PIN_ERROR_INVALID_MODE 0x02 49 | 50 | @protocol ProtocolDelegate 51 | @optional 52 | @required 53 | -(void) protocolDidReceiveCustomData:(uint8_t *) data length:(uint8_t) length; 54 | 55 | -(void) protocolDidReceiveProtocolVersion:(uint8_t) major Minor:(uint8_t) minor Bugfix:(uint8_t) bugfix; 56 | -(void) protocolDidReceiveTotalPinCount:(uint8_t) count; 57 | -(void) protocolDidReceivePinCapability:(uint8_t) pin Value:(uint8_t) value; 58 | -(void) protocolDidReceivePinMode:(uint8_t) pin Mode:(uint8_t) mode; /* mode: I/O/Analog/PWM/Servo */ 59 | 60 | -(void) protocolDidReceivePinData:(uint8_t) pin Mode:(uint8_t) mode Value:(uint8_t) value; 61 | @end 62 | 63 | @interface RBLProtocol : NSObject 64 | @property (strong, nonatomic) BLE *ble; 65 | @property (nonatomic,assign) id delegate; 66 | -(void) parseData:(unsigned char *) data length:(int) length; 67 | 68 | /* APIs for query and read/write pins */ 69 | -(void) queryProtocolVersion; 70 | -(void) queryTotalPinCount; 71 | -(void) queryPinCapability:(uint8_t) pin; 72 | 73 | -(void) queryPinAll; 74 | -(void) queryPinMode:(uint8_t) pin; 75 | -(void) setPinMode:(uint8_t) pin Mode:(uint8_t) mode; 76 | 77 | -(void) sendCustomData: (uint8_t *) data Length:(uint8_t) length; 78 | 79 | -(void) digitalWrite:(uint8_t) pin Value:(uint8_t) value; /* write digital pin, HIGH or LOW */ 80 | //-(void) digitalRead:(uint8_t) pin; 81 | 82 | -(void) analogWrite:(uint8_t) pin Value:(uint8_t) value; 83 | //-(void) analogRead:(uint8_t) pin; 84 | 85 | -(void) servoWrite:(uint8_t) pin Value:(uint8_t) value; /* write servo pin, value = angle */ 86 | //-(void) servoRead:(uint8_t) pin; 87 | @end 88 | -------------------------------------------------------------------------------- /Examples/Readme_Chat.txt: -------------------------------------------------------------------------------- 1 | Chat Demo 2 | 3 | 1. Chat_iOS - This Demo App is to demonstrate how to use our BLE Framework to connect to BLE Shield. 4 | 5 | 2. Chat_Sketch - This is a demo to show how to use BLE library for Arduino firmware to work with the BLE Shield and communicates to iOS App. 6 | 7 | ----- 8 | 9 | 1. Chat_iOS 10 | 11 | The framework provide four delegate function for your App which will be called back from the low layer of the framework. 12 | 13 | When the framework connected to a BLE device, it will call back your App to tell you it connected to a device successfully. 14 | -(void) bleDidConnect; 15 | 16 | When the framework disconnected from your BLE device (e.g. link lost, Arduino reset button, etc.), this function will be called. 17 | -(void) bleDidDisconnect; 18 | 19 | When connected to a device and if the RSSI value changes, it will call this function. 20 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 21 | 22 | When the BLE device sends data to your App, it will call this function. 23 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 24 | 25 | You can write data to BLE device use write function, you can write up to 19-bytes at a time. 26 | -(void) write:(NSData *)d; 27 | 28 | This is for retrieving the library version of the Arduino BLE library that used with the Arduino firmware. 29 | -(UInt16) readLibVer; 30 | 31 | This will return the current BLEShield framework version. 32 | -(UInt16) readFrameworkVersion; 33 | 34 | This will return the vendor name, which is "Red Bear Lab." 35 | -(NSString *) readVendorName; 36 | 37 | This is for checking if it connected to a BLE device. 38 | -(BOOL) isConnected; 39 | 40 | This is for searching BLE devices. 41 | -(int) findBLEPeripherals:(int) timeout; 42 | 43 | This is for connecting to a BLE device. 44 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 45 | 46 | 47 | 48 | Program flow: 49 | 50 | When the App starts, it will call viewDidLoad, and there, we need to init the BLE framework, 51 | 52 | bleShield = [[BLE alloc] init]; 53 | [bleShield controlSetup:1]; 54 | bleShield.delegate = self; 55 | 56 | The App has a button for scanning available BLE devices, this button calls BLEShieldScan action. If connected before, it will disconnect the current connection. 57 | 58 | Once connected, you can type text to BLE device and it will shows typed text to serial. 59 | 60 | 61 | ----- 62 | 63 | 2. Chat_Sketch 64 | 65 | Connect your Arduino with BLE Shield to PC. Use Serial Monitor to type and receive data. 66 | 67 | Serial Monitor settings: 68 | -Carriage return 69 | -57600 baud 70 | 71 | Text typed from iPhone will be transferred to PC and vice versa. 72 | 73 | The program first setup SPI pins and then it initials the BLE library by using ble_begin(). 74 | 75 | And then it enters to the loop() which doing some tasks repeatedly. 76 | 77 | The loop first reads if any data comes from iOS App using ble_available() and ble_read() and if so, it will send it out via the Serial interface of Arduino. 78 | 79 | And then it reads from Serial port to see any data from PC, if so, it transfers data using ble_write() to send to iOS App. 80 | 81 | Currently, you can send up to 19 bytes at a time. 82 | 83 | After all, it calls ble_do_events() so that to allow the low layer BLE library to do its house-keeping tasks. 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Examples/Readme_Select.txt: -------------------------------------------------------------------------------- 1 | 2 | BLE Select 3 | 4 | This demo teaches you how to scan multiple device and select one to connect. Once connected, you can connect to the last connected device without re-scan. 5 | 6 | -------------------------------------------------------------------------------- /Examples/Readme_SimpleControls.txt: -------------------------------------------------------------------------------- 1 | BLE Demo - Simple Controls 2 | 3 | A. General Description 4 | 5 | This demo shows how to create controls from App that read from or write to BLE Shield connected to Arduino board. 6 | 7 | B. System Setup 8 | 9 | Arduino Pins: 10 | 11 | Pin 2 - Digital Output pin, for example, connect to a LED 12 | Pin A4 - Digital Input pin, connect to a button 13 | Pin 3 - PWM pin, connect to a LED 14 | Pin 5 - Servo pin, connect to a Servo 15 | Pin A5 - Analog Input pin, connect to a variable resistor 16 | 17 | C. System Design 18 | 19 | I. iOS/OS X App 20 | 21 | This App provides a simple GUI for controlling or displaying information 22 | 23 | RSSI - Current RSSI reading 24 | Digital Out - Control Arduino digital output Pin 4 25 | Digital In - Reading of Arduino digital input Pin 5 26 | PWM - Control Arduino PWM on Pin 6 27 | Servo - Control Arduino Servo on Pin 7 28 | Analog In - Enable reading of Arduino analog input Pin A5 29 | 30 | II. Protocol 31 | 32 | App to send: 33 | 34 | Opcode Data Description 35 | 0x01 0x0000 Digital Output Pin - Off 36 | 0x0001 Digital Output Pin - On 37 | 38 | 0x02 0x0000 ~ 0x00FF PWM Value 0 ~ 255 39 | 40 | 0x03 0x0000 ~ 0x00B4 Servo Value 0 ~ 180 41 | 42 | 0xA0 0x0000 Analog Input Reading Disabled 43 | 0x0001 Analog Input Reading Enabled 44 | 45 | App to read: 46 | 47 | 0x0A 0x0000 Digital Input Pin - Off 48 | 0x0001 Digital Input Pin - On 49 | 50 | 0x0B 0x0000 ~ 0x03FF Analog Input Value 0 ~ 1023 51 | 52 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/AppDelegate.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #import "BLE.h" 16 | 17 | @interface AppDelegate : NSObject 18 | { 19 | IBOutlet NSTextField *lblRSSI; 20 | IBOutlet NSTextField *lblAnalogIn; 21 | IBOutlet NSSegmentedControl *swDigitalOut; 22 | IBOutlet NSTextField *lblDigitalIn; 23 | IBOutlet NSButton *btnConnect; 24 | IBOutlet NSProgressIndicator *indConnect; 25 | IBOutlet NSSlider *sldPWM; 26 | IBOutlet NSSlider *sldServo; 27 | IBOutlet NSButton *btnAnalogIn; 28 | } 29 | 30 | @property (assign) IBOutlet NSWindow *window; 31 | @property (strong, nonatomic) BLE *ble; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/BLE/BLE.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) CBCentralManager *CM; 37 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 38 | 39 | -(void) enableReadNotification:(CBPeripheral *)p; 40 | -(void) read; 41 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 42 | 43 | -(BOOL) isConnected; 44 | -(void) write:(NSData *)d; 45 | -(void) readRSSI; 46 | 47 | -(void) controlSetup; 48 | -(int) findBLEPeripherals:(int) timeout; 49 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 50 | 51 | -(UInt16) swap:(UInt16) s; 52 | -(const char *) centralManagerStateToString:(int)state; 53 | -(void) scanTimer:(NSTimer *)timer; 54 | -(void) printKnownPeripherals; 55 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 56 | 57 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 58 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 59 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 60 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 61 | 62 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 63 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 64 | 65 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 66 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 67 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 68 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/SimpleControls-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | net.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012 RedBearLab. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/SimpleControls-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SimpleControls' target in the 'SimpleControls' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/SimpleControls_OSX/SimpleControls/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleControls 4 | // 5 | // Created by YC Poon on 27/10/12. 6 | // Copyright (c) 2012 RedBearLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SimpleControl 4 | // 5 | // Created by Cheong on 6/11/12. 6 | // Copyright (c) 2012 RedBearLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SimpleControl 4 | // 5 | // Created by Cheong on 6/11/12. 6 | // Copyright (c) 2012 RedBearLab. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/BLE/BLE.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | #import 15 | #if TARGET_OS_IPHONE 16 | #import 17 | #else 18 | #import 19 | #endif 20 | 21 | @protocol BLEDelegate 22 | @optional 23 | -(void) bleDidConnect; 24 | -(void) bleDidDisconnect; 25 | -(void) bleDidUpdateRSSI:(NSNumber *) rssi; 26 | -(void) bleDidReceiveData:(unsigned char *) data length:(int) length; 27 | @required 28 | @end 29 | 30 | @interface BLE : NSObject { 31 | 32 | } 33 | 34 | @property (nonatomic,assign) id delegate; 35 | @property (strong, nonatomic) NSMutableArray *peripherals; 36 | @property (strong, nonatomic) CBCentralManager *CM; 37 | @property (strong, nonatomic) CBPeripheral *activePeripheral; 38 | 39 | -(void) enableReadNotification:(CBPeripheral *)p; 40 | -(void) read; 41 | -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data; 42 | 43 | -(BOOL) isConnected; 44 | -(void) write:(NSData *)d; 45 | -(void) readRSSI; 46 | 47 | -(void) controlSetup; 48 | -(int) findBLEPeripherals:(int) timeout; 49 | -(void) connectPeripheral:(CBPeripheral *)peripheral; 50 | 51 | -(UInt16) swap:(UInt16) s; 52 | -(const char *) centralManagerStateToString:(int)state; 53 | -(void) scanTimer:(NSTimer *)timer; 54 | -(void) printKnownPeripherals; 55 | -(void) printPeripheralInfo:(CBPeripheral*)peripheral; 56 | 57 | -(void) getAllServicesFromPeripheral:(CBPeripheral *)p; 58 | -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p; 59 | -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p; 60 | -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service; 61 | 62 | //-(NSString *) NSUUIDToString:(NSUUID *) UUID; 63 | -(NSString *) CBUUIDToString:(CBUUID *) UUID; 64 | 65 | -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2; 66 | -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2; 67 | -(UInt16) CBUUIDToInt:(CBUUID *) UUID; 68 | -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/BLE/BLEDefines.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Copyright (c) 2013 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 | */ 13 | 14 | // RBL Service 15 | #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 16 | #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E" 17 | #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E" 18 | 19 | #define RBL_BLE_FRAMEWORK_VER 0x0200 20 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/SimpleControls_iOS/SimpleControls/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/SimpleControls_iOS/SimpleControls/Default.png -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedBearLab/iOS/b7637d26c8783fad60823578e6b905f133eea37a/Examples/SimpleControls_iOS/SimpleControls/Default@2x.png -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/SimpleControls-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | net.redbear.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/SimpleControls-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SimpleControl' target in the 'SimpleControl' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/TableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.h 3 | // SimpleControl 4 | // 5 | // Created by Cheong on 7/11/12. 6 | // Copyright (c) 2012 RedBearLab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BLE.h" 11 | 12 | @interface TableViewController : UITableViewController 13 | { 14 | IBOutlet UIButton *btnConnect; 15 | IBOutlet UISwitch *swDigitalIn; 16 | IBOutlet UISwitch *swDigitalOut; 17 | IBOutlet UISwitch *swAnalogIn; 18 | IBOutlet UILabel *lblAnalogIn; 19 | IBOutlet UISlider *sldPWM; 20 | IBOutlet UISlider *sldServo; 21 | IBOutlet UIActivityIndicatorView *indConnecting; 22 | IBOutlet UILabel *lblRSSI; 23 | } 24 | 25 | @property (strong, nonatomic) BLE *ble; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/SimpleControls_iOS/SimpleControls/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleControl 4 | // 5 | // Created by YC Poon on 6/11/12. 6 | // Copyright (c) 2012 RedBearLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Introduction 3 | ============ 4 | 5 | This BLE SDK for iOS provides a framework for Mac OSX and iOS developers to develop Bluetooth 4.0 Low Energy (aka BLE) Apps easily using a simeple TXRX Service for exchanging data. It is based on Apple's CoreBluetooth framework. 6 | 7 | It currently supports iOS 7 and Mac OSX 10.9.2.
8 | OSX 10.7.5, 10.8.x and iOS 6 also support BLE but not tested.
9 | OSX 10.9.0 and 10.9.1 have bugs, so we will not support.
10 | 11 | For iOS devices, only iPhone 4s/5/5s, iPod touch 5 and iPad 3/4/Air/Mini have BLE 4.0 support.
12 | For Mac devices, if no BLE hardware built-in, you need to buy an USB Bluetooth 4.0 dongle (CSR or Broadcom).
13 | 14 | Since BLE is a new technology, if you found your App does not run correctly, it might be the OS issue, try to restart your device to try again. 15 | 16 | The examples are for our BLE development boards, currently, it supports:
17 | - BLE Shield 18 | - BLE Mini 19 | - Blend Micro 20 | - Blend 21 | - BLE Nano 22 | - RBL nRF51822 23 | 24 | Please refer to their repositories at https://github.com/RedBearLab/ 25 | 26 | 27 | License 28 | ======= 29 | 30 | Copyright (c) 2012-2014 RedBearLab 31 | 32 | Permission is hereby granted, free of charge, to any person obtaining a copy 33 | of this software and associated documentation files (the "Software"), to deal 34 | in the Software without restriction, including without limitation the rights 35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | copies of the Software, and to permit persons to whom the Software is 37 | furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in all 40 | copies or substantial portions of the Software. 41 | 42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 48 | SOFTWARE. 49 | --------------------------------------------------------------------------------