Simple step tracking

Dependencies:   MPU9250 mbed-os

Fork of ST by alonso palomino

Committer:
alonsopg
Date:
Tue Oct 17 20:55:04 2017 +0000
Revision:
3:3157e61f2bfd
Parent:
2:02175845b24c
Child:
4:b741278722c1
iot

Who changed what in which revision?

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