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; };