Jan Jongboom / Mbed OS ble-devicelink-example

Dependencies:   ChainableLED

Committer:
Jan Jongboom
Date:
Mon May 01 14:04:51 2017 +0200
Revision:
0:cfbdc6a35374
Initial commit

Who changed what in which revision?

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