mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal

Dependencies:   BLE_API nRF51822 mbed-dev-bin

Dependents:   microbit Microbit IoTChallenge1 microbit ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MicroBitTemperatureService.h Source File

MicroBitTemperatureService.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_TEMPERATURE_SERVICE_H
00027 #define MICROBIT_TEMPERATURE_SERVICE_H
00028 
00029 #include "MicroBitConfig.h"
00030 #include "ble/BLE.h"
00031 #include "MicroBitThermometer.h"
00032 #include "EventModel.h"
00033 
00034 // UUIDs for our service and characteristics
00035 extern const uint8_t  MicroBitTemperatureServiceUUID[];
00036 extern const uint8_t  MicroBitTemperatureServiceDataUUID[];
00037 extern const uint8_t  MicroBitTemperatureServicePeriodUUID[];
00038 
00039 
00040 /**
00041   * Class definition for the custom MicroBit Temperature Service.
00042   * Provides a BLE service to remotely read the silicon temperature of the nRF51822.
00043   */
00044 class MicroBitTemperatureService
00045 {
00046     public:
00047 
00048     /**
00049       * Constructor.
00050       * Create a representation of the TemperatureService
00051       * @param _ble The instance of a BLE device that we're running on.
00052       * @param _thermometer An instance of MicroBitThermometer to use as our temperature source.
00053       */
00054     MicroBitTemperatureService(BLEDevice &_ble, MicroBitThermometer &_thermometer);
00055 
00056     /**
00057       * Callback. Invoked when any of our attributes are written via BLE.
00058       */
00059     void onDataWritten(const GattWriteCallbackParams *params);
00060 
00061     /**
00062      * Temperature update callback
00063      */
00064     void temperatureUpdate(MicroBitEvent e);
00065 
00066     private:
00067 
00068     // Bluetooth stack we're running on.
00069     BLEDevice               &ble;
00070     MicroBitThermometer     &thermometer;
00071 
00072     // memory for our 8 bit temperature characteristic.
00073     int8_t             temperatureDataCharacteristicBuffer;
00074     uint16_t           temperaturePeriodCharacteristicBuffer;
00075 
00076     // Handles to access each characteristic when they are held by Soft Device.
00077     GattAttribute::Handle_t temperatureDataCharacteristicHandle;
00078     GattAttribute::Handle_t temperaturePeriodCharacteristicHandle;
00079 };
00080 
00081 
00082 #endif