1st compiling version, display seems to be ok, RF not tested.

This commit is contained in:
Dirk Jahnke 2018-11-06 22:54:26 +01:00
parent 724c622ca4
commit bb141a2615
3 changed files with 27 additions and 21 deletions

View File

@ -16,7 +16,6 @@
#ifdef MONGOOSE_OS #ifdef MONGOOSE_OS
/* /*
static bool s_randomSeedCalled = false; static bool s_randomSeedCalled = false;
static void randomSeed(unsigned long seed) { static void randomSeed(unsigned long seed) {
if(seed != 0) { if(seed != 0) {
srand(seed); srand(seed);

View File

@ -890,7 +890,9 @@
#define YIELD yield(); #define YIELD yield();
#elif (RH_PLATFORM == RH_PLATFORM_ESP8266) #elif (RH_PLATFORM == RH_PLATFORM_ESP8266)
// ESP8266 also hash it // ESP8266 also hash it
#define YIELD yield(); // freertos/include/freertos/task.h
// #include "freertos/task.h"
#define YIELD
#else #else
#define YIELD #define YIELD
#endif #endif

View File

@ -70,7 +70,7 @@ static uint8_t getNormalTextHeight() { return Org_01.yAdvance; }
static void setLargeTextSize(void) { display->setFont(&FreeMonoBold9pt7b); } static void setLargeTextSize(void) { display->setFont(&FreeMonoBold9pt7b); }
//static uint8_t getLargeTextHeight() { return FreeMonoBold9pt7b.yAdvance; } //static uint8_t getLargeTextHeight() { return FreeMonoBold9pt7b.yAdvance; }
//static uint8_t getLargeTextCharsPerLine() { return 12; } //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_receive_cb(void *arg);
static void fastclockRF_send_cb(void *arg); static void fastclockRF_send_cb(void *arg);
static void initFastclockRF_cb(void *arg); static void initFastclockRF_cb(void *arg);
@ -126,7 +126,6 @@ void setup(void) {
LOG(LL_INFO, ("*** Setup started")); LOG(LL_INFO, ("*** Setup started"));
LOG(LL_INFO, ("*** Setting timer")); LOG(LL_INFO, ("*** Setting timer"));
mgos_set_timer(2000 /* ms */, false /* repeat */, initDisplay_cb, NULL); 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); mgos_set_timer(7000 /* ms */, false /* repeat */, initFastclockRF_cb, NULL);
LOG(LL_INFO, ("*** Setup done")); LOG(LL_INFO, ("*** Setup done"));
} }
@ -181,7 +180,7 @@ static void show_dashboard(int hour, int minute) {
static long lastSentTimeTick = 0; static long lastSentTimeTick = 0;
static long msPerModelSecond = 1000; // 500 = real time static long msPerModelSecond = 50; // 500 = real time
static struct clock_s { static struct clock_s {
uint8_t day; uint8_t day;
uint8_t hour; uint8_t hour;
@ -193,25 +192,29 @@ static struct clock_s {
static void incrementClockByMilliseconds(int amount) { static void incrementClockByMilliseconds(int amount) {
fastclock.millisecond += amount; fastclock.millisecond += amount;
if (fastclock.millisecond >= 1000) { if (fastclock.millisecond >= 1000) {
fastclock.millisecond -= 1000; int carryover = fastclock.millisecond / 1000;
fastclock.second++; fastclock.millisecond = fastclock.millisecond % 1000;
fastclock.second += carryover;
if (fastclock.second >= 60) { if (fastclock.second >= 60) {
fastclock.second -= 60; carryover = fastclock.second / 60;
fastclock.minute++; fastclock.second = fastclock.second % 60;
fastclock.minute += carryover;
if (fastclock.minute >= 60) { if (fastclock.minute >= 60) {
fastclock.minute -= 60; carryover = fastclock.minute / 60;
fastclock.hour++; fastclock.minute = fastclock.minute % 60;
fastclock.hour += carryover;
if (fastclock.hour >= 24) { if (fastclock.hour >= 24) {
fastclock.hour -=24; carryover = fastclock.hour / 24;
fastclock.day++; fastclock.hour = fastclock.hour % 24;
fastclock.day += carryover;
if (fastclock.day >= 7) { 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) { static void fastclockRF_receive_cb(void *arg) {
@ -226,7 +229,7 @@ static void fastclockRF_receive_cb(void *arg) {
uint8_t from, to, id, flags; uint8_t from, to, id, flags;
if (Datagram.recvfrom(buf, &len, &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 else
{ {
@ -256,10 +259,11 @@ static void fastclockRF_send_cb(void *arg) {
static void timeTick_cb(void *arg) { static void timeTick_cb(void *arg) {
(void) arg; (void) arg;
long newTimeTick = millis(); long newTimeTick = millis();
int fastclockTimeAdvance = (newTimeTick - lastSentTimeTick) / msPerModelSecond; int fastclockTimeAdvance = (newTimeTick - lastSentTimeTick) * 1000 / msPerModelSecond;
incrementClockByMilliseconds(fastclockTimeAdvance); incrementClockByMilliseconds(fastclockTimeAdvance);
lastSentTimeTick += fastclockTimeAdvance * msPerModelSecond; //lastSentTimeTick += fastclockTimeAdvance * msPerModelSecond/1000;
lastSentTimeTick = newTimeTick;
} }
static void initFastclockRF_cb(void *arg) { static void initFastclockRF_cb(void *arg) {
@ -271,12 +275,13 @@ static void initFastclockRF_cb(void *arg) {
fastclock.minute = 0; fastclock.minute = 0;
fastclock.second = 0; fastclock.second = 0;
fastclock.millisecond = 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(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; // static int hour = 0, minute = 0;
show_dashboard(fastclock.hour, fastclock.minute); show_dashboard(fastclock.hour, fastclock.minute);
LOG(LL_INFO, ("%02d:%02d", fastclock.hour, fastclock.minute)); LOG(LL_INFO, ("%02d:%02d", fastclock.hour, fastclock.minute));