IF482.cpp fully functional

This commit is contained in:
Klaus K Wilting 2019-01-26 18:49:53 +01:00
parent 99f1a2015d
commit 335432e692
2 changed files with 19 additions and 22 deletions

View File

@ -80,53 +80,44 @@ void if482_init(void) {
// use rtc 1Hz clock for triggering IF482 telegram send // use rtc 1Hz clock for triggering IF482 telegram send
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz); Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
pinMode(RTC_INT, INPUT_PULLUP);
// setup external interupt for active low RTC INT pin
attachInterrupt(RTC_INT, IF482IRQ, FALLING);
ESP_LOGI(TAG, "IF482 generator initialized"); ESP_LOGI(TAG, "IF482 generator initialized");
} // if482_init } // 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 mon;
char buf[14] = {0}; char buf[14] = "000000F000000";
char out[17];
strcat_P(out, "O"); // <STX>
switch (timeStatus()) { // indicates if time has been set and recently synced switch (timeStatus()) { // indicates if time has been set and recently synced
case timeSet: // time is set and is synced case timeSet: // time is set and is synced
strcat_P(out, "A"); mon = 'A';
break; break;
case timeNeedsSync: // time had been set but sync attempt did not succeed case timeNeedsSync: // time had been set but sync attempt did not succeed
strcat_P(out, "M"); mon = 'M';
break; break;
default: // time not set, no valid time default: // time not set, no valid time
strcat_P(out, "?"); mon = '?';
break; break;
} // switch } // 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? snprintf(out, sizeof out, "O%cL%s\r", mon, buf);
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"); // <ETX>
return out; return out;
} }
// interrupt triggered routine // interrupt triggered routine
void sendIF482(time_t t) { IF482.write(if482Telegram(t)); } void sendIF482(time_t t) { IF482.println(if482Telegram(t)); }
#endif // HAS_IF482 #endif // HAS_IF482

View File

@ -397,6 +397,12 @@ void setup() {
#endif #endif
#endif // HAS_BUTTON #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() } // setup()
void loop() { void loop() {