Basic OLED
This commit is contained in:
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@@ -38,7 +38,7 @@
|
||||
"SPI_HAS_NOTUSINGINTERRUPT",
|
||||
"FEATURE_TX_INPUT_SBUS",
|
||||
"DEVICE_MODE_TX",
|
||||
"DEVICE_MODE_RX"
|
||||
"FEATURE_TX_OLED"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
#define FEATURE_TX_INPUT_SBUS
|
||||
|
||||
#define DEBUG_SERIAL
|
||||
// #define DEBUG_SERIAL
|
||||
// #define DEBUG_PING_PONG
|
||||
// #define DEBUG_LED
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,24 +5,54 @@
|
||||
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#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
|
||||
Reference in New Issue
Block a user