PTDBean Class Reference
Inherits from | PTDBleDevice : NSObject |
---|---|
Declared in | PTDBean.h |
Overview
An PTDBean object represents a Light Blue Bean that gives access to setting and retrieving of Arduino attributes, such as the name, temperature, accelerometer, look at Other Methods below for more.
Example:
// Set this class as the Bean's delegate to receive messages
self.bean.delegate = self;
// ask the Bean for the current ambient temperature
[self.bean readTemperature];
// This is called when the Bean responds
-(void)bean:(PTDBean *)bean didUpdateTemperature:(NSNumber *)degrees_celsius {
NSString *msg = [NSString stringWithFormat:@"received did update temp reading:%@", degrees_celsius];
NSLog(@"%@",msg);
}
See BeanXcodeWorkspace for more examples.
Identifying a Bean
identifier
The UUID of the CoreBluetooth peripheral associated with the Bean. This is not guaranteed to be the same between different devices. If a bluetooth cache is cleared, this UUID is not guaranteed to stay the same. For more info, refer to the Apple identifier documentation
@property (nonatomic, readonly) NSUUID *identifier
Declared In
PTDBean.h
name
The Bean’s name. For more info, refer to the Apple name documentation
@property (nonatomic, readonly) NSString *name
Declared In
PTDBean.h
delegate
The PTDBeanDelegate delegate object for the Bean. Set your class as the delegate to receive messages and responses from the Bean.
@property (nonatomic, weak) id<PTDBeanDelegate> delegate
Declared In
PTDBean.h
beanManager
Used to create and manage Beans.
@property (nonatomic, readonly) PTDBeanManager *beanManager
See Also
Declared In
PTDBean.h
advertisementData
Bluetooth LE advertising data. A dictionary containing CBAdvertisementDataLocalNameKey
@property (nonatomic, readonly) NSDictionary *advertisementData
Declared In
PTDBean.h
firmwareVersion
The version of the Bean’s current firmware.
@property (nonatomic, readonly) NSString *firmwareVersion
Declared In
PTDBean.h
hardwareVersion
The version of the Bean’s hardware.
@property (nonatomic, readonly) NSString *hardwareVersion
Declared In
PTDBean.h
newestAvailableFirmwareVersion
The Newest firmware version available
@property (nonatomic) NSString *newestAvailableFirmwareVersion
Declared In
PTDBean.h
– checkFirmwareVersionAvailableWithHandler:
Check if a firmware version is available with a handler to be called if so
- (void)checkFirmwareVersionAvailableWithHandler:(void ( ^ ) ( BOOL firmwareAvailable , NSError *error ))handler
Declared In
PTDBean.h
– checkHardwareVersionAvailableWithHandler:
Check if hardware version is available with a handler to be called if so
- (void)checkHardwareVersionAvailableWithHandler:(void ( ^ ) ( BOOL hardwareAvailable , NSError *error ))handler
Declared In
PTDBean.h
– firmwareUpdateAvailable:error:
Check if a firmware update is available
- (FirmwareStatus)firmwareUpdateAvailable:(NSString *)bakedFirmwareVersion error:(NSError *__autoreleasing *)error
Declared In
PTDBean.h
– updateFirmwareWithImages:andTargetVersion:
Update this Bean with a set of asymmetric firmware images.
- (void)updateFirmwareWithImages:(NSArray *)images andTargetVersion:(NSString *)version
Parameters
images |
An array of paths to firmware images for this Bean’s hardware variant |
---|---|
version |
An NSString of the parsed datestamp for the firmware images. When Bean reflects this date in its Firmware Version characteristic, the firmware version process is complete. |
Declared In
PTDBean.h
lastDiscovered
Represents last time this Bean was discovered while scanning.
@property (nonatomic, readonly) NSDate *lastDiscovered
Declared In
PTDBean.h
– isEqualToBean:
Test equality with another Bean. This method returns TRUE if both Beans have the same identifier
- (BOOL)isEqualToBean:(PTDBean *)bean
Parameters
bean |
The Bean with which to test equality |
---|
Declared In
PTDBean.h
Security
– setPairingPin:
Sets or clears a Bluetooth pairing pin. This operation can only be used if the Bean is connected. The pairing pin will be cleared/disabled if pinCode is a null pointer.
- (BOOL)setPairingPin:(NSUInteger *)pinCode
Parameters
pinCode |
Bluetooth pairing pin with value between 0 and 999,999 (zero padded 6 digit positive integer). Use a null pointer to clear/disable pairing pin. |
---|
Return Value
A Boolean indicating if the operation was successful.
Declared In
PTDBean.h
Monitoring a Bean's Connection State
state
The current connection state of the Bean. See BeanState for more details.
@property (nonatomic, readonly) PTDBleDeviceState state
Discussion
if (self.bean.state == BeanState_Discovered) {
NSLog(@"Bean discovered, try connecting");
}
else if (self.bean.state == BeanState_ConnectedAndValidated) {
NSLog(@"Bean connected, try calling an API");
}
Declared In
PTDBean.h
Auto Reconnect
autoReconnect
If true, automatically reconnect to this Bean
@property (nonatomic) BOOL autoReconnect
Declared In
PTDBean.h
uploadInProgress;
uploadInProgress
If true, a sketch upload is in progress
@property (nonatomic, readonly) BOOL uploadInProgress
Declared In
PTDBean.h
updateInProgress;
updateInProgress
If true, a firmware update is in progress
@property (nonatomic, readonly) BOOL updateInProgress
Declared In
PTDBean.h
updateStepNumber
updateStepNumber
While an update is in progress, the current step number
@property (nonatomic, readonly) NSInteger updateStepNumber
Declared In
PTDBean.h
Radio Configuration
radioConfig
Cached data for Bean’s Radio Configuration. Should call readRadioConfig first to ensure this data is fresh.
@property (nonatomic, strong, readonly) PTDBeanRadioConfig *radioConfig
Declared In
PTDBean.h
– readRadioConfig
Requests the Bean’s current Radio Configuration.
- (void)readRadioConfig
Discussion
When you call this method to read the Bean’s Radio Configuration, the bean calls the [PTDBeanDelegate bean:didUpdateRadioConfig:] method of its delegate object. If the Bean’s Radio Config is successfully retrieved, you can access it through the Bean’s radioConfig property.
Declared In
PTDBean.h
– setRadioConfig:
Sets the Bean’s radio configuration.
- (void)setRadioConfig:(PTDBeanRadioConfig *)config
Parameters
config |
see PTDBeanRadioConfig |
---|
Declared In
PTDBean.h
Programming and Configuring Arduino
arduinoPowerState
The power state for the Bean’s Arduino. Indicates if the Arduino is powered on or off.
@property (nonatomic) ArduinoPowerState arduinoPowerState
See Also
Declared In
PTDBean.h
– setArduinoPowerState:
Temporarily turns the Bean’s Arduino on or off.
- (void)setArduinoPowerState:(ArduinoPowerState)state
Parameters
"YES" |
sets the Arduino to a powered-on state and “NO” is a shutdown state. |
---|
Declared In
PTDBean.h
– readArduinoPowerState
Requests the current Arduino power state
- (void)readArduinoPowerState
Discussion
When you call this method to read the Arduino Power State, the bean calls the [PTDBeanDelegate beanDidUpdateArduinoPowerState:] method of its delegate object. If the Arduino’s Power State is successfully retrieved, you can access it through the Bean’s arduinoPowerState property.
Declared In
PTDBean.h
– programArduinoWithRawHexImage:andImageName:
Programs the Arduino with raw binary data. (Not Intel Hex)
- (void)programArduinoWithRawHexImage:(NSData *)image andImageName:(NSString *)name
Parameters
image |
The raw binary image used to program the Arduino |
---|---|
name |
The name of the sketch. |
Discussion
After the Arduino is programmed, the Bean calls the [PTDBeanDelegate bean:didProgramArduinoWithError:] method of its delegate object.
Declared In
PTDBean.h
– readArduinoSketchInfo
Requests information about the currently programmed Arduino Sketch.
- (void)readArduinoSketchInfo
Discussion
When you call this method to read the Arduino sketch info, the bean calls the [PTDBeanDelegate beanDid:didUpdateSketchName:dateProgrammed:crc32:] method of its delegate object.
Declared In
PTDBean.h
sketchName
The name of the Arduino Sketch used to program the Bean firmware. Should call
@property (nonatomic, strong, readonly) NSString *sketchName
Declared In
PTDBean.h
dateProgrammed
The date that the Bean’s Arduino sketch was programmed. Should call
@property (nonatomic, strong, readonly) NSDate *dateProgrammed
Declared In
PTDBean.h
Accessing Battery Voltage
– readBatteryVoltage
Requests the current battery or power supply voltage.
- (void)readBatteryVoltage
Discussion
When you call this method to read the battery or power supply voltage, the bean calls the [PTDBeanDelegate bean:didUpdateBattery:] method of its delegate object. If the Bean’s supply voltage is successfully retrieved, you can access it through the Bean’s batteryVoltage property.
See Also
Declared In
PTDBean.h
batteryVoltage
Cached representation of the Bean’s battery or power supply voltage. Should call readBatteryVoltage first to ensure this data is fresh.
@property (nonatomic, readonly) NSNumber *batteryVoltage
Declared In
PTDBean.h
Accessing LED colors
– setLedColor:
Sets the Bean’s RGB LED color
- (void)setLedColor:(UIColor *)color
Parameters
color |
Color object which is used to set the Led. iOS uses UIColor, while OS X uses NSColor. |
---|
Declared In
PTDBean.h
– readLedColor
Requests the Bean’s current Led Color.
- (void)readLedColor
Discussion
When you call this method to read the LED values, the bean calls the [PTDBeanDelegate bean:didUpdateLedColor:] method of its delegate object.
Declared In
PTDBean.h
Sending Serial Data
– sendSerialData:
Sends data over serial to the Bean’s Arduino
- (void)sendSerialData:(NSData *)data
Parameters
data |
data to send over serial to the Arduino |
---|
Declared In
PTDBean.h
– sendSerialString:
Sends human-readable ASCII data over serial to the Bean’s Arduino
- (void)sendSerialString:(NSString *)string
Parameters
string |
An NSString which is converted to NSData for sending over serial to the Bean’s Arduino |
---|
Declared In
PTDBean.h
– releaseSerialGate
Allows you to bypass the delay where serial data is not allowed to pass through the bean during early connection.
- (void)releaseSerialGate
Declared In
PTDBean.h
Accessing Acceleration Data
– readAccelerationAxes
Requests the Bean’s current acceleration values
- (void)readAccelerationAxes
Discussion
When you call this method to read the Acceleration, the bean calls the [PTDBeanDelegate bean:didUpdateAccelerationAxes:] method of its delegate object.
Example:
// let the Bean know we implement PTDBeanDelegate
self.bean.delegate = self;
// ask the Bean for the acceleration data
[self.bean readAccelerationAxes];
// check for the Bean to send it back
-(void)bean:(PTDBean*)bean didUpdateAccelerationAxes:(PTDAcceleration)acceleration {
NSString *msg = [NSString stringWithFormat:@"x:%f y:%f z:%f", acceleration.x,acceleration.y,acceleration.z];
NSLog(@"%@", msg);
}
Declared In
PTDBean.h
Accessing "Scratch" Data
– setScratchBank:data:
Stores data in one of the Bean’s scratch banks.
- (void)setScratchBank:(NSInteger)bank data:(NSData *)data
Parameters
bank |
The index of the scratch bank to store data, from 1 to 5. |
---|---|
data |
Data to be stored in the selected bank. Can be up to 20 bytes. |
Discussion
Example:
// set the scratch bank, 1-5
int scratchBank = 1
// set the scratch data
[self.bean setScratchBank:scratchBank withValue:[@"scratchdata" dataUsingEncoding:NSUTF8StringEncoding]];
// after some time, ask for it back
[self.bean readScratchBank:scratchBank];
// check the delegate value
-(void)bean:(PTDBean *)bean didUpdateScratchBank:(NSNumber *)number withValue:(NSData *)data {
NSString* str = [NSString stringWithUTF8String:[data bytes]];
NSString *msg = [NSString stringWithFormat:@"received scratch number:%@ scratch:%@", number, str];
NSLog(@"%@", msg);
}
See Also
Declared In
PTDBean.h
– readScratchBank:
Requests Bean’s current scratch bank data.
- (void)readScratchBank:(NSInteger)bank
Parameters
The |
index of the scratch bank to request, from 1 to 5. |
---|
Discussion
When you call this method to read one of the Bean’s scratch banks, the bean calls the [PTDBeanDelegate bean:didUpdateScratchBank:withValue:] method of its delegate object.
Declared In
PTDBean.h
Accessing Temperature Data
– readTemperature
Requests the Bean’s current temperature reading in Celsius.
- (void)readTemperature
Discussion
When you call this method to read the Bean’s temperature, the bean calls the [PTDBeanDelegate bean:didUpdateTemperature:] method of its delegate object.
Declared In
PTDBean.h