vbfgh

Dependencies:   BLE_API HCSR04 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_LED_Button_Nucleo by Jan Jongboom

Committer:
janjongboom
Date:
Fri Apr 29 11:44:02 2016 +0000
Revision:
11:5e43f35f64a8
Child:
14:c75f17f554c1
BLE Workshop, LED and Button service

Who changed what in which revision?

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