From 335432e692307b01a35d8638a5f4e7a4a506c946 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 26 Jan 2019 18:49:53 +0100 Subject: [PATCH] IF482.cpp fully functional --- src/if482.cpp | 35 +++++++++++++---------------------- src/main.cpp | 6 ++++++ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/if482.cpp b/src/if482.cpp index d1fcf7cb..698424e2 100644 --- a/src/if482.cpp +++ b/src/if482.cpp @@ -80,53 +80,44 @@ void if482_init(void) { // use rtc 1Hz clock for triggering IF482 telegram send Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz); Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); - - // setup external interupt for active low RTC INT pin - attachInterrupt(RTC_INT, IF482IRQ, FALLING); + pinMode(RTC_INT, INPUT_PULLUP); ESP_LOGI(TAG, "IF482 generator initialized"); } // if482_init -char *if482Telegram(time_t t) { +String if482Telegram(time_t t) { - static char out[17] = {0}; // 16 bytes IF482 telegram + null termination char - char buf[14] = {0}; - - strcat_P(out, "O"); // + char mon; + char buf[14] = "000000F000000"; + char out[17]; switch (timeStatus()) { // indicates if time has been set and recently synced case timeSet: // time is set and is synced - strcat_P(out, "A"); + mon = 'A'; break; case timeNeedsSync: // time had been set but sync attempt did not succeed - strcat_P(out, "M"); + mon = 'M'; break; default: // time not set, no valid time - strcat_P(out, "?"); + mon = '?'; break; } // switch - strcat_P(out, "L"); // local time + if (!timeNotSet) // do we have valid time? + snprintf(buf, sizeof buf, "%02u%02u%02u%1u%02u%02u%02u", year(t)-2000, month(t), + day(t), weekday(t), hour(t), minute(t), second(t)); - if (!timeNotSet) { // do we have valid time? - sprintf(buf, "%02u%02u%02u%1u%02u%02u%02u", year(t), month(t), day(t), - weekday(t), hour(t), minute(t), second(t)); - strcat(out, buf); - } else { - strcat_P(out, "000000F000000"); - } - - strcat_P(out, "\r"); // + snprintf(out, sizeof out, "O%cL%s\r", mon, buf); return out; } // interrupt triggered routine -void sendIF482(time_t t) { IF482.write(if482Telegram(t)); } +void sendIF482(time_t t) { IF482.println(if482Telegram(t)); } #endif // HAS_IF482 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bd20090e..acaf8c0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -397,6 +397,12 @@ void setup() { #endif #endif // HAS_BUTTON +// start RTC interrupt +#if defined HAS_IF482 && defined HAS_RTC + // setup external interupt for active low RTC INT pin + attachInterrupt(digitalPinToInterrupt(RTC_INT), IF482IRQ, FALLING); +#endif + } // setup() void loop() {