Seat sensor first upload wokring 07092016

Dependencies:   BLE_API mbed nRF51822

Committer:
samuelmoss
Date:
Wed Sep 07 15:08:48 2016 +0000
Revision:
0:f23a00038055
First upload working 07092016

Who changed what in which revision?

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