do not store pointers, this just do not work

This commit is contained in:
Pawel Spychalski (DzikuVx)
2018-05-15 17:44:50 +02:00
parent 37984e21a4
commit ab5806bf53
6 changed files with 114 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
{ {
"board": "bsfrance:avr:lora32u4", "board": "bsfrance:avr:lora32u4",
"sketch": "crossbow/crossbow.ino", "sketch": "crossbow/crossbow.ino",
"port": "COM5", "port": "COM11",
"output": "../build" "output": "../build"
} }

View File

@@ -3,12 +3,14 @@
{ {
"name": "Win32", "name": "Win32",
"includePath": [ "includePath": [
"${workspaceRoot}" "${workspaceRoot}",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino"
], ],
"browse": { "browse": {
"limitSymbolsToIncludedHeaders": false, "limitSymbolsToIncludedHeaders": false,
"path": [ "path": [
"${workspaceRoot}" "${workspaceRoot}",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino"
] ]
}, },
"intelliSenseMode": "msvc-x64", "intelliSenseMode": "msvc-x64",

View File

@@ -1,6 +1,7 @@
{ {
"files.associations": { "files.associations": {
"variables.h": "c" "variables.h": "c",
"arduino.h": "c"
}, },
"files.exclude": { "files.exclude": {
"**/build": true "**/build": true

View File

@@ -242,14 +242,13 @@ void setup(void)
#ifdef DEVICE_MODE_TX #ifdef DEVICE_MODE_TX
#ifdef FEATURE_TX_OLED #ifdef FEATURE_TX_OLED
oled.init( oled.init();
oled.page(
&radioState, &radioState,
&rxDeviceState, &rxDeviceState,
&txDeviceState, &txDeviceState,
&button0, TX_PAGE_INIT
&button1
); );
oled.page(TX_PAGE_INIT);
#endif #endif
/* /*
@@ -354,7 +353,13 @@ void loop(void)
button1.loop(); button1.loop();
#ifdef FEATURE_TX_OLED #ifdef FEATURE_TX_OLED
oled.loop(); oled.loop(
&radioState,
&rxDeviceState,
&txDeviceState,
&button0,
&button1
);
#endif #endif
txInput.recoverStuckFrames(); txInput.recoverStuckFrames();

View File

@@ -4,25 +4,21 @@ TxOled::TxOled(void) {
Adafruit_SSD1306 _display(-1); Adafruit_SSD1306 _display(-1);
} }
void TxOled::init( 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.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
_display.setTextSize(1); _display.setTextSize(1);
_display.setTextColor(WHITE); _display.setTextColor(WHITE);
_display.clearDisplay(); _display.clearDisplay();
_display.display(); _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; bool update = false;
//Depending on page, things might be different //Depending on page, things might be different
@@ -34,7 +30,7 @@ void TxOled::loop(void) {
case TX_PAGE_STATS: case TX_PAGE_STATS:
//Second button refreshes this page //Second button refreshes this page
if (_button1->getState() == TACTILE_STATE_SHORT_PRESS) { if (button1->getState() == TACTILE_STATE_SHORT_PRESS) {
update = true; update = true;
} }
break; break;
@@ -42,7 +38,7 @@ void TxOled::loop(void) {
} }
//Short press of button0 always toggles no next page //Short press of button0 always toggles no next page
if (_button0->getState() == TACTILE_STATE_SHORT_PRESS) { if (button0->getState() == TACTILE_STATE_SHORT_PRESS) {
_mainPageSequenceIndex++; _mainPageSequenceIndex++;
if (_mainPageSequenceIndex == TX_OLED_PAGE_COUNT) { if (_mainPageSequenceIndex == TX_OLED_PAGE_COUNT) {
_mainPageSequenceIndex = 0; _mainPageSequenceIndex = 0;
@@ -51,34 +47,48 @@ void TxOled::loop(void) {
} }
if (update) { 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) { switch (page) {
case TX_PAGE_INIT: case TX_PAGE_INIT:
renderPageInit(); renderPageInit(radioState, rxDeviceState, txDeviceState);
break; break;
case TX_PAGE_STATS: case TX_PAGE_STATS:
renderPageStats(); renderPageStats(radioState, rxDeviceState, txDeviceState);
break; break;
case TX_PAGE_PWR: case TX_PAGE_PWR:
renderPagePwr(); renderPagePwr(radioState, rxDeviceState, txDeviceState);
break; break;
case TX_PAGE_BIND: case TX_PAGE_BIND:
renderPageBind(); renderPageBind(radioState, rxDeviceState, txDeviceState);
break; break;
case TX_PAGE_MODE: case TX_PAGE_MODE:
renderPageMode(); renderPageMode(radioState, rxDeviceState, txDeviceState);
break; break;
} }
_page = page; _page = page;
} }
void TxOled::renderPagePwr(void) { void TxOled::renderPagePwr(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
_display.clearDisplay(); _display.clearDisplay();
_display.setTextColor(WHITE, BLACK); _display.setTextColor(WHITE, BLACK);
@@ -91,7 +101,11 @@ void TxOled::renderPagePwr(void) {
_display.display(); _display.display();
} }
void TxOled::renderPageBind(void) { void TxOled::renderPageBind(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
_display.clearDisplay(); _display.clearDisplay();
_display.setTextColor(WHITE, BLACK); _display.setTextColor(WHITE, BLACK);
@@ -104,7 +118,11 @@ void TxOled::renderPageBind(void) {
_display.display(); _display.display();
} }
void TxOled::renderPageMode(void) { void TxOled::renderPageMode(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
_display.clearDisplay(); _display.clearDisplay();
_display.setTextColor(WHITE, BLACK); _display.setTextColor(WHITE, BLACK);
@@ -117,61 +135,64 @@ void TxOled::renderPageMode(void) {
_display.display(); _display.display();
} }
void TxOled::renderPageStats(void) { void TxOled::renderPageStats(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
_display.clearDisplay(); _display.clearDisplay();
_display.setTextColor(WHITE, BLACK); _display.setTextColor(WHITE, BLACK);
_display.setCursor(0, 0); _display.setCursor(0, 0);
_display.setTextSize(3); _display.setTextSize(3);
_display.print(_radioState->rssi); _display.print(radioState->rssi);
_display.setCursor(18, 28); _display.setCursor(18, 28);
_display.setTextSize(2); _display.setTextSize(2);
_display.print(_radioState->snr); _display.print(radioState->snr);
_display.setCursor(74, 0); _display.setCursor(74, 0);
_display.setTextSize(3); _display.setTextSize(3);
_display.print(_rxDeviceState->rssi); _display.print(rxDeviceState->rssi);
_display.setCursor(92, 28); _display.setCursor(92, 28);
_display.setTextSize(2); _display.setTextSize(2);
_display.print(_rxDeviceState->snr); _display.print(rxDeviceState->snr);
_display.setCursor(54, 48); _display.setCursor(54, 48);
_display.setTextSize(2); _display.setTextSize(2);
_display.print(txDeviceState->roundtrip);
if (_txDeviceState->roundtrip < 100) {
_display.print(_txDeviceState->roundtrip);
} else {
_display.print(0);
}
_display.display(); _display.display();
} }
void TxOled::renderPageInit(void) { void TxOled::renderPageInit(
volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState
) {
_display.clearDisplay(); _display.clearDisplay();
_display.setTextColor(WHITE, BLACK); _display.setTextColor(WHITE, BLACK);
_display.setTextSize(2); _display.setTextSize(2);
_display.setCursor(0, 0); _display.setCursor(0, 0);
_display.print("Rdy "); _display.print("Rdy ");
_display.print(_radioState->loraTxPower); _display.print(radioState->loraTxPower);
_display.print("dBm"); _display.print("dBm");
_display.setTextSize(1); _display.setTextSize(1);
_display.setCursor(0, 32); _display.setCursor(0, 32);
_display.print("Bandwitdh: "); _display.print("Bandwitdh: ");
_display.print(_radioState->loraBandwidth / 1000); _display.print(radioState->loraBandwidth / 1000);
_display.print("kHz"); _display.print("kHz");
_display.setCursor(0, 42); _display.setCursor(0, 42);
_display.print("SF: "); _display.print("SF: ");
_display.print(_radioState->loraSpreadingFactor); _display.print(radioState->loraSpreadingFactor);
_display.setCursor(64, 42); _display.setCursor(64, 42);
_display.print("CR: "); _display.print("CR: ");
_display.print(_radioState->loraCodingRate); _display.print(radioState->loraCodingRate);
_display.setCursor(0, 52); _display.setCursor(0, 52);
_display.print("Rate: "); _display.print("Rate: ");

View File

@@ -30,27 +30,47 @@ const uint8_t pageSequence[TX_OLED_PAGE_COUNT] = {
class TxOled { class TxOled {
public: public:
TxOled(void); TxOled(void);
void init( void init();
void loop(
volatile RadioState_t *radioState, volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState, RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState, TxDeviceState_t *txDeviceState,
Tactile *button0, Tactile *button0,
Tactile *button1 Tactile *button1
); );
void loop(void); void page(
void page(int page); volatile RadioState_t *radioState,
RxDeviceState_t *rxDeviceState,
TxDeviceState_t *txDeviceState,
int page
);
private: private:
volatile RadioState_t *_radioState;
RxDeviceState_t *_rxDeviceState;
TxDeviceState_t *_txDeviceState;
Tactile *_button0;
Tactile *_button1;
Adafruit_SSD1306 _display; Adafruit_SSD1306 _display;
void renderPageInit(void); void renderPageInit(
void renderPageStats(void); volatile RadioState_t *radioState,
void renderPagePwr(void); RxDeviceState_t *rxDeviceState,
void renderPageBind(void); TxDeviceState_t *txDeviceState
void renderPageMode(void); );
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 _page = TX_PAGE_NONE;
uint8_t _mainPageSequenceIndex = 0; uint8_t _mainPageSequenceIndex = 0;
}; };