From bb141a261578b6ab476b2b6ff412264246e04f63 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Tue, 6 Nov 2018 22:54:26 +0100 Subject: [PATCH] 1st compiling version, display seems to be ok, RF not tested. --- src/RadioHead/RHReliableDatagram.cpp | 1 - src/RadioHead/RadioHead.h | 4 ++- src/main.cpp | 43 ++++++++++++++++------------ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/RadioHead/RHReliableDatagram.cpp b/src/RadioHead/RHReliableDatagram.cpp index f9bacd7..ef45d4c 100644 --- a/src/RadioHead/RHReliableDatagram.cpp +++ b/src/RadioHead/RHReliableDatagram.cpp @@ -16,7 +16,6 @@ #ifdef MONGOOSE_OS /* static bool s_randomSeedCalled = false; - static void randomSeed(unsigned long seed) { if(seed != 0) { srand(seed); diff --git a/src/RadioHead/RadioHead.h b/src/RadioHead/RadioHead.h index 7e8c5b8..7c8aac2 100644 --- a/src/RadioHead/RadioHead.h +++ b/src/RadioHead/RadioHead.h @@ -890,7 +890,9 @@ #define YIELD yield(); #elif (RH_PLATFORM == RH_PLATFORM_ESP8266) // ESP8266 also hash it - #define YIELD yield(); +// freertos/include/freertos/task.h + // #include "freertos/task.h" + #define YIELD #else #define YIELD #endif diff --git a/src/main.cpp b/src/main.cpp index 74a5532..5db36f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,7 @@ static uint8_t getNormalTextHeight() { return Org_01.yAdvance; } static void setLargeTextSize(void) { display->setFont(&FreeMonoBold9pt7b); } //static uint8_t getLargeTextHeight() { return FreeMonoBold9pt7b.yAdvance; } //static uint8_t getLargeTextCharsPerLine() { return 12; } -static void timer_cb(void *arg); +static void updateDisplay_cb(void *arg); static void fastclockRF_receive_cb(void *arg); static void fastclockRF_send_cb(void *arg); static void initFastclockRF_cb(void *arg); @@ -126,7 +126,6 @@ void setup(void) { LOG(LL_INFO, ("*** Setup started")); LOG(LL_INFO, ("*** Setting timer")); mgos_set_timer(2000 /* ms */, false /* repeat */, initDisplay_cb, NULL); - mgos_set_timer(5000 /* ms */, true /* repeat */, timer_cb, NULL); mgos_set_timer(7000 /* ms */, false /* repeat */, initFastclockRF_cb, NULL); LOG(LL_INFO, ("*** Setup done")); } @@ -181,7 +180,7 @@ static void show_dashboard(int hour, int minute) { static long lastSentTimeTick = 0; -static long msPerModelSecond = 1000; // 500 = real time +static long msPerModelSecond = 50; // 500 = real time static struct clock_s { uint8_t day; uint8_t hour; @@ -193,25 +192,29 @@ static struct clock_s { static void incrementClockByMilliseconds(int amount) { fastclock.millisecond += amount; if (fastclock.millisecond >= 1000) { - fastclock.millisecond -= 1000; - fastclock.second++; + int carryover = fastclock.millisecond / 1000; + fastclock.millisecond = fastclock.millisecond % 1000; + fastclock.second += carryover; if (fastclock.second >= 60) { - fastclock.second -= 60; - fastclock.minute++; + carryover = fastclock.second / 60; + fastclock.second = fastclock.second % 60; + fastclock.minute += carryover; if (fastclock.minute >= 60) { - fastclock.minute -= 60; - fastclock.hour++; + carryover = fastclock.minute / 60; + fastclock.minute = fastclock.minute % 60; + fastclock.hour += carryover; if (fastclock.hour >= 24) { - fastclock.hour -=24; - fastclock.day++; + carryover = fastclock.hour / 24; + fastclock.hour = fastclock.hour % 24; + fastclock.day += carryover; if (fastclock.day >= 7) { - fastclock.day -= 7; + fastclock.day = fastclock.day % 7; } } } } } - LOG(LL_INFO, ("*** new clock: %02d:%02d:%02d.%03d day %d", fastclock.hour, fastclock.minute, fastclock.second, fastclock.millisecond, fastclock.day)); + LOG(LL_INFO, ("*** new clock: %02d:%02d:%02d.%03d day %d, incBy_ms=%d", fastclock.hour, fastclock.minute, fastclock.second, fastclock.millisecond, fastclock.day, amount)); } static void fastclockRF_receive_cb(void *arg) { @@ -226,7 +229,7 @@ static void fastclockRF_receive_cb(void *arg) { uint8_t from, to, id, flags; if (Datagram.recvfrom(buf, &len, &from, &to, &id, &flags)) { - LOG(LL_INFO, ("got request: %s", (char*)buf)); + LOG(LL_INFO, ("got request: %d bytes, from=%d, to=%d, id=%d, msg=%02x %02x %02x %02x", len, from, to, id, buf[0], buf[1], buf[2], buf[3])); } else { @@ -256,10 +259,11 @@ static void fastclockRF_send_cb(void *arg) { static void timeTick_cb(void *arg) { (void) arg; long newTimeTick = millis(); - int fastclockTimeAdvance = (newTimeTick - lastSentTimeTick) / msPerModelSecond; + int fastclockTimeAdvance = (newTimeTick - lastSentTimeTick) * 1000 / msPerModelSecond; incrementClockByMilliseconds(fastclockTimeAdvance); - lastSentTimeTick += fastclockTimeAdvance * msPerModelSecond; + //lastSentTimeTick += fastclockTimeAdvance * msPerModelSecond/1000; + lastSentTimeTick = newTimeTick; } static void initFastclockRF_cb(void *arg) { @@ -271,12 +275,13 @@ static void initFastclockRF_cb(void *arg) { fastclock.minute = 0; fastclock.second = 0; fastclock.millisecond = 0; - mgos_set_timer(200 /* ms */, true /* repeat */, fastclockRF_receive_cb, NULL); + mgos_set_timer(100 /* ms */, true /* repeat */, fastclockRF_receive_cb, NULL); mgos_set_timer(500 /* ms */, true /* repeat */, timeTick_cb, NULL); - mgos_set_timer(4000 /* ms */, true /* repeat */, fastclockRF_send_cb, NULL); + mgos_set_timer(3000 /* ms */, true /* repeat */, fastclockRF_send_cb, NULL); + mgos_set_timer(1000 /* ms */, true /* repeat */, updateDisplay_cb, NULL); } -static void timer_cb(void *arg) { +static void updateDisplay_cb(void *arg) { // static int hour = 0, minute = 0; show_dashboard(fastclock.hour, fastclock.minute); LOG(LL_INFO, ("%02d:%02d", fastclock.hour, fastclock.minute));