My fork

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

Fork of microbit-dal-bluetooth-mdw 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 
00047     // TODO: initialise characteristic value buffers
00048 
00049 
00050 
00051     // Set default security requirements - optional
00052     // animationTypeCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00053     // animationStatusCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00054     // animationControlCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
00055 
00056     // TODO: create GattService containing the three characteristics
00057     // create an array of our characteristics so we can pass them to the service when we create it
00058 
00059     // create the animation service and specify its characteristics
00060 
00061 
00062 
00063     // TODO: add the service to the Bluetooth attribute table
00064 
00065 
00066     // TODO: take a note of the handles of our new characteristics now that they're in the attribute table
00067 
00068 
00069     // TODO: set the attribute table's characteristic values to the initialised buffer values    
00070     
00071 
00072     // TODO: register a callback function for when a characteristic is written to
00073     
00074     // subscribe to animation status events so they can be notified to the connected client
00075     if (EventModel::defaultEventBus)
00076         EventModel::defaultEventBus->listen(ANIMATION_STATUS_EVENT, MICROBIT_EVT_ANY, this, &MicroBitAnimationService::animationStatusUpdate,  MESSAGE_BUS_LISTENER_IMMEDIATE);
00077 }
00078 
00079 
00080 /**
00081   * Callback. Invoked when any of our attributes are written via BLE.
00082   */
00083 void MicroBitAnimationService::onDataWritten(const GattWriteCallbackParams *params)
00084 {
00085    
00086     // TODO: handle write to animation type characteristic
00087 
00088  
00089     // TODO: handle write to animation control characteristic
00090 
00091 
00092 }
00093 
00094 void MicroBitAnimationService::animationStatusUpdate(MicroBitEvent e)
00095 {
00096     // TODO: notify connected client of change to the animation status characteristic
00097 
00098 
00099 }
00100 
00101 const uint8_t  MicroBitAnimationServiceUUID[] = {
00102     0xe9,0x5d,0x71,0x70,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00103 };
00104 
00105 const uint8_t  MicroBitAnimationServiceAnimationTypeCharacteristicUUID[] = {
00106     0xe9,0x5d,0xC3,0x06,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00107 };
00108 
00109 const uint8_t  MicroBitAnimationServiceAnimationStatusCharacteristicUUID[] = {
00110     0xe9,0x5d,0x45,0x92,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00111 };
00112 
00113 const uint8_t  MicroBitAnimationServiceAnimationControlCharacteristicUUID[] = {
00114     0xe9,0x5d,0xb8,0x4c,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
00115 };