PDIOT Group F project

Dependencies:   MPU9250

Committer:
brano2
Date:
Wed Oct 30 13:22:52 2019 +0000
Revision:
6:0e453739484a
Parent:
5:a06ee79f2c4b
Fix bluetooth comms

Who changed what in which revision?

UserRevisionLine numberNew 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 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 5:a06ee79f2c4b 44 // uint8_t val[6];
brano2 5:a06ee79f2c4b 45 // uint8_t* ptr = (uint8_t *) &newState; //cast the 16bit pointer to an 8bit pointer
brano2 5:a06ee79f2c4b 46 // for(int i=0; i<6; i++)
brano2 5:a06ee79f2c4b 47 // {
brano2 5:a06ee79f2c4b 48 // val[i] = *ptr; //pass data to other array
brano2 5:a06ee79f2c4b 49 // ptr++; //move your pointer
brano2 5:a06ee79f2c4b 50 // }
brano2 5:a06ee79f2c4b 51 // val = (uint8_t *) &newState;
brano2 6:0e453739484a 52 // printf("acc x: %x-%x-%x-%x\r\n", val[0], val[1], val[2], val[3]);
brano2 5:a06ee79f2c4b 53 ble.gattServer().write(acceleration.getValueHandle(),
brano2 5:a06ee79f2c4b 54 val,
brano2 5:a06ee79f2c4b 55 6);
brano2 6:0e453739484a 56 // printf("acc x: %x-%x-%x-%x\r\n", val[0], val[1], val[2], val[3]);
brano2 5:a06ee79f2c4b 57 }
brano2 5:a06ee79f2c4b 58
brano2 5:a06ee79f2c4b 59 private:
brano2 5:a06ee79f2c4b 60 BLE &ble;
brano2 5:a06ee79f2c4b 61 ReadOnlyArrayGattCharacteristic<int16_t, 3> acceleration;
brano2 5:a06ee79f2c4b 62 };
brano2 5:a06ee79f2c4b 63
brano2 5:a06ee79f2c4b 64 #endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */