cool

Dependencies:   BLE_API mbed nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DistanceService.h Source File

DistanceService.h

00001 /* ARM University Program Microcontroller Library
00002  * 
00003  * Distance Service
00004  *
00005  * This software is distributed under an "AS IS" BASIS,
00006  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00007  */
00008 
00009 #ifndef __BLE_DISTANCE_SERVICE_H__
00010 #define __BLE_DISTANCE_SERVICE_H__
00011 
00012 #define UUID_DISTANCE 0x2000
00013 #define UUID_DISTANCE_SERVICE 0x8888
00014 
00015 #include "BLEDevice.h"
00016 
00017 /* Distance Service (Custom)    */
00018 /* Characteristics:     */
00019 /*  - Distance (Custom) */
00020 
00021 
00022  class DistanceService {
00023  public:
00024     /**
00025      * Constructor.
00026      *
00027      * param[in] _ble
00028      *               Reference to the underlying BLEDevice.
00029      *
00030      * param[in] distance in millimeters (16-bit signed, 2 decimals).
00031      *               initial value for the distance     
00032      */
00033      
00034      DistanceService(BLEDevice &_ble, uint8_t initial_value){   
00035         ble = BLEDevice(_ble);
00036         distanceCharacteristic = GattCharacteristic(
00037             UUID_DISTANCE,
00038             (uint8_t *)&initial_value, 
00039             sizeof(uint16_t), 
00040             sizeof(uint16_t),
00041             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY
00042         );
00043         GattCharacteristic *charTable[] = {&distanceCharacteristic};
00044         GattService distanceService(UUID_DISTANCE_SERVICE, charTable, 1);
00045         ble.addService(distanceService);
00046         ble.updateCharacteristicValue(distanceCharacteristic.getValueHandle(), (uint8_t *) &initial_value, sizeof(uint32_t));
00047      }
00048 
00049  // Complete your code here.
00050     void updateDistance(uint32_t distance) {
00051         ble.updateCharacteristicValue(distanceCharacteristic.getValueHandle(), (uint8_t *) distance, sizeof(uint32_t));
00052     }
00053 
00054  private:
00055     BLEDevice &ble;
00056 
00057     //Declare you GattCharacteristic objects here.
00058     
00059     GattCharacteristic distanceCharacteristic;
00060 };
00061 
00062 #endif /* #ifndef __BLE_DISTANCE_SERVICE_H__*/
00063 
00064 
00065 // *******************************ARM University Program Copyright � ARM Ltd 2015*************************************//