diff --git a/src/ClockClient.h b/src/ClockClient.h index 4c79a01..88ba32f 100644 --- a/src/ClockClient.h +++ b/src/ClockClient.h @@ -36,7 +36,7 @@ class ClockClient static int const getClockMinutes() { return clockMinutes; } static int const getClockSeconds() { return clockSeconds; } static void addClockChangeCallback(ClockChangeCallback callback); - static int getNumberOfKnownClocks(); + int getNumberOfKnownClocks() { return fastclockScanner.getNumberOfKnownClocks(); }; static String *getKnownClocks(); int getListenPort(); IPAddress getMulticastIP(); diff --git a/src/SevenSegmentClock.cpp b/src/SevenSegmentClock.cpp index e8f6594..05c49c9 100644 --- a/src/SevenSegmentClock.cpp +++ b/src/SevenSegmentClock.cpp @@ -4,6 +4,18 @@ static const uint16_t PixelCount = 4*7*3+3; #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 // order of segments: // b @@ -288,6 +300,7 @@ uint8_t SevenSegmentClock::LedDataPin; Adafruit_NeoPixel *SevenSegmentClock::strip; void SevenSegmentClock::initColors(uint8_t _brightness) { + #if 0 SevenSegmentClock::red = strip->Color(_brightness, 0, 0); SevenSegmentClock::green = strip->Color(0, _brightness, 0); SevenSegmentClock::blue = strip->Color(0, 0, _brightness); @@ -295,10 +308,13 @@ void SevenSegmentClock::initColors(uint8_t _brightness) { SevenSegmentClock::black = strip->Color(0, 0, 0); SevenSegmentClock::yellow = strip->Color(_brightness, _brightness, 0); SevenSegmentClock::setColor(SevenSegmentClock::getColor()); // reset color to enforce reclaculation + #endif } void SevenSegmentClock::setColor(Color color) { currentColorHandle = color; + currentColor = getColorByHandle(color); + #if 0 switch (currentColorHandle) { case Black: currentColor = SevenSegmentClock::black; break; case Blue: currentColor = SevenSegmentClock::blue; break; @@ -307,6 +323,7 @@ void SevenSegmentClock::setColor(Color color) { case White: currentColor = SevenSegmentClock::white; break; case Yellow: currentColor = SevenSegmentClock::yellow; break; } + #endif } void SevenSegmentClock::begin(void) { diff --git a/src/SevenSegmentClock.h b/src/SevenSegmentClock.h index f33abef..f237710 100644 --- a/src/SevenSegmentClock.h +++ b/src/SevenSegmentClock.h @@ -29,6 +29,49 @@ public: void displaySeperator(char seperatorCharacter); void setBrightness(uint8_t b) { brightness=b; initColors(b); }; 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; iColor((red * brightness) / 255, (green * brightness) / 255, (blue * brightness) / 255); + } + uint32 getColorByName(String name) { + for (int i=0; iUTC offset (minutes)
"; const char _FORM_PARAM[] PROGMEM = "
"; const char _FORM_COLOR_HEADLINE[] PROGMEM = "
Display color:
"; -const char _FORM_COLOR_BLUE[] PROGMEM = "
"; -const char _FORM_COLOR_RED[] PROGMEM = "
"; -const char _FORM_COLOR_GREEN[] PROGMEM = "
"; -const char _FORM_COLOR_WHITE[] PROGMEM = "
"; -const char _FORM_COLOR_YELLOW[] PROGMEM = "
"; -const char _FORM_BRIGHTNESS[] PROGMEM = "

"; -const char _FORM_FASTCLOCK_INFO[] PROGMEM = "

Number of fastclocks found: {nfc}
"; -const char _FORM_END[] PROGMEM = "
"; -const char _CONFIG_LINK[] PROGMEM = "
"; +const char _FORM_COLOR_template[] PROGMEM = "
"; +const char _FORM_COLOR_BLUE[] PROGMEM = "
"; +const char _FORM_COLOR_RED[] PROGMEM = "
"; +const char _FORM_COLOR_GREEN[] PROGMEM = "
"; +const char _FORM_COLOR_WHITE[] PROGMEM = "
"; +const char _FORM_COLOR_YELLOW[] PROGMEM = "
"; +const char _FORM_BRIGHTNESS[] PROGMEM = "
"; +const char _FORM_FASTCLOCK_INFO[] PROGMEM = "
Number of fastclocks found: {nfc}

"; +const char _FORM_END[] PROGMEM = "

"; +const char _SAVE_PERM_BUTTON[] PROGMEM = "

"; +const char _CONFIG_BUTTON[] PROGMEM = "

"; +const char _VSPACE[] PROGMEM = "

"; const char _SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; const char _END[] PROGMEM = ""; @@ -172,6 +122,7 @@ void appConfig() { String page = FPSTR(_HEAD); String input; String value; + int ivalue; page.replace("{v}", "7Seg Config"); page += FPSTR(_SCRIPT); @@ -194,32 +145,31 @@ void appConfig() { input = FPSTR(_FORM_CLOCKMODE_FAST); input.replace("{check}", (config.getString("appMode").equals("Fastclock")) ? "checked" : ""); page += input; + page += FPSTR(_VSPACE); page += FPSTR(_FORM_UTC_OFFSET); + page += FPSTR(_VSPACE); page += FPSTR(_FORM_CLOCKNAME); + page += FPSTR(_VSPACE); page += FPSTR(_FORM_COLOR_HEADLINE); - input = FPSTR(_FORM_COLOR_BLUE); - input.replace("{check}", (config.getString("clockColor").equals("Blue")) ? "checked" : ""); - page += input; - input = FPSTR(_FORM_COLOR_RED); - 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; + for (int i=0; iarg(i), DEBUG_MAX_INFO); } if (server->hasArg("b")) { - sevenSegmentClock.setBrightness(server->arg("b").toInt()); + int brightness = server->arg("b").toInt(); + sevenSegmentClock.setBrightness(brightness); + config.setInt("brightness", brightness); 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::Color colorHandle = sevenSegmentClock.getColorHandleByName(server->arg("c")); sevenSegmentClock.setColor(colorHandle); + config.setString("clockColor", colorName); page += F("
Set color to "); page += server->arg("c"); page += F(".
"); @@ -294,7 +247,8 @@ void appConfigSave() { page += F(" minutes."); } page += String(F("
Configuration updated.
")); - page += FPSTR(_CONFIG_LINK); + page += FPSTR(_CONFIG_BUTTON); + page += FPSTR(_SAVE_PERM_BUTTON); page += FPSTR(_END); server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page);