Compare commits
No commits in common. "d3da31d6db01ad1a2ed5fd1523bf80531c6cb1ad" and "93e82c535ee348a02d47b2809e24b0ed32987094" have entirely different histories.
d3da31d6db
...
93e82c535e
|
@ -36,8 +36,8 @@ class ClockClient
|
||||||
static int const getClockMinutes() { return clockMinutes; }
|
static int const getClockMinutes() { return clockMinutes; }
|
||||||
static int const getClockSeconds() { return clockSeconds; }
|
static int const getClockSeconds() { return clockSeconds; }
|
||||||
static void addClockChangeCallback(ClockChangeCallback callback);
|
static void addClockChangeCallback(ClockChangeCallback callback);
|
||||||
int getNumberOfKnownClocks() { return fastclockScanner.getNumberOfKnownClocks(); };
|
static int getNumberOfKnownClocks();
|
||||||
String *getKnownClocks() { return fastclockScanner.getKnownClocks(); };
|
static String *getKnownClocks();
|
||||||
int getListenPort();
|
int getListenPort();
|
||||||
IPAddress getMulticastIP();
|
IPAddress getMulticastIP();
|
||||||
static String const getClockString() {
|
static String const getClockString() {
|
||||||
|
|
|
@ -127,28 +127,6 @@ void Config::loadFile(const char *filename, const char * const sectionConfigItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::writeAllConfigs(void) {
|
|
||||||
boolean allChangesWritten = false;
|
|
||||||
logHeap();
|
|
||||||
|
|
||||||
while (!allChangesWritten) {
|
|
||||||
for (int i=0; i<numberOfConfigItems; ++i) {
|
|
||||||
debug.out(configItems[i].section);
|
|
||||||
debug.out(".");
|
|
||||||
debug.out(configItems[i].name);
|
|
||||||
debug.out("(");
|
|
||||||
debug.out(configItems[i].changed ? "changed" : "-");
|
|
||||||
debug.out(")=");
|
|
||||||
debug.outln(configItems[i].value);
|
|
||||||
if (configItems[i].changed) {
|
|
||||||
writeConfigFile(configItems[i].section);
|
|
||||||
break; // leave for-loop and restart search for changes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// no further changes found, we are done
|
|
||||||
allChangesWritten = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::writeConfigFile(String filename) {
|
void Config::writeConfigFile(String filename) {
|
||||||
logHeap();
|
logHeap();
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void setString(String parameter, String value);
|
void setString(String parameter, String value);
|
||||||
void setInt(String parameter, int value);
|
void setInt(String parameter, int value);
|
||||||
void setBoolean(String parameter, boolean value);
|
void setBoolean(String parameter, boolean value);
|
||||||
void writeAllConfigs(void) ;
|
|
||||||
private:
|
private:
|
||||||
String _filename = "";
|
String _filename = "";
|
||||||
Debug& debug;
|
Debug& debug;
|
||||||
|
|
|
@ -4,18 +4,6 @@ static const uint16_t PixelCount = 4*7*3+3;
|
||||||
|
|
||||||
#define colorSaturation 31
|
#define colorSaturation 31
|
||||||
|
|
||||||
SevenSegmentClock::ColorSelection
|
|
||||||
SevenSegmentClock::colorSelection[] = {
|
|
||||||
{ Black, "Black", 0, 0, 0 },
|
|
||||||
{ Blue, "Blue", 0, 0, 255 },
|
|
||||||
{ Red, "Red", 255, 0, 0 },
|
|
||||||
{ Green, "Green", 0, 255, 0 },
|
|
||||||
{ White, "White", 255, 255, 255 },
|
|
||||||
{ Yellow, "Yellow", 255, 255, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
int SevenSegmentClock::numberOfSupportedColors = sizeof(SevenSegmentClock::colorSelection) / sizeof(SevenSegmentClock::colorSelection[0]);
|
|
||||||
|
|
||||||
// Seven Segment Layout: 3 LEDs per segment
|
// Seven Segment Layout: 3 LEDs per segment
|
||||||
// order of segments:
|
// order of segments:
|
||||||
// b
|
// b
|
||||||
|
@ -300,7 +288,6 @@ uint8_t SevenSegmentClock::LedDataPin;
|
||||||
Adafruit_NeoPixel *SevenSegmentClock::strip;
|
Adafruit_NeoPixel *SevenSegmentClock::strip;
|
||||||
|
|
||||||
void SevenSegmentClock::initColors(uint8_t _brightness) {
|
void SevenSegmentClock::initColors(uint8_t _brightness) {
|
||||||
#if 0
|
|
||||||
SevenSegmentClock::red = strip->Color(_brightness, 0, 0);
|
SevenSegmentClock::red = strip->Color(_brightness, 0, 0);
|
||||||
SevenSegmentClock::green = strip->Color(0, _brightness, 0);
|
SevenSegmentClock::green = strip->Color(0, _brightness, 0);
|
||||||
SevenSegmentClock::blue = strip->Color(0, 0, _brightness);
|
SevenSegmentClock::blue = strip->Color(0, 0, _brightness);
|
||||||
|
@ -308,13 +295,10 @@ void SevenSegmentClock::initColors(uint8_t _brightness) {
|
||||||
SevenSegmentClock::black = strip->Color(0, 0, 0);
|
SevenSegmentClock::black = strip->Color(0, 0, 0);
|
||||||
SevenSegmentClock::yellow = strip->Color(_brightness, _brightness, 0);
|
SevenSegmentClock::yellow = strip->Color(_brightness, _brightness, 0);
|
||||||
SevenSegmentClock::setColor(SevenSegmentClock::getColor()); // reset color to enforce reclaculation
|
SevenSegmentClock::setColor(SevenSegmentClock::getColor()); // reset color to enforce reclaculation
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SevenSegmentClock::setColor(Color color) {
|
void SevenSegmentClock::setColor(Color color) {
|
||||||
currentColorHandle = color;
|
currentColorHandle = color;
|
||||||
currentColor = getColorByHandle(color);
|
|
||||||
#if 0
|
|
||||||
switch (currentColorHandle) {
|
switch (currentColorHandle) {
|
||||||
case Black: currentColor = SevenSegmentClock::black; break;
|
case Black: currentColor = SevenSegmentClock::black; break;
|
||||||
case Blue: currentColor = SevenSegmentClock::blue; break;
|
case Blue: currentColor = SevenSegmentClock::blue; break;
|
||||||
|
@ -323,7 +307,6 @@ void SevenSegmentClock::setColor(Color color) {
|
||||||
case White: currentColor = SevenSegmentClock::white; break;
|
case White: currentColor = SevenSegmentClock::white; break;
|
||||||
case Yellow: currentColor = SevenSegmentClock::yellow; break;
|
case Yellow: currentColor = SevenSegmentClock::yellow; break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SevenSegmentClock::begin(void) {
|
void SevenSegmentClock::begin(void) {
|
||||||
|
|
|
@ -29,49 +29,6 @@ public:
|
||||||
void displaySeperator(char seperatorCharacter);
|
void displaySeperator(char seperatorCharacter);
|
||||||
void setBrightness(uint8_t b) { brightness=b; initColors(b); };
|
void setBrightness(uint8_t b) { brightness=b; initColors(b); };
|
||||||
uint8_t getBrightness(void) { return brightness; };
|
uint8_t getBrightness(void) { return brightness; };
|
||||||
int getNumberSupportedColors(void) { return numberOfSupportedColors; };
|
|
||||||
String getColorName(int index) { return String(colorSelection[index].colorName); };
|
|
||||||
String getColorName(Color handle) {
|
|
||||||
for (int i=0; i<numberOfSupportedColors; ++i) {
|
|
||||||
if (colorSelection[i].handle == handle)
|
|
||||||
return colorSelection[i].colorName;
|
|
||||||
}
|
|
||||||
debug.outln(F("ERROR: Unknown color / handle not known"), DEBUG_ERROR);
|
|
||||||
return String(F("ERROR: Unknown color handle"));
|
|
||||||
};
|
|
||||||
Color getColorHandle(int index) { return colorSelection[index].handle; };
|
|
||||||
uint32_t getAdjustedStripColor(uint8_t red, uint8_t green, uint8_t blue) {
|
|
||||||
return strip->Color((red * brightness) / 255, (green * brightness) / 255, (blue * brightness) / 255);
|
|
||||||
}
|
|
||||||
uint32 getColorByName(String name) {
|
|
||||||
for (int i=0; i<numberOfSupportedColors; ++i) {
|
|
||||||
if (colorSelection[i].colorName.equals(name)) {
|
|
||||||
return getAdjustedStripColor(colorSelection[i].red, colorSelection[i].green, colorSelection[i].blue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug.out(F("ERROR: Unknown color name "), DEBUG_ERROR);
|
|
||||||
debug.outln(name, DEBUG_ERROR);
|
|
||||||
return 0xffffffff;
|
|
||||||
};
|
|
||||||
uint32 getColorByHandle(Color handle) {
|
|
||||||
for (int i=0; i<numberOfSupportedColors; ++i) {
|
|
||||||
if (colorSelection[i].handle == handle) {
|
|
||||||
return getAdjustedStripColor(colorSelection[i].red, colorSelection[i].green, colorSelection[i].blue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug.outln(F("ERROR: Unknown color handle"), DEBUG_ERROR);
|
|
||||||
return 0xffffffff;
|
|
||||||
};
|
|
||||||
Color getColorHandleByName(String name) {
|
|
||||||
for (int i=0; i<numberOfSupportedColors; ++i) {
|
|
||||||
if (colorSelection[i].colorName.equals(name)) {
|
|
||||||
return colorSelection[i].handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug.out(F("ERROR: Unknown color name "), DEBUG_ERROR);
|
|
||||||
debug.outln(name, DEBUG_ERROR);
|
|
||||||
return Green; // default
|
|
||||||
};
|
|
||||||
private:
|
private:
|
||||||
Debug& debug;
|
Debug& debug;
|
||||||
Config& config;
|
Config& config;
|
||||||
|
@ -89,11 +46,5 @@ private:
|
||||||
uint32_t currentColor;
|
uint32_t currentColor;
|
||||||
void displaySegment(unsigned int ledAddress, uint32_t color);
|
void displaySegment(unsigned int ledAddress, uint32_t color);
|
||||||
void initColors(uint8_t _brightness);
|
void initColors(uint8_t _brightness);
|
||||||
static struct ColorSelection {
|
|
||||||
Color handle;
|
|
||||||
String colorName;
|
|
||||||
uint8_t red, green, blue;
|
|
||||||
} colorSelection[];
|
|
||||||
static int numberOfSupportedColors;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
248
src/main.cpp
248
src/main.cpp
|
@ -41,8 +41,61 @@ Debug debug;
|
||||||
Config config(debug);
|
Config config(debug);
|
||||||
ClockClient fastclock(debug, config);
|
ClockClient fastclock(debug, config);
|
||||||
SevenSegmentClock sevenSegmentClock(debug, config);
|
SevenSegmentClock sevenSegmentClock(debug, config);
|
||||||
ClockClient fastclockClient(debug, config);
|
|
||||||
ESP8266WebServer *server;
|
ESP8266WebServer *server;
|
||||||
|
ClockClient fastclockClient(debug, config);
|
||||||
|
|
||||||
|
static struct ColorSelection {
|
||||||
|
uint8_t id;
|
||||||
|
SevenSegmentClock::Color colorHandle;
|
||||||
|
String colorName;
|
||||||
|
} colorSelection[] = {
|
||||||
|
{ 1, SevenSegmentClock::Black, "black" },
|
||||||
|
{ 2, SevenSegmentClock::Blue, "blue" },
|
||||||
|
{ 3, SevenSegmentClock::Red, "red" },
|
||||||
|
{ 4, SevenSegmentClock::Green, "green" },
|
||||||
|
{ 5, SevenSegmentClock::White, "white" },
|
||||||
|
{ 6, SevenSegmentClock::Yellow, "yellow" }
|
||||||
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
static const String getColorName(uint8_t color) {
|
||||||
|
for (unsigned int i=0; i<sizeof(colorSelection); ++i) {
|
||||||
|
if (color == colorSelection[i].id) {
|
||||||
|
return colorSelection[i].colorName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "**INVALID**";
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t getColorId(SevenSegmentClock::Color color) {
|
||||||
|
for (unsigned int i=0; i<sizeof(colorSelection); ++i) {
|
||||||
|
if (color == colorSelection[i].colorHandle) {
|
||||||
|
return colorSelection[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const SevenSegmentClock::Color getColorHandle(uint8_t id) {
|
||||||
|
for (unsigned int i=0; i<sizeof(colorSelection); ++i) {
|
||||||
|
if (id == colorSelection[i].id) {
|
||||||
|
return colorSelection[i].colorHandle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SevenSegmentClock::Green; // default
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const SevenSegmentClock::Color getColorHandleByName(String name) {
|
||||||
|
for (unsigned int i=0; i<sizeof(colorSelection); ++i) {
|
||||||
|
if (name.equals(colorSelection[i].colorName)) {
|
||||||
|
return colorSelection[i].colorHandle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SevenSegmentClock::Green; // default
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//flag for saving data
|
//flag for saving data
|
||||||
bool shouldSaveConfig = false;
|
bool shouldSaveConfig = false;
|
||||||
|
@ -81,6 +134,25 @@ void setupWifiConnection() {
|
||||||
//save the custom parameters to FS
|
//save the custom parameters to FS
|
||||||
if (shouldSaveConfig) {
|
if (shouldSaveConfig) {
|
||||||
debug.outln("saving config ... NYI", DEBUG_MED_INFO);
|
debug.outln("saving config ... NYI", DEBUG_MED_INFO);
|
||||||
|
// DynamicJsonDocument config(2048);
|
||||||
|
//JsonObject json = jsonBuffer.createObject();
|
||||||
|
/*
|
||||||
|
config["clock_name"] = clockName;
|
||||||
|
config["clock_channel"] = clockChannelString;
|
||||||
|
config["clock_color"] = clockColor;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
File configFile = SPIFFS.open("/config.json", "w");
|
||||||
|
if (!configFile) {
|
||||||
|
Serial.println("failed to open config file for writing");
|
||||||
|
}
|
||||||
|
|
||||||
|
serializeJsonPretty(config, Serial);
|
||||||
|
serializeJson(config, configFile);
|
||||||
|
configFile.close();
|
||||||
|
//end save
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.out("local ip: ", DEBUG_MAX_INFO); debug.outln(WiFi.localIP(), DEBUG_MAX_INFO);
|
debug.out("local ip: ", DEBUG_MAX_INFO); debug.outln(WiFi.localIP(), DEBUG_MAX_INFO);
|
||||||
|
@ -94,11 +166,8 @@ const char _SCRIPT[] PROGMEM = "<script>function c(l){document.getEle
|
||||||
const char _HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
|
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 _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 _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'>";
|
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' value='{n}'><br/>";
|
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_CLOCKSFOUND_START[] PROGMEM = "Fastclocks seen:<br/><ul>";
|
|
||||||
const char _FORM_CLOCKSFOUND_ITEM[] PROGMEM = "<li>{fc}</li>";
|
|
||||||
const char _FORM_CLOCKSFOUND_END[] PROGMEM = "</ul><br/>";
|
|
||||||
const char _FORM_CLOCKMODE_HEADLINE[] PROGMEM = "<br/>Clock mode:<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_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_REAL[] PROGMEM = "<input class='r' id='mr' name='m' type='radio' value='real' {check}><label for='md'>Real Clock</label><br/>";
|
||||||
|
@ -106,18 +175,15 @@ const char _FORM_CLOCKMODE_FAST[] PROGMEM = "<input class='r' id='mf' name='m' t
|
||||||
const char _FORM_UTC_OFFSET[] PROGMEM = "<label for='utc'>UTC offset (minutes)</label><input id='utc' name='utc' length=4 placeholder='120'><br/>";
|
const char _FORM_UTC_OFFSET[] PROGMEM = "<label for='utc'>UTC offset (minutes)</label><input id='utc' name='utc' length=4 placeholder='120'><br/>";
|
||||||
const char _FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
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_HEADLINE[] PROGMEM = "<br/>Display color:<br/>";
|
||||||
const char _FORM_COLOR_template[] PROGMEM = "<input class='r' id='{cid}' name='c' type='radio' value='{cname}' {check}><label for='{cid}'>{cname}</label><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_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_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_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_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_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_BRIGHTNESS[] PROGMEM = "<label for='b'>Brightness:</label><input id='b' name='b' type='range' min='10' max='255' value='{bright}'><br/>";
|
const char _FORM_FASTCLOCK_INFO[] PROGMEM = "<br/><br/><div>Number of fastclocks found: {nfc}</div>";
|
||||||
const char _FORM_FASTCLOCK_INFO[] PROGMEM = "<div>Number of fastclocks found: {nfc}</div><br/>";
|
const char _FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||||
const char _FORM_END[] PROGMEM = "<br/><button type='submit'>apply</button></form><br/>";
|
const char _CONFIG_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/config\">Configure</a></div>";
|
||||||
const char _SAVE_PERM_BUTTON[] PROGMEM = "<br/><form action=\"/configSavePermanent\" method=\"get\"><button>Save permanently</button></form><br/>";
|
|
||||||
const char _CONFIG_BUTTON[] PROGMEM = "<br/><form action=\"/config\" method=\"get\"><button>Configure</button></form><br/>";
|
|
||||||
const char _VSPACE[] PROGMEM = "<br/><br/>";
|
|
||||||
const char _SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
const char _SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||||
const char _END[] PROGMEM = "</div></body></html>";
|
const char _END[] PROGMEM = "</div></body></html>";
|
||||||
|
|
||||||
|
@ -125,7 +191,6 @@ void appConfig() {
|
||||||
String page = FPSTR(_HEAD);
|
String page = FPSTR(_HEAD);
|
||||||
String input;
|
String input;
|
||||||
String value;
|
String value;
|
||||||
int ivalue;
|
|
||||||
|
|
||||||
page.replace("{v}", "7Seg Config");
|
page.replace("{v}", "7Seg Config");
|
||||||
page += FPSTR(_SCRIPT);
|
page += FPSTR(_SCRIPT);
|
||||||
|
@ -148,43 +213,32 @@ void appConfig() {
|
||||||
input = FPSTR(_FORM_CLOCKMODE_FAST);
|
input = FPSTR(_FORM_CLOCKMODE_FAST);
|
||||||
input.replace("{check}", (config.getString("appMode").equals("Fastclock")) ? "checked" : "");
|
input.replace("{check}", (config.getString("appMode").equals("Fastclock")) ? "checked" : "");
|
||||||
page += input;
|
page += input;
|
||||||
page += FPSTR(_VSPACE);
|
|
||||||
page += FPSTR(_FORM_UTC_OFFSET);
|
page += FPSTR(_FORM_UTC_OFFSET);
|
||||||
page += FPSTR(_VSPACE);
|
page += FPSTR(_FORM_CLOCKNAME);
|
||||||
input = FPSTR(_FORM_CLOCKNAME);
|
|
||||||
value = config.getString("listenToClock");
|
|
||||||
input.replace("{n}", value);
|
|
||||||
page += input;
|
|
||||||
page += FPSTR(_FORM_CLOCKSFOUND_START);
|
|
||||||
String *knownClocks = fastclock.getKnownClocks();
|
|
||||||
for (int i=0; i<fastclock.getNumberOfKnownClocks(); ++i) {
|
|
||||||
input = FPSTR(_FORM_CLOCKSFOUND_ITEM);
|
|
||||||
input.replace("{fc}", knownClocks[i]);
|
|
||||||
page += input;
|
|
||||||
}
|
|
||||||
page += FPSTR(_FORM_CLOCKSFOUND_END);
|
|
||||||
|
|
||||||
page += FPSTR(_VSPACE);
|
|
||||||
page += FPSTR(_FORM_COLOR_HEADLINE);
|
page += FPSTR(_FORM_COLOR_HEADLINE);
|
||||||
for (int i=0; i<sevenSegmentClock.getNumberSupportedColors(); ++i) {
|
input = FPSTR(_FORM_COLOR_BLUE);
|
||||||
input = FPSTR(_FORM_COLOR_template);
|
input.replace("{check}", (config.getString("clockColor").equals("Blue")) ? "checked" : "");
|
||||||
input.replace("{cid}", sevenSegmentClock.getColorName(i));
|
page += input;
|
||||||
input.replace("{cname}", sevenSegmentClock.getColorName(i));
|
input = FPSTR(_FORM_COLOR_RED);
|
||||||
input.replace("{check}", (config.getString("clockColor").equals(sevenSegmentClock.getColorName(i))) ? "checked" : "");
|
input.replace("{check}", (config.getString("clockColor").equals("Red")) ? "checked" : "");
|
||||||
|
page += input;
|
||||||
|
input = FPSTR(_FORM_COLOR_GREEN);
|
||||||
|
input.replace("{check}", (config.getString("clockColor").equals("Green")) ? "checked" : "");
|
||||||
|
page += input;
|
||||||
|
input = FPSTR(_FORM_COLOR_YELLOW);
|
||||||
|
input.replace("{check}", (config.getString("clockColor").equals("Yellow")) ? "checked" : "");
|
||||||
|
page += input;
|
||||||
|
input = FPSTR(_FORM_COLOR_WHITE);
|
||||||
|
input.replace("{check}", (config.getString("clockColor").equals("White")) ? "checked" : "");
|
||||||
page += input;
|
page += input;
|
||||||
}
|
|
||||||
|
|
||||||
page += FPSTR(_VSPACE);
|
|
||||||
input = FPSTR(_FORM_BRIGHTNESS);
|
input = FPSTR(_FORM_BRIGHTNESS);
|
||||||
value = String(sevenSegmentClock.getBrightness());
|
value = String(sevenSegmentClock.getBrightness());
|
||||||
input.replace("{bright}", value);
|
input.replace("{bright}", value);
|
||||||
page += input;
|
page += input;
|
||||||
|
|
||||||
page += FPSTR(_VSPACE);
|
|
||||||
input = FPSTR(_FORM_FASTCLOCK_INFO);
|
input = FPSTR(_FORM_FASTCLOCK_INFO);
|
||||||
ivalue = fastclock.getNumberOfKnownClocks();
|
//value = String(ClockClient::getNumberOfKnownClocks());
|
||||||
value = String(ivalue);
|
value = String("unknown");
|
||||||
//value = String("unknown");
|
|
||||||
input.replace("{nfc}", value);
|
input.replace("{nfc}", value);
|
||||||
page += input;
|
page += input;
|
||||||
|
|
||||||
|
@ -217,18 +271,15 @@ void appConfigSave() {
|
||||||
debug.outln(server->arg(i), DEBUG_MAX_INFO);
|
debug.outln(server->arg(i), DEBUG_MAX_INFO);
|
||||||
}
|
}
|
||||||
if (server->hasArg("b")) {
|
if (server->hasArg("b")) {
|
||||||
int brightness = server->arg("b").toInt();
|
sevenSegmentClock.setBrightness(server->arg("b").toInt());
|
||||||
sevenSegmentClock.setBrightness(brightness);
|
|
||||||
config.setInt("brightness", brightness);
|
|
||||||
page += F("<div>Set brightness to ");
|
page += F("<div>Set brightness to ");
|
||||||
page += server->arg("b");
|
page += server->arg("b");
|
||||||
page += F(".</div>");
|
page += F(".</div>");
|
||||||
}
|
}
|
||||||
if (server->hasArg("c")) {
|
if (server->hasArg("c")) {
|
||||||
String colorName = server->arg("c");
|
String colorName = server->arg("c");
|
||||||
SevenSegmentClock::Color colorHandle = sevenSegmentClock.getColorHandleByName(server->arg("c"));
|
SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c"));
|
||||||
sevenSegmentClock.setColor(colorHandle);
|
sevenSegmentClock.setColor(colorHandle);
|
||||||
config.setString("clockColor", colorName);
|
|
||||||
page += F("<div>Set color to ");
|
page += F("<div>Set color to ");
|
||||||
page += server->arg("c");
|
page += server->arg("c");
|
||||||
page += F(".</div>");
|
page += F(".</div>");
|
||||||
|
@ -262,28 +313,7 @@ void appConfigSave() {
|
||||||
page += F(" minutes.</div>");
|
page += F(" minutes.</div>");
|
||||||
}
|
}
|
||||||
page += String(F("<div>Configuration updated.</div>"));
|
page += String(F("<div>Configuration updated.</div>"));
|
||||||
page += FPSTR(_CONFIG_BUTTON);
|
page += FPSTR(_CONFIG_LINK);
|
||||||
page += FPSTR(_SAVE_PERM_BUTTON);
|
|
||||||
page += FPSTR(_END);
|
|
||||||
server->sendHeader("Content-Length", String(page.length()));
|
|
||||||
server->send(200, "text/html", page);
|
|
||||||
}
|
|
||||||
|
|
||||||
void appConfigSavePermanent() {
|
|
||||||
String page = FPSTR(_HEAD);
|
|
||||||
|
|
||||||
page.replace("{v}", "7Seg Config");
|
|
||||||
page += FPSTR(_SCRIPT);
|
|
||||||
page += FPSTR(_STYLE);
|
|
||||||
page += FPSTR(_HEAD_END);
|
|
||||||
page += String(F("<h1>"));
|
|
||||||
page += appName;
|
|
||||||
page += String(F("</h1>"));
|
|
||||||
|
|
||||||
debug.outln("Writing configs to save them permanently", DEBUG_MAX_INFO);
|
|
||||||
config.writeAllConfigs();
|
|
||||||
page += String(F("<div>Configuration permanently saved.</div>"));
|
|
||||||
page += FPSTR(_CONFIG_BUTTON);
|
|
||||||
page += FPSTR(_END);
|
page += FPSTR(_END);
|
||||||
server->sendHeader("Content-Length", String(page.length()));
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
@ -303,15 +333,77 @@ void setup() {
|
||||||
if (SPIFFS.begin()) {
|
if (SPIFFS.begin()) {
|
||||||
debug.outln(F("mounted file system"), DEBUG_MAX_INFO);
|
debug.outln(F("mounted file system"), DEBUG_MAX_INFO);
|
||||||
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
|
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
|
||||||
|
#if 0
|
||||||
|
if (SPIFFS.exists("/config.json")) {
|
||||||
|
//file exists, reading and loading
|
||||||
|
Serial.println("reading config file");
|
||||||
|
File configFile = SPIFFS.open("/config.json", "r");
|
||||||
|
if (configFile) {
|
||||||
|
Serial.println("opened config file");
|
||||||
|
size_t size = configFile.size();
|
||||||
|
// Allocate a buffer to store contents of the file.
|
||||||
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
|
||||||
|
configFile.readBytes(buf.get(), size);
|
||||||
|
DynamicJsonDocument config(2048);
|
||||||
|
//JsonObject json = jsonBuffer.createObject();
|
||||||
|
DeserializationError error = deserializeJson(config, configFile);
|
||||||
|
serializeJson(config, Serial);
|
||||||
|
if (!error) {
|
||||||
|
Serial.println("\nparsed json");
|
||||||
|
|
||||||
|
//**strcpy(mqtt_server, json["mqtt_server"]);
|
||||||
|
//**strcpy(mqtt_port, json["mqtt_port"]);
|
||||||
|
//strcpy(blynk_token, json["blynk_token"]);
|
||||||
|
|
||||||
|
if (config["clock_name"]) {
|
||||||
|
strncpy(clockName, config["clock_name"], MAX_CLOCK_NAME_LEN);
|
||||||
|
} else {
|
||||||
|
Serial.println("no clock name in config");
|
||||||
|
}
|
||||||
|
if (config["clock_channel"]) {
|
||||||
|
strncpy(clockChannelString, config["clock_channel"], MAX_CLOCK_CHANNEL_STRING_LEN);
|
||||||
|
} else {
|
||||||
|
Serial.println("no clock channel in config");
|
||||||
|
}
|
||||||
|
if (config["clock_color"]) {
|
||||||
|
//strncpy(clockColor, config["clock_color"], MAX_CLOCK_COLOR_LEN);
|
||||||
|
clockColor = getColorHandle(config["clock_color"]);
|
||||||
|
} else {
|
||||||
|
Serial.println("no clock color in config");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("failed to load json config, using defaults");
|
||||||
|
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 = getColorHandleByName(DEFAULT_CLOCK_COLOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("no config file found");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
debug.outln(F("failed to mount FS"), DEBUG_ERROR);
|
debug.outln(F("failed to mount FS"), DEBUG_ERROR);
|
||||||
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
|
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
|
||||||
}
|
}
|
||||||
|
//end read
|
||||||
|
// setupWifiConnection();
|
||||||
|
|
||||||
|
/*
|
||||||
|
radio.setClockChannel(clockChannel);
|
||||||
|
radio.setClockName(clockName);
|
||||||
|
radio.begin();
|
||||||
|
fastclock.begin();
|
||||||
|
pinMode(POWER_OFF_PIN, INPUT);
|
||||||
|
*/
|
||||||
setupWifiConnection();
|
setupWifiConnection();
|
||||||
debug.outln(F("Starting NTP Client"), DEBUG_MAX_INFO);
|
debug.outln(F("Starting NTP Client"), DEBUG_MAX_INFO);
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
|
|
||||||
debug.outln(F("Have following configuration:"), DEBUG_MAX_INFO);
|
debug.outln(F("Have following configuration:"), DEBUG_MAX_INFO);
|
||||||
|
//Serial.print(" Clock name: "); Serial.println(config.getString("clock_name"));
|
||||||
debug.out(F(" App Mode: "), DEBUG_MAX_INFO); debug.outln(config.getString("appMode"), DEBUG_MAX_INFO);
|
debug.out(F(" App Mode: "), DEBUG_MAX_INFO); debug.outln(config.getString("appMode"), DEBUG_MAX_INFO);
|
||||||
debug.out(F(" Clock color: "), DEBUG_MAX_INFO); debug.outln(config.getString("clockColor"), DEBUG_MAX_INFO);
|
debug.out(F(" Clock color: "), DEBUG_MAX_INFO); debug.outln(config.getString("clockColor"), DEBUG_MAX_INFO);
|
||||||
debug.out(F(" Brightness: "), DEBUG_MAX_INFO); debug.outln(config.getString("brightness"), DEBUG_MAX_INFO);
|
debug.out(F(" Brightness: "), DEBUG_MAX_INFO); debug.outln(config.getString("brightness"), DEBUG_MAX_INFO);
|
||||||
|
@ -325,15 +417,11 @@ void setup() {
|
||||||
|
|
||||||
debug.outln(F("Starting 7-segment clock display ..."), DEBUG_MAX_INFO);
|
debug.outln(F("Starting 7-segment clock display ..."), DEBUG_MAX_INFO);
|
||||||
sevenSegmentClock.begin();
|
sevenSegmentClock.begin();
|
||||||
sevenSegmentClock.setBrightness(config.getInt("brightness"));
|
|
||||||
sevenSegmentClock.setColor(sevenSegmentClock.getColorHandleByName(config.getString("clockColor")));
|
|
||||||
|
|
||||||
// setting up web server for clock configuration
|
// setting up web server for clock configuration
|
||||||
server = new ESP8266WebServer(80);
|
server = new ESP8266WebServer(80);
|
||||||
server->on("/config", HTTP_GET, appConfig);
|
server->on("/config", HTTP_GET, appConfig);
|
||||||
server->on("/configSave", HTTP_GET, appConfigSave);
|
server->on("/configsave", HTTP_GET, appConfigSave);
|
||||||
server->on("/configSavePermanent", HTTP_GET, appConfigSavePermanent);
|
|
||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +432,8 @@ void loop() {
|
||||||
timeClient.update();
|
timeClient.update();
|
||||||
fastclock.loop();
|
fastclock.loop();
|
||||||
|
|
||||||
|
//Serial.println(timeClient.getFormattedTime());
|
||||||
|
|
||||||
if (config.getString("appMode").equals(MODE_DEMO)) {
|
if (config.getString("appMode").equals(MODE_DEMO)) {
|
||||||
if (millis() > nextUpdate_ms) {
|
if (millis() > nextUpdate_ms) {
|
||||||
nextUpdate_ms = millis() + 1000;
|
nextUpdate_ms = millis() + 1000;
|
||||||
|
|
Loading…
Reference in New Issue