Petr Manas
/
pdiot-f-mbed
PDIOT Group F project
source/ButtonService.h@5:a06ee79f2c4b, 2019-10-29 (annotated)
- Committer:
- brano2
- Date:
- Tue Oct 29 14:59:35 2019 +0000
- Revision:
- 5:a06ee79f2c4b
- Child:
- 6:0e453739484a
Try bluetooth comms
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 | 5:a06ee79f2c4b | 17 | #ifndef __BLE_BUTTON_SERVICE_H__ |
brano2 | 5:a06ee79f2c4b | 18 | #define __BLE_BUTTON_SERVICE_H__ |
brano2 | 5:a06ee79f2c4b | 19 | |
brano2 | 5:a06ee79f2c4b | 20 | class ImuService { |
brano2 | 5:a06ee79f2c4b | 21 | public: |
brano2 | 5:a06ee79f2c4b | 22 | const static uint16_t BUTTON_SERVICE_UUID = 0xA000; |
brano2 | 5:a06ee79f2c4b | 23 | const static uint16_t BUTTON_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 | 5:a06ee79f2c4b | 27 | acceleration(BUTTON_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 | 5:a06ee79f2c4b | 32 | GattService buttonService(ImuService::BUTTON_SERVICE_UUID, |
brano2 | 5:a06ee79f2c4b | 33 | charTable, |
brano2 | 5:a06ee79f2c4b | 34 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
brano2 | 5:a06ee79f2c4b | 35 | ble.gattServer().addService(buttonService); |
brano2 | 5:a06ee79f2c4b | 36 | } |
brano2 | 5:a06ee79f2c4b | 37 | |
brano2 | 5:a06ee79f2c4b | 38 | void updateImuState(int16_t* newState) { |
brano2 | 5:a06ee79f2c4b | 39 | uint8_t val[6]; |
brano2 | 5:a06ee79f2c4b | 40 | val[0] = (newState[0] & 0xFF00) >> 8; val[1] = newState[0] & 0x00FF; |
brano2 | 5:a06ee79f2c4b | 41 | val[2] = (newState[1] & 0xFF00) >> 8; val[3] = newState[1] & 0x00FF; |
brano2 | 5:a06ee79f2c4b | 42 | val[4] = (newState[2] & 0xFF00) >> 8; val[5] = newState[2] & 0x00FF; |
brano2 | 5:a06ee79f2c4b | 43 | // uint8_t val[6]; |
brano2 | 5:a06ee79f2c4b | 44 | // uint8_t* ptr = (uint8_t *) &newState; //cast the 16bit pointer to an 8bit pointer |
brano2 | 5:a06ee79f2c4b | 45 | // for(int i=0; i<6; i++) |
brano2 | 5:a06ee79f2c4b | 46 | // { |
brano2 | 5:a06ee79f2c4b | 47 | // val[i] = *ptr; //pass data to other array |
brano2 | 5:a06ee79f2c4b | 48 | // ptr++; //move your pointer |
brano2 | 5:a06ee79f2c4b | 49 | // } |
brano2 | 5:a06ee79f2c4b | 50 | // val = (uint8_t *) &newState; |
brano2 | 5:a06ee79f2c4b | 51 | ble.gattServer().write(acceleration.getValueHandle(), |
brano2 | 5:a06ee79f2c4b | 52 | val, |
brano2 | 5:a06ee79f2c4b | 53 | 6); |
brano2 | 5:a06ee79f2c4b | 54 | printf("acc x: %x-%x-%x-%x\r\n", val[0], val[1], val[2], val[3]); |
brano2 | 5:a06ee79f2c4b | 55 | } |
brano2 | 5:a06ee79f2c4b | 56 | |
brano2 | 5:a06ee79f2c4b | 57 | private: |
brano2 | 5:a06ee79f2c4b | 58 | BLE &ble; |
brano2 | 5:a06ee79f2c4b | 59 | ReadOnlyArrayGattCharacteristic<int16_t, 3> acceleration; |
brano2 | 5:a06ee79f2c4b | 60 | }; |
brano2 | 5:a06ee79f2c4b | 61 | |
brano2 | 5:a06ee79f2c4b | 62 | #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */ |