Skip to content

Commit

Permalink
Display select doesn't seem to be working properly on Si Hai version …
Browse files Browse the repository at this point in the history
…of the clock #8
  • Loading branch information
judge2005 committed Apr 7, 2024
1 parent c69d870 commit 1fdb55d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <ESPmDNS.h>
#include <AsyncWiFiManager.h>
#include <EspSNTPTimeSync.h>
#ifndef HARDWARE_SI_HAI_CLOCK
#include <EspRTCTimeSync.h>
#endif
#include <ConfigItem.h>
#include <EEPROMConfig.h>
#include <ImprovWiFi.h>
Expand Down Expand Up @@ -88,7 +90,9 @@ AsyncWebSocket *ws = new AsyncWebSocket("/ws"); // access at ws://[esp ip]/ws
DNSServer *dns = new DNSServer();
AsyncWiFiManager *wifiManager = new AsyncWiFiManager(server, dns);
TimeSync *timeSync;
#ifndef HARDWARE_SI_HAI_CLOCK
RTCTimeSync *rtcTimeSync;
#endif
MQTTBroker *mqttBroker;

TaskHandle_t wifiManagerTask;
Expand All @@ -106,9 +110,6 @@ AsyncWiFiManagerParameter *hostnameParam;
String ssid("EleksTubeIPS");
String chipId = getChipId();

#define SCLpin (22)
#define SDApin (21)

// Persistent Configuration
StringConfigItem hostName("hostname", 63, "elekstubeips");

Expand Down Expand Up @@ -217,14 +218,17 @@ EEPROMConfig config(rootConfig);
void asyncTimeSetCallback(String time) {
DEBUG(time);
tfts->setStatus("NTP time received...");

#ifndef HARDWARE_SI_HAI_CLOCK
rtcTimeSync->enabled(false);
rtcTimeSync->setDS3231();
#endif
}

void asyncTimeErrorCallback(String msg) {
DEBUG(msg);
#ifndef HARDWARE_SI_HAI_CLOCK
rtcTimeSync->enabled(true);
#endif
}

template<class T>
Expand Down Expand Up @@ -422,7 +426,11 @@ void clockTaskFn(void *pArg) {
break;
default:
tfts->setShowDigits(true);
#ifndef HARDWARE_SI_HAI_CLOCK
if (timeSync->initialized() || rtcTimeSync->initialized()) {
#else
if (timeSync->initialized()) {
#endif
ipsClock->loop();
if (ipsClock->getFourDigitDisplay() == 2 && IPSClock::getTimeOrDate().value == 0) {
weather->drawSingleDay(ipsClock->getBrightness(), 0, 0);
Expand Down Expand Up @@ -706,7 +714,9 @@ void timeHandler(AsyncWebServerRequest *request) {
DEBUG(String("Setting time from wifi manager") + wifiTime);

timeSync->setTime(wifiTime);
#ifndef HARDWARE_SI_HAI_CLOCK
rtcTimeSync->setTime(wifiTime);
#endif

request->send(LittleFS, "/time.html");
}
Expand Down Expand Up @@ -1045,9 +1055,11 @@ void setup() {
timeSync = new EspSNTPTimeSync(IPSClock::getTimeZone().value, asyncTimeSetCallback, asyncTimeErrorCallback);
timeSync->init();

rtcTimeSync = new EspRTCTimeSync(SDApin, SCLpin);
#ifndef HARDWARE_SI_HAI_CLOCK
rtcTimeSync = new EspRTCTimeSync(RTC_SDA_PIN, RTC_SCL_PIN);
rtcTimeSync->init();
rtcTimeSync->enabled(true);
#endif

IPSClock::getTimeZone().setCallback(onTimezoneChanged);

Expand Down

0 comments on commit 1fdb55d

Please sign in to comment.