Solution for Bluetooth SIG hands-on training course

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

Dependents:   microbit

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

Committer:
bluetooth_mdw
Date:
Fri Mar 24 06:20:38 2017 +0000
Revision:
82:91e085d6ad72
Parent:
74:9771cd712730
Removed comment re: writing initial values to the Attribute Table. Added comments to onDataWritten. Removed solution details.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan Austin 1:8aa5cdb4ab67 1 /*
Jonathan Austin 1:8aa5cdb4ab67 2 The MIT License (MIT)
Jonathan Austin 1:8aa5cdb4ab67 3
Jonathan Austin 1:8aa5cdb4ab67 4 Copyright (c) 2016 British Broadcasting Corporation.
Jonathan Austin 1:8aa5cdb4ab67 5 This software is provided by Lancaster University by arrangement with the BBC.
Jonathan Austin 1:8aa5cdb4ab67 6
Jonathan Austin 1:8aa5cdb4ab67 7 Permission is hereby granted, free of charge, to any person obtaining a
Jonathan Austin 1:8aa5cdb4ab67 8 copy of this software and associated documentation files (the "Software"),
Jonathan Austin 1:8aa5cdb4ab67 9 to deal in the Software without restriction, including without limitation
Jonathan Austin 1:8aa5cdb4ab67 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
Jonathan Austin 1:8aa5cdb4ab67 11 and/or sell copies of the Software, and to permit persons to whom the
Jonathan Austin 1:8aa5cdb4ab67 12 Software is furnished to do so, subject to the following conditions:
Jonathan Austin 1:8aa5cdb4ab67 13
Jonathan Austin 1:8aa5cdb4ab67 14 The above copyright notice and this permission notice shall be included in
Jonathan Austin 1:8aa5cdb4ab67 15 all copies or substantial portions of the Software.
Jonathan Austin 1:8aa5cdb4ab67 16
Jonathan Austin 1:8aa5cdb4ab67 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Jonathan Austin 1:8aa5cdb4ab67 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jonathan Austin 1:8aa5cdb4ab67 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Jonathan Austin 1:8aa5cdb4ab67 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Jonathan Austin 1:8aa5cdb4ab67 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Jonathan Austin 1:8aa5cdb4ab67 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Jonathan Austin 1:8aa5cdb4ab67 23 DEALINGS IN THE SOFTWARE.
Jonathan Austin 1:8aa5cdb4ab67 24 */
Jonathan Austin 1:8aa5cdb4ab67 25
Jonathan Austin 1:8aa5cdb4ab67 26 #ifndef MICROBIT_ACCELEROMETER_SERVICE_H
Jonathan Austin 1:8aa5cdb4ab67 27 #define MICROBIT_ACCELEROMETER_SERVICE_H
Jonathan Austin 1:8aa5cdb4ab67 28
Jonathan Austin 1:8aa5cdb4ab67 29 #include "MicroBitConfig.h"
Jonathan Austin 1:8aa5cdb4ab67 30 #include "ble/BLE.h"
Jonathan Austin 1:8aa5cdb4ab67 31 #include "MicroBitAccelerometer.h"
Jonathan Austin 1:8aa5cdb4ab67 32 #include "EventModel.h"
Jonathan Austin 1:8aa5cdb4ab67 33
Jonathan Austin 1:8aa5cdb4ab67 34 // UUIDs for our service and characteristics
Jonathan Austin 1:8aa5cdb4ab67 35 extern const uint8_t MicroBitAccelerometerServiceUUID[];
Jonathan Austin 1:8aa5cdb4ab67 36 extern const uint8_t MicroBitAccelerometerServiceDataUUID[];
Jonathan Austin 1:8aa5cdb4ab67 37 extern const uint8_t MicroBitAccelerometerServicePeriodUUID[];
Jonathan Austin 1:8aa5cdb4ab67 38
Jonathan Austin 1:8aa5cdb4ab67 39 /**
Jonathan Austin 1:8aa5cdb4ab67 40 * Class definition for a MicroBit BLE Accelerometer Service.
Jonathan Austin 1:8aa5cdb4ab67 41 * Provides access to live accelerometer data via Bluetooth, and provides basic configuration options.
Jonathan Austin 1:8aa5cdb4ab67 42 */
Jonathan Austin 1:8aa5cdb4ab67 43 class MicroBitAccelerometerService
Jonathan Austin 1:8aa5cdb4ab67 44 {
Jonathan Austin 1:8aa5cdb4ab67 45 public:
Jonathan Austin 1:8aa5cdb4ab67 46
Jonathan Austin 1:8aa5cdb4ab67 47 /**
Jonathan Austin 1:8aa5cdb4ab67 48 * Constructor.
Jonathan Austin 1:8aa5cdb4ab67 49 * Create a representation of the AccelerometerService
Jonathan Austin 1:8aa5cdb4ab67 50 * @param _ble The instance of a BLE device that we're running on.
Jonathan Austin 1:8aa5cdb4ab67 51 * @param _accelerometer An instance of MicroBitAccelerometer.
Jonathan Austin 1:8aa5cdb4ab67 52 */
Jonathan Austin 1:8aa5cdb4ab67 53 MicroBitAccelerometerService(BLEDevice &_ble, MicroBitAccelerometer &_acclerometer);
Jonathan Austin 1:8aa5cdb4ab67 54
Jonathan Austin 1:8aa5cdb4ab67 55
Jonathan Austin 1:8aa5cdb4ab67 56 private:
Jonathan Austin 1:8aa5cdb4ab67 57
Jonathan Austin 1:8aa5cdb4ab67 58 /**
Jonathan Austin 1:8aa5cdb4ab67 59 * Callback. Invoked when any of our attributes are written via BLE.
Jonathan Austin 1:8aa5cdb4ab67 60 */
Jonathan Austin 1:8aa5cdb4ab67 61 void onDataWritten(const GattWriteCallbackParams *params);
Jonathan Austin 1:8aa5cdb4ab67 62
Jonathan Austin 1:8aa5cdb4ab67 63 /**
Jonathan Austin 1:8aa5cdb4ab67 64 * Accelerometer update callback
Jonathan Austin 1:8aa5cdb4ab67 65 */
Jonathan Austin 1:8aa5cdb4ab67 66 void accelerometerUpdate(MicroBitEvent e);
Jonathan Austin 1:8aa5cdb4ab67 67
Jonathan Austin 1:8aa5cdb4ab67 68 // Bluetooth stack we're running on.
Jonathan Austin 1:8aa5cdb4ab67 69 BLEDevice &ble;
Jonathan Austin 1:8aa5cdb4ab67 70 MicroBitAccelerometer &accelerometer;
Jonathan Austin 1:8aa5cdb4ab67 71
Jonathan Austin 1:8aa5cdb4ab67 72 // memory for our 8 bit control characteristics.
Jonathan Austin 1:8aa5cdb4ab67 73 uint16_t accelerometerDataCharacteristicBuffer[3];
Jonathan Austin 1:8aa5cdb4ab67 74 uint16_t accelerometerPeriodCharacteristicBuffer;
Jonathan Austin 1:8aa5cdb4ab67 75
Jonathan Austin 1:8aa5cdb4ab67 76 // Handles to access each characteristic when they are held by Soft Device.
Jonathan Austin 1:8aa5cdb4ab67 77 GattAttribute::Handle_t accelerometerDataCharacteristicHandle;
Jonathan Austin 1:8aa5cdb4ab67 78 GattAttribute::Handle_t accelerometerPeriodCharacteristicHandle;
Jonathan Austin 1:8aa5cdb4ab67 79 };
Jonathan Austin 1:8aa5cdb4ab67 80
Jonathan Austin 1:8aa5cdb4ab67 81
Jonathan Austin 1:8aa5cdb4ab67 82 #endif