Edson Alcala
/
StepTracking
Simple step tracking
Fork of ST by
ButtonService.h@11:03a4a6e9f27c, 2017-10-22 (annotated)
- Committer:
- EdsonAlcala
- Date:
- Sun Oct 22 14:47:11 2017 +0000
- Revision:
- 11:03a4a6e9f27c
- Parent:
- 10:f5cd99dd9efa
last version
Who changed what in which revision?
User | Revision | Line number | New 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 | |
EdsonAlcala | 9:e265a634306d | 37 | void updateButtonState(float roll, float pitch, float yaw, int16_t gx, int16_t gy, int16_t gz) { |
EdsonAlcala | 4:b741278722c1 | 38 | uint8_t *rollValue; |
EdsonAlcala | 4:b741278722c1 | 39 | rollValue = reinterpret_cast<uint8_t*>(&roll); |
EdsonAlcala | 4:b741278722c1 | 40 | |
EdsonAlcala | 5:2fbd60a970d6 | 41 | uint8_t *pitchValue; |
EdsonAlcala | 5:2fbd60a970d6 | 42 | pitchValue = reinterpret_cast<uint8_t*>(&pitch); |
EdsonAlcala | 5:2fbd60a970d6 | 43 | |
EdsonAlcala | 5:2fbd60a970d6 | 44 | uint8_t *yawValue; |
EdsonAlcala | 5:2fbd60a970d6 | 45 | yawValue = reinterpret_cast<uint8_t*>(&yaw); |
EdsonAlcala | 4:b741278722c1 | 46 | |
EdsonAlcala | 5:2fbd60a970d6 | 47 | uint8_t *gxValue; |
EdsonAlcala | 5:2fbd60a970d6 | 48 | gxValue = reinterpret_cast<uint8_t*>(&gx); |
EdsonAlcala | 5:2fbd60a970d6 | 49 | |
EdsonAlcala | 5:2fbd60a970d6 | 50 | uint8_t *gyValue; |
EdsonAlcala | 5:2fbd60a970d6 | 51 | gyValue = reinterpret_cast<uint8_t*>(&gy); |
EdsonAlcala | 5:2fbd60a970d6 | 52 | |
EdsonAlcala | 5:2fbd60a970d6 | 53 | uint8_t *gzValue; |
EdsonAlcala | 5:2fbd60a970d6 | 54 | gzValue = reinterpret_cast<uint8_t*>(&gz); |
EdsonAlcala | 4:b741278722c1 | 55 | |
EdsonAlcala | 9:e265a634306d | 56 | uint8_t result[20]; |
EdsonAlcala | 9:e265a634306d | 57 | |
EdsonAlcala | 5:2fbd60a970d6 | 58 | copy(rollValue, rollValue + 4, result); |
EdsonAlcala | 5:2fbd60a970d6 | 59 | copy(pitchValue, pitchValue + 4, result + 4); |
EdsonAlcala | 8:1bac78ab3acc | 60 | copy(yawValue, yawValue + 4, result + 8); |
EdsonAlcala | 4:b741278722c1 | 61 | |
EdsonAlcala | 11:03a4a6e9f27c | 62 | copy(gxValue, gxValue + 2, result + 12); |
EdsonAlcala | 11:03a4a6e9f27c | 63 | copy(gyValue, gyValue + 2, result + 14); |
EdsonAlcala | 11:03a4a6e9f27c | 64 | copy(gzValue, gzValue + 2, result + 16); |
EdsonAlcala | 10:f5cd99dd9efa | 65 | |
EdsonAlcala | 11:03a4a6e9f27c | 66 | //uint8_t gxLowerValue = gx & 0xff; |
EdsonAlcala | 11:03a4a6e9f27c | 67 | //uint8_t gxHighValue = gx >> 8 |
EdsonAlcala | 10:f5cd99dd9efa | 68 | |
EdsonAlcala | 11:03a4a6e9f27c | 69 | //uint8_t gyLowerValue = gy & 0xff; |
EdsonAlcala | 11:03a4a6e9f27c | 70 | //uint8_t gyHighValue = gy >> 8 |
EdsonAlcala | 10:f5cd99dd9efa | 71 | |
EdsonAlcala | 11:03a4a6e9f27c | 72 | //uint8_t gzLowerValue = gz & 0xff; |
EdsonAlcala | 11:03a4a6e9f27c | 73 | //uint8_t gzHighValue = gz >> 8 |
EdsonAlcala | 10:f5cd99dd9efa | 74 | |
EdsonAlcala | 11:03a4a6e9f27c | 75 | //result[13] = gxLowerValue; |
EdsonAlcala | 11:03a4a6e9f27c | 76 | //result[14] = gxHighValue; |
EdsonAlcala | 10:f5cd99dd9efa | 77 | |
EdsonAlcala | 11:03a4a6e9f27c | 78 | //result[15] = gyLowerValue; |
EdsonAlcala | 11:03a4a6e9f27c | 79 | //result[16] = gyHighValue; |
EdsonAlcala | 10:f5cd99dd9efa | 80 | |
EdsonAlcala | 11:03a4a6e9f27c | 81 | //result[17] = gzLowerValue; |
EdsonAlcala | 11:03a4a6e9f27c | 82 | //result[18] = gzHighValue; |
EdsonAlcala | 9:e265a634306d | 83 | |
EdsonAlcala | 7:eff79b4c37ab | 84 | ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)result, sizeof(result)); |
alonsopg | 2:02175845b24c | 85 | } |
alonsopg | 2:02175845b24c | 86 | |
alonsopg | 2:02175845b24c | 87 | private: |
alonsopg | 2:02175845b24c | 88 | BLE &ble; |
EdsonAlcala | 9:e265a634306d | 89 | ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(uint8_t[20])> buttonState; |
alonsopg | 2:02175845b24c | 90 | }; |
alonsopg | 2:02175845b24c | 91 | |
alonsopg | 2:02175845b24c | 92 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |