HCSR04 Ultrasonic sensor exposed over BLE

Dependencies:   BLE_API HCSR04 mbed nRF51822

Committer:
janjongboom
Date:
Mon May 09 10:26:40 2016 +0000
Revision:
0:470a1164da56
HCSR04 ultrasonic sensor over BLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
janjongboom 0:470a1164da56 1 /* mbed Microcontroller Library
janjongboom 0:470a1164da56 2 * Copyright (c) 2006-2013 ARM Limited
janjongboom 0:470a1164da56 3 *
janjongboom 0:470a1164da56 4 * Licensed under the Apache License, Version 2.0 (the "License");
janjongboom 0:470a1164da56 5 * you may not use this file except in compliance with the License.
janjongboom 0:470a1164da56 6 * You may obtain a copy of the License at
janjongboom 0:470a1164da56 7 *
janjongboom 0:470a1164da56 8 * http://www.apache.org/licenses/LICENSE-2.0
janjongboom 0:470a1164da56 9 *
janjongboom 0:470a1164da56 10 * Unless required by applicable law or agreed to in writing, software
janjongboom 0:470a1164da56 11 * distributed under the License is distributed on an "AS IS" BASIS,
janjongboom 0:470a1164da56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
janjongboom 0:470a1164da56 13 * See the License for the specific language governing permissions and
janjongboom 0:470a1164da56 14 * limitations under the License.
janjongboom 0:470a1164da56 15 */
janjongboom 0:470a1164da56 16
janjongboom 0:470a1164da56 17 #ifndef __BLE_ULTRA_SERVICE_H__
janjongboom 0:470a1164da56 18 #define __BLE_ULTRA_SERVICE_H__
janjongboom 0:470a1164da56 19
janjongboom 0:470a1164da56 20 class UltrasonicService {
janjongboom 0:470a1164da56 21 public:
janjongboom 0:470a1164da56 22 const static uint16_t SERVICE_UUID = 0xA998;
janjongboom 0:470a1164da56 23 const static uint16_t STATE_CHARACTERISTIC_UUID = 0xA999;
janjongboom 0:470a1164da56 24
janjongboom 0:470a1164da56 25 UltrasonicService(BLE &_ble) :
janjongboom 0:470a1164da56 26 ble(_ble), state(STATE_CHARACTERISTIC_UUID, 0, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
janjongboom 0:470a1164da56 27 {
janjongboom 0:470a1164da56 28 GattCharacteristic *charTable[] = {&state};
janjongboom 0:470a1164da56 29 GattService service(UltrasonicService::SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
janjongboom 0:470a1164da56 30 ble.gattServer().addService(service);
janjongboom 0:470a1164da56 31 }
janjongboom 0:470a1164da56 32
janjongboom 0:470a1164da56 33 void updateState(uint32_t newState) {
janjongboom 0:470a1164da56 34 ble.gattServer().write(state.getValueHandle(), (uint8_t *)&newState, sizeof(uint32_t));
janjongboom 0:470a1164da56 35 }
janjongboom 0:470a1164da56 36
janjongboom 0:470a1164da56 37 private:
janjongboom 0:470a1164da56 38 BLE &ble;
janjongboom 0:470a1164da56 39 ReadOnlyGattCharacteristic<uint32_t> state;
janjongboom 0:470a1164da56 40 };
janjongboom 0:470a1164da56 41
janjongboom 0:470a1164da56 42 #endif /* #ifndef __BLE_ULTRA_SERVICE_H__ */
janjongboom 0:470a1164da56 43