ble_button_test

Dependencies:   mbed BLE_API nRF51822

Committer:
mesoln
Date:
Tue Sep 17 15:58:36 2019 +0000
Revision:
1:950af3c28eef
Parent:
0:e6839efb5545
ble_button_name

Who changed what in which revision?

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