Attempting to publish a tree

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MicroBitLEDService.h Source File

MicroBitLEDService.h

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 EVENT 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 #ifndef MICROBIT_LED_SERVICE_H
00027 #define MICROBIT_LED_SERVICE_H
00028 
00029 #include "MicroBitConfig.h"
00030 #include "ble/BLE.h"
00031 #include "MicroBitDisplay.h"
00032 
00033 // Defines the buffer size for scrolling text over BLE, hence also defines
00034 // the maximum string length that can be scrolled via the BLE service.
00035 #define MICROBIT_BLE_MAXIMUM_SCROLLTEXT         20
00036 
00037 // UUIDs for our service and characteristics
00038 extern const uint8_t  MicroBitLEDServiceUUID[];
00039 extern const uint8_t  MicroBitLEDServiceMatrixUUID[];
00040 extern const uint8_t  MicroBitLEDServiceTextUUID[];
00041 extern const uint8_t  MicroBitLEDServiceScrollingSpeedUUID[];
00042 
00043 
00044 /**
00045   * Class definition for the custom MicroBit LED Service.
00046   * Provides a BLE service to remotely read and write the state of the LED display.
00047   */
00048 class MicroBitLEDService
00049 {
00050     public:
00051 
00052     /**
00053       * Constructor.
00054       * Create a representation of the LEDService
00055       * @param _ble The instance of a BLE device that we're running on.
00056       * @param _display An instance of MicroBitDisplay to interface with.
00057       */
00058     MicroBitLEDService(BLEDevice &_ble, MicroBitDisplay &_display);
00059 
00060     /**
00061       * Callback. Invoked when any of our attributes are written via BLE.
00062       */
00063     void onDataWritten(const GattWriteCallbackParams *params);
00064 
00065     /**
00066       * Callback. Invoked when any of our attributes are read via BLE.
00067       */
00068     void onDataRead(GattReadAuthCallbackParams *params);
00069 
00070     private:
00071 
00072     // Bluetooth stack we're running on.
00073     BLEDevice           &ble;
00074     MicroBitDisplay     &display;
00075 
00076     // memory for our 8 bit control characteristics.
00077     uint8_t             matrixCharacteristicBuffer[5];
00078     uint16_t            scrollingSpeedCharacteristicBuffer;
00079     uint8_t             textCharacteristicBuffer[MICROBIT_BLE_MAXIMUM_SCROLLTEXT];
00080 
00081     // Handles to access each characteristic when they are held by Soft Device.
00082     GattAttribute::Handle_t matrixCharacteristicHandle;
00083     GattAttribute::Handle_t textCharacteristicHandle;
00084     GattAttribute::Handle_t scrollingSpeedCharacteristicHandle;
00085 
00086     // We hold a copy of the GattCharacteristic, as mbed's BLE API requires this to provide read callbacks (pity!).
00087     GattCharacteristic  matrixCharacteristic;
00088 };
00089 
00090 
00091 #endif