From af9d2150bff18e0a5d0a257a6195698796ae1096 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 20 Sep 2019 19:45:37 +0200 Subject: [PATCH] display line6 code sanitized --- include/globals.h | 9 +++++---- src/display.cpp | 16 ++++++---------- src/lorawan.cpp | 21 ++++++++------------- src/main.cpp | 6 +++--- src/ota.cpp | 2 +- src/rcommand.cpp | 7 ------- 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/include/globals.h b/include/globals.h index 773af1ad..a753d5fb 100644 --- a/include/globals.h +++ b/include/globals.h @@ -42,7 +42,8 @@ #define SCREEN_MODE (0x80) // I2C bus access control -#define I2C_MUTEX_LOCK() (xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE) +#define I2C_MUTEX_LOCK() \ + (xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE) #define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess)) enum sendprio_t { prio_low, prio_normal, prio_high }; @@ -103,9 +104,9 @@ extern std::set, Mallocator> macs; extern std::array::iterator it; extern std::array beacons; -extern configData_t cfg; // current device configuration -extern char display_line6[], display_line7[]; // screen buffers -extern uint8_t volatile channel; // wifi channel rotation counter +extern configData_t cfg; // current device configuration +extern char lmic_event_msg[]; // display buffer +extern uint8_t volatile channel; // wifi channel rotation counter extern uint16_t volatile macs_total, macs_wifi, macs_ble, batt_voltage; // display values extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC diff --git a/src/display.cpp b/src/display.cpp index 2d8e7a13..d4786d19 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -13,12 +13,13 @@ Display-Mask (128 x 64 pixel): 3|BLTH:abcde SF:ab 4|WIFI:abcde ch:ab 5|RLIM:abcd abcdKB -6|xxxxxxxxxxxxxxxx 6|20:27:00* 27.Feb 7|yyyyyyyyyyyyyyab - -line 6: x = Text for LORA status OR time/date -line 7: y = Text for LMIC status; ab = payload queue + +line 6: * = time source indicator: L|G|R|?, + inverse = clock controller is active, + pulsed = pps input signal is active +line 7: y = LMIC event message; ab = payload queue length */ @@ -239,17 +240,13 @@ void draw_page(time_t t, uint8_t page) { #endif // HAS_DCF77 || HAS_IF482 if (timeSource != _unsynced) u8x8.printf(" %2d.%3s", day(t), printmonth[month(t)]); -#else // update LoRa status display -#if (HAS_LORA) - u8x8.printf("%-16s", display_line6); -#endif #endif // TIME_SYNC_INTERVAL #if (HAS_LORA) // line 7: update LMiC event display u8x8.setCursor(0, 7); - u8x8.printf("%-14s", display_line7); + u8x8.printf("%-14s", lmic_event_msg); // update LoRa send queue display msgWaiting = uxQueueMessagesWaiting(LoraSendQueue); @@ -259,7 +256,6 @@ void draw_page(time_t t, uint8_t page) { u8x8.printf("%-2s", msgWaiting == SEND_QUEUE_SIZE ? "<>" : buff); } else u8x8.printf(" "); - #endif // HAS_LORA break; // page0 diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 4ae42fd9..573e8aa5 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -231,7 +231,6 @@ void onEvent(ev_t ev) { case EV_JOINED: strcpy_P(buff, PSTR("JOINED")); - sprintf(display_line6, " "); // clear previous lmic status // set data rate adaptation according to saved setting LMIC_setAdrMode(cfg.adrmode); // set data rate and transmit power to defaults only if we have no ADR @@ -258,16 +257,7 @@ void onEvent(ev_t ev) { break; case EV_TXCOMPLETE: - -#if (TIME_SYNC_LORASERVER) - // if last packet sent was a timesync request, store TX timestamp - if (LMIC.pendTxPort == TIMEPORT) - store_time_sync_req(osticks2ms(LMIC.txend)); // milliseconds -#endif - - strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") - : PSTR("TX COMPLETE")); - sprintf(display_line6, " "); // clear previous lmic status + strcpy_P(buff, PSTR("TX COMPLETE")); break; case EV_LOST_TSYNC: @@ -321,7 +311,7 @@ void onEvent(ev_t ev) { // Log & Display if asked if (*buff) { ESP_LOGI(TAG, "%s", buff); - sprintf(display_line7, buff); + sprintf(lmic_event_msg, buff); } } @@ -585,7 +575,12 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, // transmit complete message handler void myTxCallback(void *pUserData, int fSuccess) { - /* currently no code here */ + +#if (TIME_SYNC_LORASERVER) + // if last packet sent was a timesync request, store TX timestamp + if (LMIC.pendTxPort == TIMEPORT) + store_time_sync_req(osticks2ms(LMIC.txend)); // milliseconds +#endif } // decode LORAWAN MAC message diff --git a/src/main.cpp b/src/main.cpp index c6eb2867..91741688 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,9 +76,9 @@ triggers pps 1 sec impulse // Basic Config #include "main.h" -configData_t cfg; // struct holds current device configuration -char display_line6[16], display_line7[16]; // display buffers -uint8_t volatile channel = 0; // channel rotation counter +configData_t cfg; // struct holds current device configuration +char lmic_event_msg[16]; // display buffer for LMIC event message +uint8_t volatile channel = 0; // channel rotation counter uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0, batt_voltage = 0; // globals for display diff --git a/src/ota.cpp b/src/ota.cpp index 18eaa84e..fc1662bc 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -41,7 +41,7 @@ inline String getHeaderValue(String header, String headerName) { void start_ota_update() { // check battery status if we can before doing ota - if (!batt_sufficient()) { + if (!batt_sufficient()) { ESP_LOGE(TAG, "Battery voltage %dmV too low for OTA", batt_voltage); return; } diff --git a/src/rcommand.cpp b/src/rcommand.cpp index b3053790..5c08210e 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -19,32 +19,25 @@ void do_reset() { void set_reset(uint8_t val[]) { switch (val[0]) { case 0: // restart device - sprintf(display_line6, "Reset pending"); do_reset(); break; case 1: // reset MAC counter ESP_LOGI(TAG, "Remote command: reset MAC counter"); reset_counters(); // clear macs get_salt(); // get new salt - sprintf(display_line6, "Reset counter"); break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - sprintf(display_line6, "Factory reset"); eraseConfig(); break; case 3: // reset send queues ESP_LOGI(TAG, "Remote command: flush send queue"); - sprintf(display_line6, "Queue reset"); flushQueues(); break; case 9: // reset and ask for software update via Wifi OTA ESP_LOGI(TAG, "Remote command: software update via Wifi"); #if (USE_OTA) - sprintf(display_line6, "Software update"); cfg.runmode = 1; -#else - sprintf(display_line6, "Software update not implemented"); #endif // USE_OTA break;