Compare commits

..

No commits in common. "b773437d45956c8e14d0bf76f76f3ada6ad963c2" and "4f28b11cf7a798845dfdf7d7a45d2008056d7f6b" have entirely different histories.

4 changed files with 19 additions and 86 deletions

View File

@ -17,5 +17,4 @@ upload_port = /dev/cu.wchusbserial1420
[lib_deps] [lib_deps]
library = library =
WifiManager, WifiManager,
Adafruit NeoPixel, Adafruit NeoPixel
NTPClient

View File

@ -193,12 +193,10 @@ void SevenSegmentClock::displaySeperator(char seperatorCharacter) {
void SevenSegmentClock::displayTime(int hour, int minute) { void SevenSegmentClock::displayTime(int hour, int minute) {
if (clockHour != hour || clockMinute != minute) {
clockHour = hour; clockHour = hour;
clockMinute = minute; clockMinute = minute;
Serial.print("SevenSegmentClock: new time "); Serial.print("SevenSegmentClock: new time ");
Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute);
}
displayUpdate(); displayUpdate();
}; };
@ -283,7 +281,7 @@ void SevenSegmentClock::displayUpdate(void) {
} }
} }
uint32_t SevenSegmentClock::red, SevenSegmentClock::green, SevenSegmentClock::blue, SevenSegmentClock::white, SevenSegmentClock::black, SevenSegmentClock::yellow; uint32_t SevenSegmentClock::red, SevenSegmentClock::green, SevenSegmentClock::blue, SevenSegmentClock::white, SevenSegmentClock::black;
uint8_t SevenSegmentClock::LedDataPin; uint8_t SevenSegmentClock::LedDataPin;
Adafruit_NeoPixel *SevenSegmentClock::strip; Adafruit_NeoPixel *SevenSegmentClock::strip;
@ -293,7 +291,6 @@ void SevenSegmentClock::initColors(uint8_t _brightness) {
SevenSegmentClock::blue = strip->Color(0, 0, _brightness); SevenSegmentClock::blue = strip->Color(0, 0, _brightness);
SevenSegmentClock::white = strip->Color(_brightness, _brightness, _brightness); SevenSegmentClock::white = strip->Color(_brightness, _brightness, _brightness);
SevenSegmentClock::black = strip->Color(0, 0, 0); SevenSegmentClock::black = strip->Color(0, 0, 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
} }
@ -305,7 +302,6 @@ void SevenSegmentClock::setColor(Color color) {
case Red: currentColor = SevenSegmentClock::red; break; case Red: currentColor = SevenSegmentClock::red; break;
case Green: currentColor = SevenSegmentClock::green; break; case Green: currentColor = SevenSegmentClock::green; break;
case White: currentColor = SevenSegmentClock::white; break; case White: currentColor = SevenSegmentClock::white; break;
case Yellow: currentColor = SevenSegmentClock::yellow; break;
} }
} }

View File

@ -19,9 +19,10 @@ public:
enum BlinkMode { NoBlinking, ClockBlinking, SeperatorBlinking, DecimalPointBlinking }; enum BlinkMode { NoBlinking, ClockBlinking, SeperatorBlinking, DecimalPointBlinking };
void setBlinkMode(BlinkMode _blinkMode) { blinkMode = _blinkMode; }; void setBlinkMode(BlinkMode _blinkMode) { blinkMode = _blinkMode; };
void setClockHalted(bool halted) { clockHalted = halted; }; void setClockHalted(bool halted) { clockHalted = halted; };
enum Color { Black, Red, Green, Blue, White, Yellow }; enum Color { Black, Red, Green, Blue, White };
void setColor(Color color); void setColor(Color color);
Color getColor(void) { return currentColorHandle; }; Color getColor(void) { return currentColorHandle; };
static uint32_t red, green, blue, white, black;
enum ClockDisplayStatus { Off, Booting, Halted, StandardClock, FastClock }; enum ClockDisplayStatus { Off, Booting, Halted, StandardClock, FastClock };
void displayDigit(unsigned int digitNum, char c); void displayDigit(unsigned int digitNum, char c);
void displaySeperator(char seperatorCharacter); void displaySeperator(char seperatorCharacter);
@ -33,7 +34,6 @@ private:
static Adafruit_NeoPixel *strip; static Adafruit_NeoPixel *strip;
static BlinkMode blinkMode; static BlinkMode blinkMode;
static uint8_t brightness; static uint8_t brightness;
static uint32_t red, green, blue, white, black, yellow;
ClockDisplayStatus displayStatus; ClockDisplayStatus displayStatus;
int clockHour; int clockHour;
int clockMinute; int clockMinute;

View File

