Petr Manas
/
pdiot-f-mbed
PDIOT Group F project
source/ImuService.h@8:ed92317b2c9b, 2019-11-05 (annotated)
- Committer:
- brano2
- Date:
- Tue Nov 05 13:54:48 2019 +0000
- Revision:
- 8:ed92317b2c9b
- Parent:
- 7:db23f12fcd02
Print acceleration at slow rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brano2 | 5:a06ee79f2c4b | 1 | /* mbed Microcontroller Library |
brano2 | 5:a06ee79f2c4b | 2 | * Copyright (c) 2006-2013 ARM Limited |
brano2 | 5:a06ee79f2c4b | 3 | * |
brano2 | 5:a06ee79f2c4b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
brano2 | 5:a06ee79f2c4b | 5 | * you may not use this file except in compliance with the License. |
brano2 | 5:a06ee79f2c4b | 6 | * You may obtain a copy of the License at |
brano2 | 5:a06ee79f2c4b | 7 | * |
brano2 | 5:a06ee79f2c4b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
brano2 | 5:a06ee79f2c4b | 9 | * |
brano2 | 5:a06ee79f2c4b | 10 | * Unless required by applicable law or agreed to in writing, software |
brano2 | 5:a06ee79f2c4b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
brano2 | 5:a06ee79f2c4b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
brano2 | 5:a06ee79f2c4b | 13 | * See the License for the specific language governing permissions and |
brano2 | 5:a06ee79f2c4b | 14 | * limitations under the License. |
brano2 | 5:a06ee79f2c4b | 15 | */ |
brano2 | 5:a06ee79f2c4b | 16 | |
brano2 | 7:db23f12fcd02 | 17 | #ifndef __BLE_IMU_SERVICE_H__ |
brano2 | 7:db23f12fcd02 | 18 | #define __BLE_IMU_SERVICE_H__ |
brano2 | 5:a06ee79f2c4b | 19 | |
brano2 | 5:a06ee79f2c4b | 20 | class ImuService { |
brano2 | 5:a06ee79f2c4b | 21 | public: |
brano2 | 7:db23f12fcd02 | 22 | const static uint16_t IMU_SERVICE_UUID = 0xA000; |
brano2 | 7:db23f12fcd02 | 23 | const static uint16_t IMU_STATE_CHARACTERISTIC_UUID = 0xA001; |
brano2 | 5:a06ee79f2c4b | 24 | |
brano2 | 5:a06ee79f2c4b | 25 | ImuService(BLE &_ble, int16_t* initAcc) : |
brano2 | 5:a06ee79f2c4b | 26 | ble(_ble), |
brano2 | 7:db23f12fcd02 | 27 | acceleration(IMU_STATE_CHARACTERISTIC_UUID, |
brano2 | 5:a06ee79f2c4b | 28 | initAcc, |
brano2 | 5:a06ee79f2c4b | 29 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
brano2 | 5:a06ee79f2c4b | 30 | { |
brano2 | 5:a06ee79f2c4b | 31 | GattCharacteristic *charTable[] = {&acceleration}; |
brano2 | 7:db23f12fcd02 | 32 | GattService imuService(ImuService::IMU_SERVICE_UUID, |
brano2 | 5:a06ee79f2c4b | 33 | charTable, |
brano2 | 5:a06ee79f2c4b | 34 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
brano2 | 7:db23f12fcd02 | 35 | ble.gattServer().addService(imuService); |
brano2 | 5:a06ee79f2c4b | 36 | } |
brano2 | 5:a06ee79f2c4b | 37 | |
brano2 | 6:0e453739484a | 38 | void updateImuState(int16_t newState[3]) { |
brano2 | 6:0e453739484a | 39 | // printf("acc: %d, %d, %d\r\n", newState[0], newState[1], newState[2]); |
brano2 | 5:a06ee79f2c4b | 40 | uint8_t val[6]; |
brano2 | 6:0e453739484a | 41 | val[0] = (newState[0] & 0xFF00) >> 8; val[1] = newState[0] & 0xFF; |
brano2 | 6:0e453739484a | 42 | val[2] = (newState[1] & 0xFF00) >> 8; val[3] = newState[1] & 0xFF; |
brano2 | 6:0e453739484a | 43 | val[4] = (newState[2] & 0xFF00) >> 8; val[5] = newState[2] & 0xFF; |
brano2 | 6:0e453739484a | 44 | // printf("acc x: %x-%x-%x-%x\r\n", val[0], val[1], val[2], val[3]); |
brano2 | 5:a06ee79f2c4b | 45 | ble.gattServer().write(acceleration.getValueHandle(), |
brano2 | 5:a06ee79f2c4b | 46 | val, |
brano2 | 5:a06ee79f2c4b | 47 | 6); |
brano2 | 6:0e453739484a | 48 | // printf("acc x: %x-%x-%x-%x\r\n", val[0], val[1], val[2], val[3]); |
brano2 | 5:a06ee79f2c4b | 49 | } |
brano2 | 5:a06ee79f2c4b | 50 | |
brano2 | 5:a06ee79f2c4b | 51 | private: |
brano2 | 5:a06ee79f2c4b | 52 | BLE &ble; |
brano2 | 5:a06ee79f2c4b | 53 | ReadOnlyArrayGattCharacteristic<int16_t, 3> acceleration; |
brano2 | 5:a06ee79f2c4b | 54 | }; |
brano2 | 5:a06ee79f2c4b | 55 | |
brano2 | 7:db23f12fcd02 | 56 | #endif /* #ifndef __BLE_IMU_SERVICE_H__ */ |