My fork

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

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

Committer:
bluetooth_mdw
Date:
Tue Dec 27 11:55:17 2016 +0000
Revision:
77:9909cbcd0ece
Parent:
74:9771cd712730
Animation service skeleton

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bluetooth_mdw 74:9771cd712730 1 /*
bluetooth_mdw 74:9771cd712730 2 The MIT License (MIT)
bluetooth_mdw 74:9771cd712730 3
bluetooth_mdw 74:9771cd712730 4 Copyright (c) 2016 British Broadcasting Corporation.
bluetooth_mdw 74:9771cd712730 5 This software is provided by Lancaster University by arrangement with the BBC.
bluetooth_mdw 74:9771cd712730 6
bluetooth_mdw 74:9771cd712730 7 Permission is hereby granted, free of charge, to any person obtaining a
bluetooth_mdw 74:9771cd712730 8 copy of this software and associated documentation files (the "Software"),
bluetooth_mdw 74:9771cd712730 9 to deal in the Software without restriction, including without limitation
bluetooth_mdw 74:9771cd712730 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
bluetooth_mdw 74:9771cd712730 11 and/or sell copies of the Software, and to permit persons to whom the
bluetooth_mdw 74:9771cd712730 12 Software is furnished to do so, subject to the following conditions:
bluetooth_mdw 74:9771cd712730 13
bluetooth_mdw 74:9771cd712730 14 The above copyright notice and this permission notice shall be included in
bluetooth_mdw 74:9771cd712730 15 all copies or substantial portions of the Software.
bluetooth_mdw 74:9771cd712730 16
bluetooth_mdw 74:9771cd712730 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bluetooth_mdw 74:9771cd712730 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bluetooth_mdw 74:9771cd712730 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO Animation SHALL
bluetooth_mdw 74:9771cd712730 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bluetooth_mdw 74:9771cd712730 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
bluetooth_mdw 74:9771cd712730 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
bluetooth_mdw 74:9771cd712730 23 DEALINGS IN THE SOFTWARE.
bluetooth_mdw 74:9771cd712730 24 */
bluetooth_mdw 74:9771cd712730 25
bluetooth_mdw 74:9771cd712730 26 /**
bluetooth_mdw 74:9771cd712730 27 * Class definition for a MicroBit BLE Animation Service.
bluetooth_mdw 74:9771cd712730 28 * Provides a BLE gateway onto an Animation Model.
bluetooth_mdw 74:9771cd712730 29 */
bluetooth_mdw 74:9771cd712730 30
bluetooth_mdw 74:9771cd712730 31 #include "MicroBitConfig.h"
bluetooth_mdw 74:9771cd712730 32 #include "MicroBitAnimationService.h"
bluetooth_mdw 74:9771cd712730 33 #include "ble/UUID.h"
bluetooth_mdw 74:9771cd712730 34 #include "Animator.h"
bluetooth_mdw 74:9771cd712730 35
bluetooth_mdw 74:9771cd712730 36 /**
bluetooth_mdw 74:9771cd712730 37 * Constructor.
bluetooth_mdw 74:9771cd712730 38 * Create a representation of the AnimationService
bluetooth_mdw 74:9771cd712730 39 * @param _ble The instance of a BLE device that we're running on.
bluetooth_mdw 74:9771cd712730 40 */
bluetooth_mdw 74:9771cd712730 41 MicroBitAnimationService::MicroBitAnimationService(BLEDevice &_ble) :
bluetooth_mdw 74:9771cd712730 42 ble(_ble)
bluetooth_mdw 74:9771cd712730 43 {
bluetooth_mdw 77:9909cbcd0ece 44 // TODO: Three GattCharacteristic objects. UUID, valuePTR, length, max length, properties.
bluetooth_mdw 77:9909cbcd0ece 45
bluetooth_mdw 74:9771cd712730 46
bluetooth_mdw 77:9909cbcd0ece 47 // TODO: initialise characteristic value buffers
bluetooth_mdw 74:9771cd712730 48
bluetooth_mdw 77:9909cbcd0ece 49
bluetooth_mdw 74:9771cd712730 50
bluetooth_mdw 74:9771cd712730 51 // Set default security requirements - optional
bluetooth_mdw 74:9771cd712730 52 // animationTypeCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
bluetooth_mdw 74:9771cd712730 53 // animationStatusCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
bluetooth_mdw 74:9771cd712730 54 // animationControlCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
bluetooth_mdw 74:9771cd712730 55
bluetooth_mdw 77:9909cbcd0ece 56 // TODO: create GattService containing the three characteristics
bluetooth_mdw 74:9771cd712730 57 // create an array of our characteristics so we can pass them to the service when we create it
bluetooth_mdw 74:9771cd712730 58
bluetooth_mdw 74:9771cd712730 59 // create the animation service and specify its characteristics
bluetooth_mdw 77:9909cbcd0ece 60
bluetooth_mdw 77:9909cbcd0ece 61
bluetooth_mdw 74:9771cd712730 62
bluetooth_mdw 77:9909cbcd0ece 63 // TODO: add the service to the Bluetooth attribute table
bluetooth_mdw 77:9909cbcd0ece 64
bluetooth_mdw 74:9771cd712730 65
bluetooth_mdw 77:9909cbcd0ece 66 // TODO: take a note of the handles of our new characteristics now that they're in the attribute table
bluetooth_mdw 77:9909cbcd0ece 67
bluetooth_mdw 77:9909cbcd0ece 68
bluetooth_mdw 77:9909cbcd0ece 69 // TODO: set the attribute table's characteristic values to the initialised buffer values
bluetooth_mdw 74:9771cd712730 70
bluetooth_mdw 74:9771cd712730 71
bluetooth_mdw 77:9909cbcd0ece 72 // TODO: register a callback function for when a characteristic is written to
bluetooth_mdw 74:9771cd712730 73
bluetooth_mdw 74:9771cd712730 74 // subscribe to animation status events so they can be notified to the connected client
bluetooth_mdw 74:9771cd712730 75 if (EventModel::defaultEventBus)
bluetooth_mdw 74:9771cd712730 76 EventModel::defaultEventBus->listen(ANIMATION_STATUS_EVENT, MICROBIT_EVT_ANY, this, &MicroBitAnimationService::animationStatusUpdate, MESSAGE_BUS_LISTENER_IMMEDIATE);
bluetooth_mdw 74:9771cd712730 77 }
bluetooth_mdw 74:9771cd712730 78
bluetooth_mdw 74:9771cd712730 79
bluetooth_mdw 74:9771cd712730 80 /**
bluetooth_mdw 74:9771cd712730 81 * Callback. Invoked when any of our attributes are written via BLE.
bluetooth_mdw 74:9771cd712730 82 */
bluetooth_mdw 74:9771cd712730 83 void MicroBitAnimationService::onDataWritten(const GattWriteCallbackParams *params)
bluetooth_mdw 74:9771cd712730 84 {
bluetooth_mdw 74:9771cd712730 85
bluetooth_mdw 77:9909cbcd0ece 86 // TODO: handle write to animation type characteristic
bluetooth_mdw 74:9771cd712730 87
bluetooth_mdw 77:9909cbcd0ece 88
bluetooth_mdw 77:9909cbcd0ece 89 // TODO: handle write to animation control characteristic
bluetooth_mdw 77:9909cbcd0ece 90
bluetooth_mdw 77:9909cbcd0ece 91
bluetooth_mdw 74:9771cd712730 92 }
bluetooth_mdw 74:9771cd712730 93
bluetooth_mdw 74:9771cd712730 94 void MicroBitAnimationService::animationStatusUpdate(MicroBitEvent e)
bluetooth_mdw 74:9771cd712730 95 {
bluetooth_mdw 77:9909cbcd0ece 96 // TODO: notify connected client of change to the animation status characteristic
bluetooth_mdw 77:9909cbcd0ece 97
bluetooth_mdw 77:9909cbcd0ece 98
bluetooth_mdw 74:9771cd712730 99 }
bluetooth_mdw 74:9771cd712730 100
bluetooth_mdw 74:9771cd712730 101 const uint8_t MicroBitAnimationServiceUUID[] = {
bluetooth_mdw 74:9771cd712730 102 0xe9,0x5d,0x71,0x70,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
bluetooth_mdw 74:9771cd712730 103 };
bluetooth_mdw 74:9771cd712730 104
bluetooth_mdw 74:9771cd712730 105 const uint8_t MicroBitAnimationServiceAnimationTypeCharacteristicUUID[] = {
bluetooth_mdw 74:9771cd712730 106 0xe9,0x5d,0xC3,0x06,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
bluetooth_mdw 74:9771cd712730 107 };
bluetooth_mdw 74:9771cd712730 108
bluetooth_mdw 74:9771cd712730 109 const uint8_t MicroBitAnimationServiceAnimationStatusCharacteristicUUID[] = {
bluetooth_mdw 74:9771cd712730 110 0xe9,0x5d,0x45,0x92,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
bluetooth_mdw 74:9771cd712730 111 };
bluetooth_mdw 74:9771cd712730 112
bluetooth_mdw 74:9771cd712730 113 const uint8_t MicroBitAnimationServiceAnimationControlCharacteristicUUID[] = {
bluetooth_mdw 74:9771cd712730 114 0xe9,0x5d,0xb8,0x4c,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8
bluetooth_mdw 74:9771cd712730 115 };