From 95ecb7c4f9fad4c72e680c085760bb4a15d32d8f Mon Sep 17 00:00:00 2001 From: Pawel Spychalski Date: Wed, 23 May 2018 15:21:11 +0200 Subject: [PATCH] Outgoing bind frame --- crossbow/crossbow.ino | 9 +++++++++ crossbow/qsp.cpp | 9 +++++++++ crossbow/qsp.h | 3 ++- crossbow/tx_oled.cpp | 14 +++++++++++++- crossbow/tx_oled.h | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index cacdf0a..0999751 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -263,6 +263,11 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) { #ifdef DEVICE_MODE_TX int8_t getFrameToTransmit(QspConfiguration_t *qsp) { + + if (platformNode.isBindMode) { + return QSP_FRAME_BIND; + } + int8_t retVal = txSendSequence[currentSequenceIndex]; currentSequenceIndex++; @@ -380,6 +385,10 @@ void loop(void) case QSP_FRAME_RC_DATA: encodeRcDataPayload(&qsp, PLATFORM_CHANNEL_COUNT); break; + + case QSP_FRAME_BIND: + encodeBindPayload(&qsp, platformNode.bindKey); + break; } transmitPayload = true; diff --git a/crossbow/qsp.cpp b/crossbow/qsp.cpp index db6d479..5642772 100644 --- a/crossbow/qsp.cpp +++ b/crossbow/qsp.cpp @@ -237,4 +237,13 @@ void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros) { qsp->payload[3] = (currentMicros >> 24) & 255; qsp->payloadLength = qspFrameLengths[QSP_FRAME_PING]; +} + +void encodeBindPayload(QspConfiguration_t *qsp, uint8_t bindKey[]) { + + for (uint8_t i = 0; i < qspFrameLengths[QSP_FRAME_PING]; i++) { + qsp->payload[i] = bindKey[i]; + } + + qsp->payloadLength = qspFrameLengths[QSP_FRAME_PING]; } \ No newline at end of file diff --git a/crossbow/qsp.h b/crossbow/qsp.h index 9312f11..26aaab1 100644 --- a/crossbow/qsp.h +++ b/crossbow/qsp.h @@ -19,4 +19,5 @@ void qspDecodeIncomingFrame( void qspClearPayload(QspConfiguration_t *qsp); void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size, uint8_t radioChannel, uint8_t bindKey[]); -void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros); \ No newline at end of file +void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros); +void encodeBindPayload(QspConfiguration_t *qsp, uint8_t bindKey[]); \ No newline at end of file diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp index dbbf784..ee914ce 100644 --- a/crossbow/tx_oled.cpp +++ b/crossbow/tx_oled.cpp @@ -22,6 +22,13 @@ void TxOled::loop() { //Second button has notthing to do over here break; + case TX_PAGE_BIND: + if (button1.getState() == TACTILE_STATE_LONG_PRESS) { + platformNode.isBindMode = !platformNode.isBindMode; + update = true; + } + break; + case TX_PAGE_STATS: //Second button refreshes this page if (button1.getState() == TACTILE_STATE_SHORT_PRESS) { @@ -93,7 +100,12 @@ void TxOled::renderPageBind() { _display.clear(); _display.draw1x2String(0, 0, "Bind"); - snprintf(buf, OLED_COL_COUNT, "Bind?"); + if (platformNode.isBindMode) { + snprintf(buf, OLED_COL_COUNT, "Binding!!"); + } else { + snprintf(buf, OLED_COL_COUNT, "Bind?"); + } + _display.draw1x2String(0, 4, buf); } diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h index 7a4191f..86b5a4e 100644 --- a/crossbow/tx_oled.h +++ b/crossbow/tx_oled.h @@ -8,8 +8,10 @@ #include "variables.h" #include "tactile.h" #include "radio_node.h" +#include "platform_node.h" extern RadioNode radioNode; +extern PlatformNode platformNode; extern RxDeviceState_t rxDeviceState; extern TxDeviceState_t txDeviceState; extern Tactile button0;