Skip to content

Instantly share code, notes, and snippets.

View marchbold's full-sized avatar
🚲
making stuff...

Michael marchbold

🚲
making stuff...
View GitHub Profile
@marchbold
marchbold / distriqt.extension.bluetoothle.subscribeToCharacteristic.as
Last active October 19, 2015 09:07
BluetoothLE: Subscribing to a Characteristic
var peripheral:Peripheral = ...; // Previously connected Peripheral
var characteristic:Characteristic = ...; // Discovered Characteristic of interest
peripheral.addEventListener( CharacteristicEvent.UPDATE, peripheral_characteristic_updatedHandler );
peripheral.addEventListener( CharacteristicEvent.UPDATE_ERROR, peripheral_characteristic_errorHandler );
peripheral.addEventListener( CharacteristicEvent.SUBSCRIBE, peripheral_characteristic_subscribeHandler );
peripheral.addEventListener( CharacteristicEvent.SUBSCRIBE_ERROR, peripheral_characteristic_subscribeErrorHandler );
peripheral.addEventListener( CharacteristicEvent.UNSUBSCRIBE, peripheral_characteristic_unsubscribeHandler );
if (!peripheral.subscribeToCharacteristic( characteristic ))
@marchbold
marchbold / distriqt.extension.bluetoothle.writeValueForCharacteristic.as
Last active June 12, 2016 18:58
Bluetooth LE: Write value for characteristic
// These variables for peripheral and characteristic should have
// previously been obtained through scanning and discovery functionality
var peripheral:Peripheral = ...;
var characteristic:Characteristic = ...;
peripheral.addEventListener( CharacteristicEvent.WRITE_SUCCESS, peripheral_characteristic_writeHandler );
peripheral.addEventListener( CharacteristicEvent.WRITE_ERROR, peripheral_characteristic_writeErrorHandler );
// Some data to write
var value:ByteArray = new ByteArray();
@marchbold
marchbold / distriqt.extension.bluetoothle.createServiceAndCharacteristics.as
Created October 20, 2015 00:49
BluetoothLE: Creating your peripheral's Service's and Characteristics
var characteristic:Characteristic = new Characteristic( "E95E787B-9C88-4A8D-9A33-BA63EBC4A3A3" );
var service:Service = new Service();
service.uuid = "90753043-6E40-4590-AFF6-5B48F6412E2F";
service.characteristics.push( characteristic );
// com.distriqt.BluetoothLE
@marchbold
marchbold / distriqt.extension.bluetoothle.publishServices.as
Last active October 20, 2015 00:57
Bluetooth LE: Publishing available services
var characteristic:Characteristic = new Characteristic( "E95E787B-9C88-4A8D-9A33-BA63EBC4A3A3" );
var service:Service = new Service();
service.uuid = "90753043-6E40-4590-AFF6-5B48F6412E2F";
service.characteristics.push( characteristic );
BluetoothLE.service.peripheralManager.addEventListener( PeripheralManagerEvent.SERVICE_ADD, peripheral_serviceAddHandler );
BluetoothLE.service.peripheralManager.addEventListener( PeripheralManagerEvent.SERVICE_ADD_ERROR, peripheral_serviceAddErrorHandler );
// Remove all to prevent duplicate services (this only removes services added by this application)
@marchbold
marchbold / distriqt.extension.bluetoothle.startAdvertising.as
Created October 20, 2015 01:03
Bluetooth LE: Advertising a service
var service:Service = ...; // A previously created and published service
BluetoothLE.service.peripheralManager.addEventListener( PeripheralManagerEvent.START_ADVERTISING, peripheral_startAdvertisingHandler );
BluetoothLE.service.peripheralManager.startAdvertising( "distriqt", new <Service>[ service ] );
...
private function peripheral_startAdvertisingHandler( event:PeripheralManagerEvent ):void
{
@marchbold
marchbold / distriqt.extension.bluetoothle.respondToReadRequests.as
Created October 20, 2015 01:17
Bluetooth LE: Responding to read requests
var characteristic:Characteristic = ...; // Some characteristic you have created and added to a published service
BluetoothLE.service.peripheralManager.addEventListener( RequestEvent.READ, peripheral_readRequestHandler );
...
private function peripheral_readRequestHandler( event:RequestEvent ):void
{
//
// Read requests will only have one object in the requests event
@marchbold
marchbold / distriqt.extension.bluetoothle.respondToWriteRequests.as
Created October 20, 2015 01:29
Bluetooth LE: Responding to write requests
var characteristic:Characteristic = ...; // Some characteristic you have created and added to a published service
BluetoothLE.service.peripheralManager.addEventListener( RequestEvent.WRITE, peripheral_writeRequestHandler );
...
private function peripheral_writeRequestHandler( event:RequestEvent ):void
{
trace( "peripheral manager: write request: " + event.requests.length );
@marchbold
marchbold / distriqt.extension.bluetoothle.updateSubscribedCentrals.as
Created October 20, 2015 01:41
Bluetooth LE: Updating Subscribed Centrals
// This assumes you have previously published and advertised services as a peripheral
var characteristic:Characteristic = ...; // Some characteristic you have created and added to a published service
BluetoothLE.service.peripheralManager.addEventListener( CentralEvent.SUBSCRIBE, peripheral_central_subscribeHandler );
BluetoothLE.service.peripheralManager.addEventListener( CentralEvent.UNSUBSCRIBE, peripheral_central_unsubscribeHandler );
...
private function peripheral_central_subscribeHandler( event:CentralEvent ):void
{
@marchbold
marchbold / distriqt.extension.notifications.delayedNotification.as
Created November 4, 2015 01:59
Setting a delayed / scheduled notification with the Notifications ANE
Notifications.init( APP_KEY );
if (Notifications.isSupported)
{
var notification:Notification = new Notification();
notification.tickerText = "Hello";
notification.title = "My Notification";
notification.body = "Hello World";
var scheduled:Date = new Date(2015,12,13, 1,1,1);
var now:Date = new Date();
@marchbold
marchbold / distriqt.extension.share.instagram.as
Created November 12, 2015 21:18
Sharing to Instagram using the Share ANE
if (Share.service.isApplicationInstalled( "com.instagram.android", "instagram://app" ))
{
var instagramImage:File = File.applicationStorageDirectory.resolvePath( "assets/instagram.igo" );
var options:ShareOptions = new ShareOptions();
options.packageName = "com.instagram.android";
options.UTI = "com.instagram.photo";
Share.service.showOpenIn( instagramImage.nativePath, "", "image/*", options );
}