![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dsf
Dependencies: BLE_API mbed nRF51822
Diff: BTDevice.cpp
- Revision:
- 0:b5906c81772b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BTDevice.cpp Sun Feb 05 16:31:58 2017 +0000 @@ -0,0 +1,35 @@ +#include "BTDevice.hpp" + +BTDevice::BTDevice() { + this->ctrl = NULL; +} + +BTDevice::BTDevice(BLE _ble):ble(_ble){} + +BTDevice::~BTDevice() { + delete this->ctrl; +} + +void BTDevice::sendMsg(char *buf, uint16_t length) { + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), (const uint8_t*)buf, length); +} + +int BTDevice::readMsg(uint8_t buf[TXRX_BUF_LEN], uint16_t expectedLen) { + uint16_t bytesRead; + ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); + + return (bytesRead == expectedLen)? bytesRead : -1; +} + +void BTDevice::attachController(Controller *c) { + this->ctrl = c; +} + +void BTDevice::setCtrlRef(float ref) { + this->ctrl->updateRef(ref); +} + +void BTDevice::setCtrlParams(ControllerParams &cp) { + this->ctrl->updateParams(cp); +} +