From d31761a4b3c2995cd3f2ed90e80c2da6d38cd92e Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Mon, 14 May 2018 20:08:45 +0200 Subject: [PATCH 1/5] Basic init page --- crossbow/config.h | 3 +- crossbow/crossbow.ino | 76 ++++++++++++++++++++------------------------------- crossbow/tx_oled.cpp | 39 ++++++++++++++++++++++++++ crossbow/tx_oled.h | 28 +++++++++++++++++++ 4 files changed, 97 insertions(+), 49 deletions(-) create mode 100644 crossbow/tx_oled.cpp create mode 100644 crossbow/tx_oled.h diff --git a/crossbow/config.h b/crossbow/config.h index cfb4482..44c13d4 100644 --- a/crossbow/config.h +++ b/crossbow/config.h @@ -18,7 +18,7 @@ #define DEVICE_MODE_TX // #define DEVICE_MODE_RX -// #define FEATURE_TX_OLED +#define FEATURE_TX_OLED // #define FORCE_TX_WITHOUT_INPUT /* @@ -32,6 +32,5 @@ #define DEBUG_SERIAL // #define DEBUG_PING_PONG // #define DEBUG_LED -// #define DEBUG_TX_INPUT_ON_OLED #endif diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index aae77ff..df4d768 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -57,13 +57,8 @@ volatile int16_t TxInput::channels[TX_INPUT_CHANNEL_COUNT]; BuzzerState_t buzzer; #ifdef FEATURE_TX_OLED -#include "Wire.h" - -#define OLED_RESET -1 -#include -Adafruit_SSD1306 display(OLED_RESET); -uint32_t lastOledTaskTime = 0; - +#include "tx_oled.h" +TxOled oled; #endif #include "tactile.h" @@ -71,11 +66,6 @@ uint32_t lastOledTaskTime = 0; Tactile button0(BUTTON_0_PIN); Tactile button1(BUTTON_1_PIN); - // uint8_t buttonStates[2] = {HIGH, HIGH}; - // uint8_t previousButtonStates[2] = {HIGH, HIGH}; - // uint32_t buttonPressMillis[2] = {0, 0}; - // uint8_t buttonAction[2] = {BUTTON_ACTION_NONE, BUTTON_ACTION_NONE}; - #endif /* @@ -252,13 +242,8 @@ void setup(void) #ifdef DEVICE_MODE_TX #ifdef FEATURE_TX_OLED - Wire.setClock(400000); - - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) - display.setTextSize(1); - display.setTextColor(WHITE); - display.clearDisplay(); - display.display(); + oled.init(&radioState); + oled.page(TX_PAGE_INIT); #endif /* @@ -625,41 +610,38 @@ void loop(void) } #ifdef FEATURE_TX_OLED - if ( - currentMillis - lastOledTaskTime > OLED_UPDATE_RATE - ) { - lastOledTaskTime = currentMillis; - display.clearDisplay(); + // if ( + // currentMillis - lastOledTaskTime > OLED_UPDATE_RATE + // ) { + // lastOledTaskTime = millis(); - display.setTextColor(WHITE, BLACK); - display.setCursor(0, 0); - display.setTextSize(3); - display.print(radioState.rssi); + - display.setCursor(18, 28); - display.setTextSize(2); - display.print(radioState.snr); + // display.setTextColor(WHITE, BLACK); + // display.setCursor(0, 0); + // display.setTextSize(3); + // display.print(radioState.rssi); - display.setCursor(74, 0); - display.setTextSize(3); - display.print(rxDeviceState.rssi); + // display.setCursor(18, 28); + // display.setTextSize(2); + // display.print(radioState.snr); - display.setCursor(92, 28); - display.setTextSize(2); - display.print(rxDeviceState.snr); + // display.setCursor(74, 0); + // display.setTextSize(3); + // display.print(rxDeviceState.rssi); - #ifdef DEBUG_TX_INPUT_ON_OLED - display.setCursor(0, 48); - display.setTextSize(2); - display.print(txInput.channels[0]); - #endif + // display.setCursor(92, 28); + // display.setTextSize(2); + // display.print(rxDeviceState.snr); - display.setCursor(54, 48); - display.setTextSize(2); - display.print(txDeviceState.roundtrip); + // display.setCursor(54, 48); + // display.setTextSize(2); + // display.print(txDeviceState.roundtrip); + + // display.display(); - display.display(); - } + // Serial.println(millis() - lastOledTaskTime); + // } #endif /* diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp new file mode 100644 index 0000000..4d78dac --- /dev/null +++ b/crossbow/tx_oled.cpp @@ -0,0 +1,39 @@ +#include "tx_oled.h" + +TxOled::TxOled(void) { + Adafruit_SSD1306 _display(-1); +} + +void TxOled::init(volatile RadioState_t *radioState) { + _display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) + _display.setTextSize(1); + _display.setTextColor(WHITE); + _display.clearDisplay(); + _display.display(); + + _radioState = radioState; +} + +void TxOled::page(int page) { + switch (page) { + + case TX_PAGE_INIT: + pageInit(); + break; + + } +} + +void TxOled::pageInit(void) { + _display.clearDisplay(); + + _display.setTextColor(WHITE, BLACK); + _display.setCursor(0, 0); + _display.setTextSize(2); + _display.print("Rdy "); + _display.print(_radioState->loraTxPower); + _display.print("dBm"); +} + + + diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h new file mode 100644 index 0000000..2a22f49 --- /dev/null +++ b/crossbow/tx_oled.h @@ -0,0 +1,28 @@ +#pragma once + +#ifndef TX_OLED_H +#define TX_OLED_H + +#include +#include "Wire.h" +#include "variables.h" + +#define OLED_RESET -1 + +enum txOledPages { + TX_PAGE_NONE, + TX_PAGE_INIT, +}; + +class TxOled { + public: + TxOled(void); + void init(volatile RadioState_t *radioState); + void page(int page); + private: + volatile RadioState_t *_radioState; + Adafruit_SSD1306 _display; + void pageInit(void); +}; + +#endif \ No newline at end of file From 0c6017122ab555cc5c7745bbed202ce3b13078a4 Mon Sep 17 00:00:00 2001 From: Pawel Spychalski Date: Tue, 15 May 2018 14:03:43 +0200 Subject: [PATCH 2/5] Basic OLED --- .vscode/c_cpp_properties.json | 2 +- crossbow/config.h | 2 +- crossbow/crossbow.ino | 53 +++++----------- crossbow/tx_oled.cpp | 139 ++++++++++++++++++++++++++++++++++++++++-- crossbow/tx_oled.h | 40 ++++++++++-- 5 files changed, 184 insertions(+), 52 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 1ec14c0..cd1bf77 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -38,7 +38,7 @@ "SPI_HAS_NOTUSINGINTERRUPT", "FEATURE_TX_INPUT_SBUS", "DEVICE_MODE_TX", - "DEVICE_MODE_RX" + "FEATURE_TX_OLED" ] } ], diff --git a/crossbow/config.h b/crossbow/config.h index 44c13d4..9dc179b 100644 --- a/crossbow/config.h +++ b/crossbow/config.h @@ -29,7 +29,7 @@ */ #define FEATURE_TX_INPUT_SBUS -#define DEBUG_SERIAL +// #define DEBUG_SERIAL // #define DEBUG_PING_PONG // #define DEBUG_LED diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index df4d768..b5c9793 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -242,7 +242,13 @@ void setup(void) #ifdef DEVICE_MODE_TX #ifdef FEATURE_TX_OLED - oled.init(&radioState); + oled.init( + &radioState, + &rxDeviceState, + &txDeviceState, + &button0, + &button1 + ); oled.page(TX_PAGE_INIT); #endif @@ -341,17 +347,21 @@ void loop(void) uint32_t currentMillis = millis(); - /* - * If we are not receiving SBUS frames from radio, try to restart serial - */ #ifdef DEVICE_MODE_TX //Process buttons button0.loop(); button1.loop(); +#ifdef FEATURE_TX_OLED + oled.loop(); +#endif + txInput.recoverStuckFrames(); + /* + * If we are not receiving SBUS frames from radio, try to restart serial + */ static uint32_t serialRestartMillis = 0; /* @@ -609,41 +619,6 @@ void loop(void) buzzerContinousMode(BUZZER_MODE_OFF, &buzzer); } -#ifdef FEATURE_TX_OLED - // if ( - // currentMillis - lastOledTaskTime > OLED_UPDATE_RATE - // ) { - // lastOledTaskTime = millis(); - - - - // display.setTextColor(WHITE, BLACK); - // display.setCursor(0, 0); - // display.setTextSize(3); - // display.print(radioState.rssi); - - // display.setCursor(18, 28); - // display.setTextSize(2); - // display.print(radioState.snr); - - // display.setCursor(74, 0); - // display.setTextSize(3); - // display.print(rxDeviceState.rssi); - - // display.setCursor(92, 28); - // display.setTextSize(2); - // display.print(rxDeviceState.snr); - - // display.setCursor(54, 48); - // display.setTextSize(2); - // display.print(txDeviceState.roundtrip); - - // display.display(); - - // Serial.println(millis() - lastOledTaskTime); - // } -#endif - /* * Handle LED updates */ diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp index 4d78dac..16769e5 100644 --- a/crossbow/tx_oled.cpp +++ b/crossbow/tx_oled.cpp @@ -4,7 +4,13 @@ TxOled::TxOled(void) { Adafruit_SSD1306 _display(-1); } -void TxOled::init(volatile RadioState_t *radioState) { +void TxOled::init( + volatile RadioState_t *radioState, + RxDeviceState_t *_rxDeviceState, + TxDeviceState_t *_txDeviceState, + Tactile *button0, + Tactile *button1 +) { _display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) _display.setTextSize(1); _display.setTextColor(WHITE); @@ -12,27 +18,148 @@ void TxOled::init(volatile RadioState_t *radioState) { _display.display(); _radioState = radioState; + _button0 = button0; + _button1 = button1; +} + +void TxOled::loop(void) { + bool update = false; + + //Depending on page, things might be different + switch (_page) { + + case TX_PAGE_INIT: + //Second button has notthing to do over here + break; + + case TX_PAGE_STATS: + //Second button refreshes this page + if (_button1->getState() == TACTILE_STATE_SHORT_PRESS) { + update = true; + } + break; + + } + + //Short press of button0 always toggles no next page + if (_button0->getState() == TACTILE_STATE_SHORT_PRESS) { + _mainPageSequenceIndex++; + if (_mainPageSequenceIndex == TX_OLED_PAGE_COUNT) { + _mainPageSequenceIndex = 0; + } + update = true; + } + + if (update) { + page(pageSequence[_mainPageSequenceIndex]); + } + } void TxOled::page(int page) { switch (page) { - case TX_PAGE_INIT: - pageInit(); + renderPageInit(); + break; + case TX_PAGE_STATS: + renderPageStats(); + break; + case TX_PAGE_PWR: + renderPagePwr(); + break; + case TX_PAGE_BIND: + renderPageBind(); + break; + case TX_PAGE_MODE: + renderPageMode(); break; } + _page = page; } -void TxOled::pageInit(void) { +void TxOled::renderPagePwr(void) { _display.clearDisplay(); - _display.setTextColor(WHITE, BLACK); - _display.setCursor(0, 0); + + //TODO add content + + _display.display(); +} + +void TxOled::renderPageBind(void) { + _display.clearDisplay(); + _display.setTextColor(WHITE, BLACK); + + //TODO add content + + _display.display(); +} + +void TxOled::renderPageMode(void) { + _display.clearDisplay(); + _display.setTextColor(WHITE, BLACK); + + //TODO add content + + _display.display(); +} + +void TxOled::renderPageStats(void) { + _display.clearDisplay(); + _display.setTextColor(WHITE, BLACK); + + _display.setTextSize(3); + _display.print(_radioState->rssi); + + _display.setCursor(18, 28); _display.setTextSize(2); + _display.print(_radioState->snr); + + _display.setCursor(74, 0); + _display.setTextSize(3); + _display.print(_rxDeviceState->rssi); + + _display.setCursor(92, 28); + _display.setTextSize(2); + _display.print(_rxDeviceState->snr); + + _display.setCursor(54, 48); + _display.setTextSize(2); + _display.print(_txDeviceState->roundtrip); + _display.display(); +} + +void TxOled::renderPageInit(void) { + _display.clearDisplay(); + _display.setTextColor(WHITE, BLACK); + _display.setTextSize(2); + + _display.setCursor(0, 0); _display.print("Rdy "); _display.print(_radioState->loraTxPower); _display.print("dBm"); + + _display.setTextSize(2); + _display.setCursor(0, 18); + _display.print("Bandwitdh: "); + _display.print(_radioState->loraBandwidth / 1000); + _display.print("kHz"); + + _display.setCursor(0, 28); + _display.print("SF: "); + _display.print(_radioState->loraSpreadingFactor); + + _display.setCursor(64, 28); + _display.print("CR: "); + _display.print(_radioState->loraCodingRate); + + _display.setCursor(0, 38); + _display.print("Rate: "); + _display.print(1000 / TX_TRANSMIT_SLOT_RATE); + _display.print("Hz"); + + _display.display(); } diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h index 2a22f49..529bb1f 100644 --- a/crossbow/tx_oled.h +++ b/crossbow/tx_oled.h @@ -5,24 +5,54 @@ #include #include "Wire.h" -#include "variables.h" - -#define OLED_RESET -1 +#include "variables.h", +#include "tactile.h" enum txOledPages { TX_PAGE_NONE, TX_PAGE_INIT, + TX_PAGE_STATS, + TX_PAGE_PWR, + TX_PAGE_BIND, + TX_PAGE_MODE +}; + +#define TX_OLED_PAGE_COUNT 5 + +const uint8_t pageSequence[TX_OLED_PAGE_COUNT] = { + TX_PAGE_INIT, + TX_PAGE_STATS, + TX_PAGE_PWR, + TX_PAGE_BIND, + TX_PAGE_MODE }; class TxOled { public: TxOled(void); - void init(volatile RadioState_t *radioState); + void init( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState, + Tactile *button0, + Tactile *button1 + ); + void loop(void); void page(int page); private: volatile RadioState_t *_radioState; + RxDeviceState_t *_rxDeviceState; + TxDeviceState_t *_txDeviceState; + Tactile *_button0; + Tactile *_button1; Adafruit_SSD1306 _display; - void pageInit(void); + void renderPageInit(void); + void renderPageStats(void); + void renderPagePwr(void); + void renderPageBind(void); + void renderPageMode(void); + uint8_t _page = TX_PAGE_NONE; + uint8_t _mainPageSequenceIndex = 0; }; #endif \ No newline at end of file From 37984e21a45d50dbfa94c88f38f0998718897b0b Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 15 May 2018 17:15:17 +0200 Subject: [PATCH 3/5] Basic OLED framework with start and info pages --- crossbow/tx_oled.cpp | 37 ++++++++++++++++++++++++++++--------- crossbow/tx_oled.h | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp index 16769e5..6626e9e 100644 --- a/crossbow/tx_oled.cpp +++ b/crossbow/tx_oled.cpp @@ -82,7 +82,11 @@ void TxOled::renderPagePwr(void) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); - //TODO add content + _display.setCursor(0, 0); + _display.setTextSize(2); + _display.print("PWR"); + + //TODO content _display.display(); } @@ -91,7 +95,11 @@ void TxOled::renderPageBind(void) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); - //TODO add content + _display.setCursor(0, 0); + _display.setTextSize(2); + _display.print("Bind"); + + //TODO content _display.display(); } @@ -100,7 +108,11 @@ void TxOled::renderPageMode(void) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); - //TODO add content + _display.setCursor(0, 0); + _display.setTextSize(2); + _display.print("Mode"); + + //TODO content _display.display(); } @@ -109,6 +121,7 @@ void TxOled::renderPageStats(void) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); + _display.setCursor(0, 0); _display.setTextSize(3); _display.print(_radioState->rssi); @@ -126,7 +139,13 @@ void TxOled::renderPageStats(void) { _display.setCursor(54, 48); _display.setTextSize(2); - _display.print(_txDeviceState->roundtrip); + + if (_txDeviceState->roundtrip < 100) { + _display.print(_txDeviceState->roundtrip); + } else { + _display.print(0); + } + _display.display(); } @@ -140,21 +159,21 @@ void TxOled::renderPageInit(void) { _display.print(_radioState->loraTxPower); _display.print("dBm"); - _display.setTextSize(2); - _display.setCursor(0, 18); + _display.setTextSize(1); + _display.setCursor(0, 32); _display.print("Bandwitdh: "); _display.print(_radioState->loraBandwidth / 1000); _display.print("kHz"); - _display.setCursor(0, 28); + _display.setCursor(0, 42); _display.print("SF: "); _display.print(_radioState->loraSpreadingFactor); - _display.setCursor(64, 28); + _display.setCursor(64, 42); _display.print("CR: "); _display.print(_radioState->loraCodingRate); - _display.setCursor(0, 38); + _display.setCursor(0, 52); _display.print("Rate: "); _display.print(1000 / TX_TRANSMIT_SLOT_RATE); _display.print("Hz"); diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h index 529bb1f..9afd2a3 100644 --- a/crossbow/tx_oled.h +++ b/crossbow/tx_oled.h @@ -5,7 +5,7 @@ #include #include "Wire.h" -#include "variables.h", +#include "variables.h" #include "tactile.h" enum txOledPages { From ab5806bf53ac303f55e34e796df60dea6e60350e Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 15 May 2018 17:44:50 +0200 Subject: [PATCH 4/5] do not store pointers, this just do not work --- .vscode/arduino.json | 2 +- .vscode/c_cpp_properties.json | 6 ++- .vscode/settings.json | 3 +- crossbow/crossbow.ino | 15 ++++-- crossbow/tx_oled.cpp | 105 +++++++++++++++++++++++++----------------- crossbow/tx_oled.h | 48 +++++++++++++------ 6 files changed, 114 insertions(+), 65 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 0ca9fe3..09e7173 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,6 +1,6 @@ { "board": "bsfrance:avr:lora32u4", "sketch": "crossbow/crossbow.ino", - "port": "COM5", + "port": "COM11", "output": "../build" } \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index cd1bf77..e5dfcc5 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,12 +3,14 @@ { "name": "Win32", "includePath": [ - "${workspaceRoot}" + "${workspaceRoot}", + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" ], "browse": { "limitSymbolsToIncludedHeaders": false, "path": [ - "${workspaceRoot}" + "${workspaceRoot}", + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" ] }, "intelliSenseMode": "msvc-x64", diff --git a/.vscode/settings.json b/.vscode/settings.json index 93492f4..77f0cd2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { - "variables.h": "c" + "variables.h": "c", + "arduino.h": "c" }, "files.exclude": { "**/build": true diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index b5c9793..643e353 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -242,14 +242,13 @@ void setup(void) #ifdef DEVICE_MODE_TX #ifdef FEATURE_TX_OLED - oled.init( + oled.init(); + oled.page( &radioState, &rxDeviceState, &txDeviceState, - &button0, - &button1 + TX_PAGE_INIT ); - oled.page(TX_PAGE_INIT); #endif /* @@ -354,7 +353,13 @@ void loop(void) button1.loop(); #ifdef FEATURE_TX_OLED - oled.loop(); + oled.loop( + &radioState, + &rxDeviceState, + &txDeviceState, + &button0, + &button1 + ); #endif txInput.recoverStuckFrames(); diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp index 6626e9e..3d1a90a 100644 --- a/crossbow/tx_oled.cpp +++ b/crossbow/tx_oled.cpp @@ -4,25 +4,21 @@ TxOled::TxOled(void) { Adafruit_SSD1306 _display(-1); } -void TxOled::init( - volatile RadioState_t *radioState, - RxDeviceState_t *_rxDeviceState, - TxDeviceState_t *_txDeviceState, - Tactile *button0, - Tactile *button1 -) { +void TxOled::init() { _display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) _display.setTextSize(1); _display.setTextColor(WHITE); _display.clearDisplay(); _display.display(); - - _radioState = radioState; - _button0 = button0; - _button1 = button1; } -void TxOled::loop(void) { +void TxOled::loop( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState, + Tactile *button0, + Tactile *button1 +) { bool update = false; //Depending on page, things might be different @@ -34,7 +30,7 @@ void TxOled::loop(void) { case TX_PAGE_STATS: //Second button refreshes this page - if (_button1->getState() == TACTILE_STATE_SHORT_PRESS) { + if (button1->getState() == TACTILE_STATE_SHORT_PRESS) { update = true; } break; @@ -42,7 +38,7 @@ void TxOled::loop(void) { } //Short press of button0 always toggles no next page - if (_button0->getState() == TACTILE_STATE_SHORT_PRESS) { + if (button0->getState() == TACTILE_STATE_SHORT_PRESS) { _mainPageSequenceIndex++; if (_mainPageSequenceIndex == TX_OLED_PAGE_COUNT) { _mainPageSequenceIndex = 0; @@ -51,34 +47,48 @@ void TxOled::loop(void) { } if (update) { - page(pageSequence[_mainPageSequenceIndex]); + page( + radioState, + rxDeviceState, + txDeviceState, + pageSequence[_mainPageSequenceIndex] + ); } } -void TxOled::page(int page) { +void TxOled::page( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState, + int page +) { switch (page) { case TX_PAGE_INIT: - renderPageInit(); + renderPageInit(radioState, rxDeviceState, txDeviceState); break; case TX_PAGE_STATS: - renderPageStats(); + renderPageStats(radioState, rxDeviceState, txDeviceState); break; case TX_PAGE_PWR: - renderPagePwr(); + renderPagePwr(radioState, rxDeviceState, txDeviceState); break; case TX_PAGE_BIND: - renderPageBind(); + renderPageBind(radioState, rxDeviceState, txDeviceState); break; case TX_PAGE_MODE: - renderPageMode(); + renderPageMode(radioState, rxDeviceState, txDeviceState); break; } _page = page; } -void TxOled::renderPagePwr(void) { +void TxOled::renderPagePwr( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState +) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); @@ -91,7 +101,11 @@ void TxOled::renderPagePwr(void) { _display.display(); } -void TxOled::renderPageBind(void) { +void TxOled::renderPageBind( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState +) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); @@ -104,7 +118,11 @@ void TxOled::renderPageBind(void) { _display.display(); } -void TxOled::renderPageMode(void) { +void TxOled::renderPageMode( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState +) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); @@ -117,61 +135,64 @@ void TxOled::renderPageMode(void) { _display.display(); } -void TxOled::renderPageStats(void) { +void TxOled::renderPageStats( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState +) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); _display.setCursor(0, 0); _display.setTextSize(3); - _display.print(_radioState->rssi); + _display.print(radioState->rssi); _display.setCursor(18, 28); _display.setTextSize(2); - _display.print(_radioState->snr); + _display.print(radioState->snr); _display.setCursor(74, 0); _display.setTextSize(3); - _display.print(_rxDeviceState->rssi); + _display.print(rxDeviceState->rssi); _display.setCursor(92, 28); _display.setTextSize(2); - _display.print(_rxDeviceState->snr); + _display.print(rxDeviceState->snr); _display.setCursor(54, 48); - _display.setTextSize(2); - - if (_txDeviceState->roundtrip < 100) { - _display.print(_txDeviceState->roundtrip); - } else { - _display.print(0); - } - + _display.setTextSize(2); + _display.print(txDeviceState->roundtrip); + _display.display(); } -void TxOled::renderPageInit(void) { +void TxOled::renderPageInit( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState +) { _display.clearDisplay(); _display.setTextColor(WHITE, BLACK); _display.setTextSize(2); _display.setCursor(0, 0); _display.print("Rdy "); - _display.print(_radioState->loraTxPower); + _display.print(radioState->loraTxPower); _display.print("dBm"); _display.setTextSize(1); _display.setCursor(0, 32); _display.print("Bandwitdh: "); - _display.print(_radioState->loraBandwidth / 1000); + _display.print(radioState->loraBandwidth / 1000); _display.print("kHz"); _display.setCursor(0, 42); _display.print("SF: "); - _display.print(_radioState->loraSpreadingFactor); + _display.print(radioState->loraSpreadingFactor); _display.setCursor(64, 42); _display.print("CR: "); - _display.print(_radioState->loraCodingRate); + _display.print(radioState->loraCodingRate); _display.setCursor(0, 52); _display.print("Rate: "); diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h index 9afd2a3..cd43e13 100644 --- a/crossbow/tx_oled.h +++ b/crossbow/tx_oled.h @@ -30,27 +30,47 @@ const uint8_t pageSequence[TX_OLED_PAGE_COUNT] = { class TxOled { public: TxOled(void); - void init( + void init(); + void loop( volatile RadioState_t *radioState, RxDeviceState_t *rxDeviceState, TxDeviceState_t *txDeviceState, Tactile *button0, Tactile *button1 - ); - void loop(void); - void page(int page); + ); + void page( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState, + int page + ); private: - volatile RadioState_t *_radioState; - RxDeviceState_t *_rxDeviceState; - TxDeviceState_t *_txDeviceState; - Tactile *_button0; - Tactile *_button1; Adafruit_SSD1306 _display; - void renderPageInit(void); - void renderPageStats(void); - void renderPagePwr(void); - void renderPageBind(void); - void renderPageMode(void); + void renderPageInit( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState + ); + void renderPageStats( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState + ); + void renderPagePwr( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState + ); + void renderPageBind( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState + ); + void renderPageMode( + volatile RadioState_t *radioState, + RxDeviceState_t *rxDeviceState, + TxDeviceState_t *txDeviceState + ); uint8_t _page = TX_PAGE_NONE; uint8_t _mainPageSequenceIndex = 0; }; From 84ec6434e4af936ca2e6f786fbac460068ff8bc9 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 15 May 2018 17:51:58 +0200 Subject: [PATCH 5/5] Additional pages --- crossbow/tx_oled.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp index 3d1a90a..cd4e930 100644 --- a/crossbow/tx_oled.cpp +++ b/crossbow/tx_oled.cpp @@ -97,6 +97,10 @@ void TxOled::renderPagePwr( _display.print("PWR"); //TODO content + _display.setCursor(0, 25); + _display.setTextSize(3); + _display.print(radioState->loraTxPower); + _display.print("dBm"); _display.display(); } @@ -130,7 +134,9 @@ void TxOled::renderPageMode( _display.setTextSize(2); _display.print("Mode"); - //TODO content + _display.setCursor(0, 25); + _display.setTextSize(3); + _display.print("Full"); _display.display(); }