Send continuous stream to mobile

Dependencies:   MPU9250

Fork of pdiot-ble-notify-array by Andrew Bates

Committer:
andrewbates11
Date:
Tue Oct 03 08:46:39 2017 +0000
Revision:
46:dfdf7d1ebde2
Parent:
0:3fe9d5124576
Child:
47:4905acf20758
sends 12 bytes each button press

Who changed what in which revision?

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