init

Dependencies:   BLE_API mbed nRF51822

Committer:
jslater8
Date:
Mon Aug 17 09:49:55 2015 +0000
Revision:
2:95c770f35636
Initial

Who changed what in which revision?

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