diff --git a/src/SevenSegmentClock.h b/src/SevenSegmentClock.h index 2a505c0..fd29dd1 100644 --- a/src/SevenSegmentClock.h +++ b/src/SevenSegmentClock.h @@ -28,7 +28,7 @@ public: void setBrightness(uint8_t b) { brightness=b; initColors(b); }; uint8_t getBrightness(void) { return brightness; }; private: - void init(void) { displayStatus = Off; clockHour=12; clockMinute=34; setClockHalted(true); currentColorHandle = Blue; currentColor = blue; }; + void init(void) { displayStatus = Off; clockHour=12; clockMinute=34; setClockHalted(true); currentColorHandle = Green; currentColor = green; }; static uint8_t LedDataPin; static Adafruit_NeoPixel *strip; static BlinkMode blinkMode; diff --git a/src/main.cpp b/src/main.cpp index a92c767..b699ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ WiFiUDP ntpUDP; // You can specify the time server pool and the offset (in seconds, can be // changed later with setTimeOffset() ). Additionaly you can specify the // update interval (in milliseconds, can be changed using setUpdateInterval() ). -NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); +NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200, 60000); #define MODE_DEMO 1 #define MODE_REALCLOCK 2 @@ -35,7 +35,7 @@ static const char *appName = "FastclockClient7Seg"; #define DEFAULT_CLOCK_NAME "fastclk" #define DEFAULT_CLOCK_CHANNEL_STRING "1" #define DEFAULT_CLOCK_CHANNEL 1 -#define DEFAULT_CLOCK_COLOR "blue" +#define DEFAULT_CLOCK_COLOR "green" SevenSegmentClock sevenSegmentClock; ESP8266WebServer *server; @@ -81,7 +81,7 @@ static const SevenSegmentClock::Color getColorHandle(uint8_t id) { return colorSelection[i].colorHandle; } } - return SevenSegmentClock::Blue; // default + return SevenSegmentClock::Green; // default } static const SevenSegmentClock::Color getColorHandleByName(String name) { @@ -90,10 +90,10 @@ static const SevenSegmentClock::Color getColorHandleByName(String name) { return colorSelection[i].colorHandle; } } - return SevenSegmentClock::Blue; // default + return SevenSegmentClock::Green; // default } -#define DEFAULT_COLOR SevenSegmentClock::Blue +#define DEFAULT_COLOR SevenSegmentClock::Green #define DEFAULT_BRIGHTNESS 31 char clockName[MAX_CLOCK_NAME_LEN+1] = DEFAULT_CLOCK_NAME; @@ -101,7 +101,7 @@ char clockChannelString[MAX_CLOCK_CHANNEL_STRING_LEN+1] = DEFAULT_CLOCK_CHANNEL_ uint8_t clockChannel = DEFAULT_CLOCK_CHANNEL; SevenSegmentClock::Color clockColor = DEFAULT_COLOR; //uint8_t brightness = DEFAULT_BRIGHTNESS; - +int utcTimeOffsetMinutes = 120; // default UTC+2h //flag for saving data bool shouldSaveConfig = false; @@ -196,6 +196,7 @@ const char _FORM_CLOCKMODE_HEADLINE[] PROGMEM = "
Clock mode:
"; const char _FORM_CLOCKMODE_DEMO[] PROGMEM = "
"; const char _FORM_CLOCKMODE_REAL[] PROGMEM = "
"; const char _FORM_CLOCKMODE_FAST[] PROGMEM = "
"; +const char _FORM_UTC_OFFSET[] PROGMEM = "
"; const char _FORM_PARAM[] PROGMEM = "
"; const char _FORM_COLOR_HEADLINE[] PROGMEM = "
Display color:
"; const char _FORM_COLOR_BLUE[] PROGMEM = "
"; @@ -235,6 +236,7 @@ void appConfig() { input = FPSTR(_FORM_CLOCKMODE_FAST); input.replace("{check}", (appMode == MODE_FASTCLOCK) ? "checked" : ""); page += input; + page += FPSTR(_FORM_UTC_OFFSET); page += FPSTR(_FORM_CLOCKNAME); page += FPSTR(_FORM_COLOR_HEADLINE); input = FPSTR(_FORM_COLOR_BLUE); @@ -267,6 +269,14 @@ void appConfig() { void appConfigSave() { String page = FPSTR(_HEAD); + page.replace("{v}", "7Seg Config"); + page += FPSTR(_SCRIPT); + page += FPSTR(_STYLE); + page += FPSTR(_HEAD_END); + page += String(F("

")); + page += appName; + page += String(F("

")); + Serial.print("appConfigSave "); Serial.print(server->args()); Serial.println(" arguments"); for (int i=0; iargs(); ++i) { Serial.print(server->argName(i)); @@ -275,30 +285,44 @@ void appConfigSave() { } if (server->hasArg("b")) { sevenSegmentClock.setBrightness(server->arg("b").toInt()); + page += F("
Set brightness to "); + page += server->arg("b"); + page += F(".
"); } if (server->hasArg("c")) { String colorName = server->arg("c"); SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c")); sevenSegmentClock.setColor(colorHandle); + page += F("
Set color to "); + page += server->arg("c"); + page += F(".
"); } if (server->hasArg("m")) { Serial.print("setting clock mode to "); Serial.println(server->arg("m")); + page += F("
Set clock mode to "); + page += server->arg("m"); + page += F(".
"); if (server->arg("m").equals("real")) appMode = MODE_REALCLOCK; else if (server->arg("m").equals("fast")) appMode = MODE_FASTCLOCK; else if (server->arg("m").equals("demo")) appMode = MODE_DEMO; else { Serial.println("ERROR: Unknown application mode, going into demo mode"); appMode = MODE_DEMO; + page += F("
ERROR: Unknown clockmode, using default: demo.
"); } } - page.replace("{v}", "7Seg Config"); - page += FPSTR(_SCRIPT); - page += FPSTR(_STYLE); - //page += _customHeadElement; - page += FPSTR(_HEAD_END); - page += String(F("

")); - page += appName; - page += String(F("

")); + if (server->hasArg("utc")) { + page += F("
Set real clock offset to "); + if (server->arg("utc").equals("")) { + page += "120"; + utcTimeOffsetMinutes = 120; + } else { + page += server->arg("utc"); + utcTimeOffsetMinutes = server->arg("utc").toInt(); + } + timeClient.setTimeOffset(utcTimeOffsetMinutes); + page += F(" minutes.
"); + } page += String(F("
Configuration updated.
")); page += FPSTR(_END); server->sendHeader("Content-Length", String(page.length())); @@ -377,7 +401,7 @@ void setup() { strncpy(clockName, DEFAULT_CLOCK_NAME, MAX_CLOCK_NAME_LEN); strncpy(clockChannelString, DEFAULT_CLOCK_CHANNEL_STRING, MAX_CLOCK_CHANNEL_STRING_LEN); //strncpy(clockColor, DEFAULT_CLOCK_COLOR, MAX_CLOCK_COLOR_LEN); - clockColor = SevenSegmentClock::Blue; + clockColor = getColorHandleByName(DEFAULT_CLOCK_COLOR); } } } else {