@ -1,8 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <NTPClient.h> //https://github.com/esp8266/Arduino
#include <WiFiUdp.h>
//needed for library //needed for library
#include <DNSServer.h> #include <DNSServer.h>
@ -13,19 +11,6 @@
#include <SPI.h> #include <SPI.h>
#include "SevenSegmentClock.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"; static const char *appName = "FastclockClient7Seg";
@ -53,8 +38,7 @@ static struct ColorSelection {
{ 2, SevenSegmentClock::Blue, "blue" }, { 2, SevenSegmentClock::Blue, "blue" },
{ 3, SevenSegmentClock::Red, "red" }, { 3, SevenSegmentClock::Red, "red" },
{ 4, SevenSegmentClock::Green, "green" }, { 4, SevenSegmentClock::Green, "green" },
{ 5, SevenSegmentClock::White, "white" }, { 5, SevenSegmentClock::White, "white" }
{ 6, SevenSegmentClock::Yellow, "yellow" }
}; };
static const String getColorName(uint8_t color) { static const String getColorName(uint8_t color) {
@ -190,19 +174,13 @@ 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 _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>&nbsp;<span class='q {i}'>{r}%</span></div>"; const char _ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a>&nbsp;<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'><label for='n'>Fastclock name</label><input id='n' name='n' length=32 placeholder='clock name'><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_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_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_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_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 = "<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 _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>"; const char _SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
@ -225,17 +203,6 @@ void appConfig() {
page += String(F("<h3>Clock Options</h3>")); page += String(F("<h3>Clock Options</h3>"));
//page += FPSTR(_PORTAL_OPTIONS); //page += FPSTR(_PORTAL_OPTIONS);
page += FPSTR(_FORM_START); 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); page += FPSTR(_FORM_COLOR_HEADLINE);
input = FPSTR(_FORM_COLOR_BLUE); input = FPSTR(_FORM_COLOR_BLUE);
input.replace("{check}", (clockColor == SevenSegmentClock::Blue) ? "checked" : ""); input.replace("{check}", (clockColor == SevenSegmentClock::Blue) ? "checked" : "");
@ -246,9 +213,6 @@ void appConfig() {
input = FPSTR(_FORM_COLOR_GREEN); input = FPSTR(_FORM_COLOR_GREEN);
input.replace("{check}", (clockColor == SevenSegmentClock::Green) ? "checked" : ""); input.replace("{check}", (clockColor == SevenSegmentClock::Green) ? "checked" : "");
page += input; page += input;
input = FPSTR(_FORM_COLOR_YELLOW);
input.replace("{check}", (clockColor == SevenSegmentClock::Yellow) ? "checked" : "");
page += input;
input = FPSTR(_FORM_COLOR_WHITE); input = FPSTR(_FORM_COLOR_WHITE);
input.replace("{check}", (clockColor == SevenSegmentClock::White) ? "checked" : ""); input.replace("{check}", (clockColor == SevenSegmentClock::White) ? "checked" : "");
page += input; page += input;
@ -281,16 +245,6 @@ void appConfigSave() {
SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c")); SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c"));
sevenSegmentClock.setColor(colorHandle); 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.replace("{v}", "7Seg Config");
page += FPSTR(_SCRIPT); page += FPSTR(_SCRIPT);
page += FPSTR(_STYLE); page += FPSTR(_STYLE);
@ -398,8 +352,6 @@ void setup() {
pinMode(POWER_OFF_PIN, INPUT); pinMode(POWER_OFF_PIN, INPUT);
*/ */
setupWifiConnection(); setupWifiConnection();
Serial.println("Starting NTP Client");
timeClient.begin();
Serial.println("Have following configuration:"); Serial.println("Have following configuration:");
Serial.print(" Clock name: "); Serial.println(clockName); Serial.print(" Clock name: "); Serial.println(clockName);
@ -420,12 +372,6 @@ int hours = 0, minutes = 0;
uint32_t nextUpdate_ms = 0; uint32_t nextUpdate_ms = 0;
void loop() { void loop() {
timeClient.update();
//Serial.println(timeClient.getFormattedTime());
switch (appMode) {
case MODE_DEMO:
if (millis() > nextUpdate_ms) { if (millis() > nextUpdate_ms) {
nextUpdate_ms = millis() + 1000; nextUpdate_ms = millis() + 1000;
minutes++; minutes++;
@ -435,14 +381,6 @@ void loop() {
sevenSegmentClock.displayTime(hours, minutes); sevenSegmentClock.displayTime(hours, minutes);
if (hours % 4 == 0) sevenSegmentClock.setBlinkMode(SevenSegmentClock::SeperatorBlinking); else sevenSegmentClock.setBlinkMode(SevenSegmentClock::NoBlinking); 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(); sevenSegmentClock.displayUpdate();
server->handleClient(); server->handleClient();
} }