|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
|
|
|
|
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
|
#include <NTPClient.h> //https://github.com/esp8266/Arduino
|
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
|
|
|
|
|
//needed for library
|
|
|
|
|
#include <DNSServer.h>
|
|
|
|
@ -11,6 +13,19 @@
|
|
|
|
|
#include <SPI.h>
|
|
|
|
|
#include "SevenSegmentClock.h"
|
|
|
|
|
|
|
|
|
|
// NTP
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
#define MODE_DEMO 1
|
|
|
|
|
#define MODE_REALCLOCK 2
|
|
|
|
|
#define MODE_FASTCLOCK 3
|
|
|
|
|
static int appMode = MODE_REAL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *appName = "FastclockClient7Seg";
|
|
|
|
|
|
|
|
|
@ -38,7 +53,8 @@ static struct ColorSelection {
|
|
|
|
|
{ 2, SevenSegmentClock::Blue, "blue" },
|
|
|
|
|
{ 3, SevenSegmentClock::Red, "red" },
|
|
|
|
|
{ 4, SevenSegmentClock::Green, "green" },
|
|
|
|
|
{ 5, SevenSegmentClock::White, "white" }
|
|
|
|
|
{ 5, SevenSegmentClock::White, "white" },
|
|
|
|
|
{ 6, SevenSegmentClock::Yellow, "yellow" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const String getColorName(uint8_t color) {
|
|
|
|
@ -174,13 +190,19 @@ const char _SCRIPT[] PROGMEM = "<script>function c(l){document.getEleme
|
|
|
|
|
const char _HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
|
|
|
|
|
const char _PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
|
|
|
|
const char _ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
|
|
|
|
const char _FORM_START[] PROGMEM = "<form method='get' action='configsave'><label for='n'>Fastclock name</label><input id='n' name='n' length=32 placeholder='clock name'><br/>";
|
|
|
|
|
const char _FORM_START[] PROGMEM = "<form method='get' action='configsave'>";
|
|
|
|
|
const char _FORM_CLOCKNAME[] PROGMEM = "<label for='n'>Fastclock name</label><input id='n' name='n' length=32 placeholder='clock name'><br/>";
|
|
|
|
|
const char _FORM_CLOCKMODE_HEADLINE[] PROGMEM = "<br/>Clock mode:<br/>";
|
|
|
|
|
const char _FORM_CLOCKMODE_DEMO[] PROGMEM = "<input class='r' id='md' name='m' type='radio' value='demo' {check}><label for='md'>Demo</label><br/>";
|
|
|
|
|
const char _FORM_CLOCKMODE_REAL[] PROGMEM = "<input class='r' id='mr' name='m' type='radio' value='real' {check}><label for='md'>Real Clock</label><br/>";
|
|
|
|
|
const char _FORM_CLOCKMODE_FAST[] PROGMEM = "<input class='r' id='mf' name='m' type='radio' value='fast' {check}><label for='md'>Fast Clock</label><br/>";
|
|
|
|
|
const char _FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
|
|
|
|
const char _FORM_COLOR_HEADLINE[] PROGMEM = "<br/>Display color:<br/>";
|
|
|
|
|
const char _FORM_COLOR_BLUE[] PROGMEM = "<input class='r' id='cb' name='c' type='radio' value='blue' {check}><label for='cb'>Blue</label><br/>";
|
|
|
|
|
const char _FORM_COLOR_RED[] PROGMEM = "<input class='r' id='cr' name='c' type='radio' value='red' {check}><label for='cr'>Red</label><br/>";
|
|
|
|
|
const char _FORM_COLOR_GREEN[] PROGMEM = "<input class='r' id='cg' name='c' type='radio' value='green' {check}><label for='cg'>Green</label><br/>";
|
|
|
|
|
const char _FORM_COLOR_WHITE[] PROGMEM = "<input class='r' id='cw' name='c' type='radio' value='white' {check}><label for='cw'>White</label><br/>";
|
|
|
|
|
const char _FORM_COLOR_YELLOW[] PROGMEM = "<input class='r' id='cy' name='c' type='radio' value='yellow' {check}><label for='cy'>Yellow</label><br/>";
|
|
|
|
|
const char _FORM_BRIGHTNESS[] PROGMEM = "<br/><label for='b'>Brightness:</label><input id='b' name='b' type='range' min='10' max='255' value='{bright}'><br/>";
|
|
|
|
|
const char _FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
|
|
|
|
const char _SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
|
|
|
@ -203,6 +225,17 @@ void appConfig() {
|
|
|
|
|
page += String(F("<h3>Clock Options</h3>"));
|
|
|
|
|
//page += FPSTR(_PORTAL_OPTIONS);
|
|
|
|
|
page += FPSTR(_FORM_START);
|
|
|
|
|
page += FPSTR(_FORM_CLOCKMODE_HEADLINE);
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_DEMO);
|
|
|
|
|
input.replace("{check}", (appMode == MODE_DEMO) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_REAL);
|
|
|
|
|
input.replace("{check}", (appMode == MODE_REALCLOCK) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_FAST);
|
|
|
|
|
input.replace("{check}", (appMode == MODE_FASTCLOCK) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
|
page += FPSTR(_FORM_CLOCKNAME);
|
|
|
|
|
page += FPSTR(_FORM_COLOR_HEADLINE);
|
|
|
|
|
input = FPSTR(_FORM_COLOR_BLUE);
|
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Blue) ? "checked" : "");
|
|
|
|
@ -213,6 +246,9 @@ void appConfig() {
|
|
|
|
|
input = FPSTR(_FORM_COLOR_GREEN);
|
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Green) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
|
input = FPSTR(_FORM_COLOR_YELLOW);
|
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Yellow) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
|
input = FPSTR(_FORM_COLOR_WHITE);
|
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::White) ? "checked" : "");
|
|
|
|
|
page += input;
|
|
|
|
@ -245,6 +281,16 @@ void appConfigSave() {
|
|
|
|
|
SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c"));
|
|
|
|
|
sevenSegmentClock.setColor(colorHandle);
|
|
|
|
|
}
|
|
|
|
|
if (server->hasArg("m")) {
|
|
|
|
|
Serial.print("setting clock mode to "); Serial.println(server->arg("m"));
|
|
|
|
|
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.replace("{v}", "7Seg Config");
|
|
|
|
|
page += FPSTR(_SCRIPT);
|
|
|
|
|
page += FPSTR(_STYLE);
|
|
|
|
@ -352,6 +398,8 @@ void setup() {
|
|
|
|
|
pinMode(POWER_OFF_PIN, INPUT);
|
|
|
|
|
*/
|
|
|
|
|
setupWifiConnection();
|
|
|
|
|
Serial.println("Starting NTP Client");
|
|
|
|
|
timeClient.begin();
|
|
|
|
|
|
|
|
|
|
Serial.println("Have following configuration:");
|
|
|
|
|
Serial.print(" Clock name: "); Serial.println(clockName);
|
|
|
|
@ -372,6 +420,12 @@ int hours = 0, minutes = 0;
|
|
|
|
|
uint32_t nextUpdate_ms = 0;
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
timeClient.update();
|
|
|
|
|
|
|
|
|
|
//Serial.println(timeClient.getFormattedTime());
|
|
|
|
|
|
|
|
|
|
switch (appMode) {
|
|
|
|
|
case MODE_DEMO:
|
|
|
|
|
if (millis() > nextUpdate_ms) {
|
|
|
|
|
nextUpdate_ms = millis() + 1000;
|
|
|
|
|
minutes++;
|
|
|
|
@ -381,6 +435,14 @@ void loop() {
|
|
|
|
|
sevenSegmentClock.displayTime(hours, minutes);
|
|
|
|
|
if (hours % 4 == 0) sevenSegmentClock.setBlinkMode(SevenSegmentClock::SeperatorBlinking); else sevenSegmentClock.setBlinkMode(SevenSegmentClock::NoBlinking);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MODE_REALCLOCK:
|
|
|
|
|
sevenSegmentClock.displayTime(timeClient.getHours(), timeClient.getMinutes());
|
|
|
|
|
break;
|
|
|
|
|
case MODE_FASTCLOCK:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sevenSegmentClock.displayUpdate();
|
|
|
|
|
server->handleClient();
|
|
|
|
|
}
|
|
|
|
|