Martin Woolley / microbit-dal

Dependencies:   BLE_API mbed-dev-bin nRF51822-bluetooth-mdw

Dependents:   microbit

Fork of microbit-dal-bluetooth-mdw_starter by Martin Woolley

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MicroBitAnimationService.cpp Source File

MicroBitAnimationService.cpp

00001 /*
00002 The MIT License (MIT)
00003  
00004 Copyright (c) 2016 British Broadcasting Corporation.
00005 This software is provided by Lancaster University by arrangement with the BBC.
00006  
00007 Permission is hereby granted, free of charge, to any person obtaining a
00008 copy of this software and associated documentation files (the "Software"),
00009 to deal in the Software without restriction, including without limitation
00010 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011 and/or sell copies of the Software, and to permit persons to whom the
00012 Software is furnished to do so, subject to the following conditions:
00013  
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016  
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO Animation SHALL
00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023 DEALINGS IN THE SOFTWARE.
00024 */
00025  
00026 /**
00027   * Class definition for a MicroBit BLE Animation Service.
00028   * Provides a BLE gateway onto an Animation Model.
00029   */
00030  
00031 #include "MicroBitConfig.h"
00032 #include "MicroBitAnimationService.h"
00033 #include "ble/UUID.h"
00034 #include "Animator.h"
00035  
00036 /**
00037   * Constructor.
00038   * Create a representation of the AnimationService
00039   * @param _ble The instance of a BLE device that we're running on.
00040   */
00041 MicroBitAnimationService::MicroBitAnimationService(BLEDevice &_ble) :
00042         ble(_ble)
00043 {
00044     // TODO: Three GattCharacteristic objects. UUID, valuePTR, length, max length, properties.
00045  
00046     // TODO: initialise characteristic value buffers
00047  
00048     // Set default security requirements - optional
00049     // animationTypeCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00050     // animationStatusCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00051     // animationControlCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00052  
00053     // TODO: create GattService containing the three characteristics
00054     // create an array of our characteristics so we can pass them to the service when we create it
00055 
00056     // create the animation service and specify its characteristics
00057  
00058  
00059     // TODO: add the service to the Bluetooth attribute table
00060  
00061     // TODO: take a note of the handles of our new characteristics now that they're in the attribute table
00062 
00063     // TODO: register a callback function for when a characteristic is written to
00064     
00065     // subscribe to animation status events so they can be notified to the connected client
00066     if (EventModel::defaultEventBus)
00067         EventModel::defaultEventBus->listen(ANIMATION_STATUS_EVENT, MICROBIT_EVT_ANY, this, &MicroBitAnimationService::animationStatusUpdate,  MESSAGE_BUS_LISTENER_IMMEDIATE);
00068 }
00069  
00070  
00071 /**
00072   * Callback. Invoked when any of our attributes are written via BLE.
00073   */
00074 void MicroBitAnimationService::onDataWritten(const GattWriteCallbackParams *params)
00075 {
00076     // TODO: handle write to animation type characteristic
00077     
00078     // TODO: handle write to animation control characteristic       
00079 }
00080  
00081 void MicroBitAnimationService::animationStatusUpdate(MicroBitEvent e)
00082 {
00083     // TODO: notify connected client of change to the animation status characteristic
00084 }
00085  
00086 const uint8_t  MicroBitAnimationServiceUUID[] = {
00087     0xe9,0x5d,0x71,0x70,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00088 };
00089  
00090 const uint8_t  MicroBitAnimationServiceAnimationTypeCharacteristicUUID[] = {
00091     0xe9,0x5d,0xC3,0x06,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00092 };
00093  
00094 const uint8_t  MicroBitAnimationServiceAnimationStatusCharacteristicUUID[] = {
00095     0xe9,0x5d,0x45,0x92,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00096 };
00097  
00098 const uint8_t  MicroBitAnimationServiceAnimationControlCharacteristicUUID[] = {
00099     0xe9,0x5d,0xb8,0x4c,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00100 };
00101