minor fixes

This commit is contained in:
coelner 2021-01-30 14:04:23 +01:00
parent 2453e9d74b
commit a8d7c13c07

View File

@ -41,7 +41,7 @@
#define NUM_LEDS 60 #define NUM_LEDS 60
#define SERIAL_BAUD 115200 #define SERIAL_BAUD 115200
#define RGBW //#define RGBW
volatile bool singleSecond = true; //show seconds volatile bool singleSecond = true; //show seconds
volatile bool allDotsOn = true; //lighten up all leds volatile bool allDotsOn = true; //lighten up all leds
volatile bool followingHour = true; //move hour like an analog one volatile bool followingHour = true; //move hour like an analog one
@ -78,7 +78,7 @@ RgbwColor darkred(HtmlColor( 0x800000) );
RgbwColor darkgreen(HtmlColor( 0x006400) ); RgbwColor darkgreen(HtmlColor( 0x006400) );
RgbwColor lightgreen(HtmlColor( 0x30ee30) ); RgbwColor lightgreen(HtmlColor( 0x30ee30) );
RgbwColor temp; RgbwColor temp;
RgbwColor secondsColor = white; RgbwColor secondsColor = black;
RgbwColor minuteColor = darkred; RgbwColor minuteColor = darkred;
RgbwColor hourColor = gold; RgbwColor hourColor = gold;
RgbwColor highnoonColor = white12; RgbwColor highnoonColor = white12;
@ -91,12 +91,12 @@ void transformtoHtmlColor (char* sOutput, RgbwColor* inputColor) {
if (inputColor->IsMonotone()) if (inputColor->IsMonotone())
{ {
//Serial.print("White: "); Serial.println(inputColor->W); //Serial.print("White: "); Serial.println(inputColor->W);
Serial.print(HtmlColor(RgbColor(inputColor->W, inputColor->W, inputColor->W)).ToNumericalString(sOutput, 12)); HtmlColor(RgbColor(inputColor->W, inputColor->W, inputColor->W)).ToNumericalString(sOutput, 12);
//Serial.println((char*)sOutput); //Serial.println((char*)sOutput);
} }
else { else {
//Serial.print("Color: "); Serial.print(inputColor->R); Serial.print(inputColor->G); Serial.println(inputColor->B); //Serial.print("Color: "); Serial.print(inputColor->R); Serial.print(inputColor->G); Serial.println(inputColor->B);
Serial.print(HtmlColor(RgbColor(inputColor->R, inputColor->G, inputColor->B)).ToNumericalString(sOutput, 12)); HtmlColor(RgbColor(inputColor->R, inputColor->G, inputColor->B)).ToNumericalString(sOutput, 12);
//Serial.println((char*)sOutput); //Serial.println((char*)sOutput);
} }
} }
@ -133,24 +133,24 @@ RgbColor darkred(HtmlColor( 0x800000 ));
RgbColor darkgreen(HtmlColor( 0x006400 )); RgbColor darkgreen(HtmlColor( 0x006400 ));
RgbColor lightgreen(HtmlColor( 0x90ee90 )); RgbColor lightgreen(HtmlColor( 0x90ee90 ));
RgbColor temp; RgbColor temp;
RgbColor secondsColor = white; RgbColor secondsColor = black;
RgbColor minuteColor = darkred; RgbColor minuteColor = darkred;
RgbColor hourColor = gold; RgbColor hourColor = gold;
RgbColor highnoonColor = white12; RgbColor highnoonColor = white12;
RgbColor backlightColor = white; RgbColor backlightColor = white;
RgbColor hourMarkingColor = whiter; RgbColor hourMarkingColor = whiter;
void transformtoHtmlColor (char* sOutput, RgbColor inputColor) { void transformtoHtmlColor (char* sOutput, RgbColor* inputColor) {
HtmlColor(inputColor).ToNumericalString(sOutput, sizeof(sOutput) - 1); HtmlColor(RgbColor(inputColor->R, inputColor->G, inputColor->B)).ToNumericalString(sOutput, 12);
} }
void transformHtmltoStrip(RgbColor outputColor, char* sInput) { void transformHtmltoStrip(RgbColor* outputColor, char* sInput) {
HtmlColor htmlTemp; HtmlColor htmlTemp;
//Serial.print("HtmltoStrip "); //Serial.print("HtmltoStrip ");
htmlTemp.Parse<HtmlColorNames>( sInput );
//Serial.println((char*)sInput); //Serial.println((char*)sInput);
htmlTemp.Parse<HtmlColorNames>( sInput );
RgbColor stripColor( htmlTemp ); RgbColor stripColor( htmlTemp );
//Serial.printf("StripColor: R:%i G:%i B:%i\n", stripColor.R, stripColor.G, stripColor.B); //Serial.printf("StripColor: R:%i G:%i B:%i W:%i\n", stripColor.R, stripColor.G, stripColor.B, stripColor.W);
memcpy(outputColor, &stripColor, sizeof(stripColor)); memcpy(outputColor, &stripColor, sizeof(stripColor));
} }
@ -164,6 +164,7 @@ struct tm timeinfo;
volatile int currentSec = 59; volatile int currentSec = 59;
volatile int currentMin = 1; volatile int currentMin = 1;
volatile int currentHour = 2; volatile int currentHour = 2;
volatile bool NTPreachable = false;
#ifdef LDR_PIN #ifdef LDR_PIN
// variable for storing the potentiometer value // variable for storing the potentiometer value
@ -179,7 +180,7 @@ const char wifiInitialApPassword[] = "12345678";
// -- Maximal length the input-range attributes can have. // -- Maximal length the input-range attributes can have.
#define COLOR_ATTR_LENGTH 60 #define COLOR_ATTR_LENGTH 60
// -- Configuration specific key. The value should be modified if config structure was changed. // -- Configuration specific key. The value should be modified if config structure was changed.
#define CONFIG_VERSION "V1.1.3" #define CONFIG_VERSION "V1.1.4"
const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\
function colorCh(id)\n\ function colorCh(id)\n\
@ -294,8 +295,8 @@ IotWebConfCheckboxParameter allDotsOnParam = IotWebConfCheckboxParameter("all Do
IotWebConfCheckboxParameter followingHourParam = IotWebConfCheckboxParameter("following Hour", "followingHour", followingHourParamValue, STRING_LEN, true); IotWebConfCheckboxParameter followingHourParam = IotWebConfCheckboxParameter("following Hour", "followingHour", followingHourParamValue, STRING_LEN, true);
ColorWithValueParameter hourColorParam = ColorWithValueParameter("Stundenfarbe", "hourColorParam", hourColorParamValue, COLOR_ATTR_LENGTH, "#FFD700"); ColorWithValueParameter hourColorParam = ColorWithValueParameter("Stundenfarbe", "hourColorParam", hourColorParamValue, COLOR_ATTR_LENGTH, "#FFD700");
ColorWithValueParameter minuteColorParam = ColorWithValueParameter("Minutenfarbe", "minuteColorParam", minuteColorParamValue, COLOR_ATTR_LENGTH, "#800000"); ColorWithValueParameter minuteColorParam = ColorWithValueParameter("Minutenfarbe", "minuteColorParam", minuteColorParamValue, COLOR_ATTR_LENGTH, "#800000");
ColorWithValueParameter secondsColorParam = ColorWithValueParameter("Sekundenfarbe", "secondsColorParam", secondsColorParamValue, COLOR_ATTR_LENGTH, "#ffffff"); ColorWithValueParameter secondsColorParam = ColorWithValueParameter("Sekundenfarbe", "secondsColorParam", secondsColorParamValue, COLOR_ATTR_LENGTH, "#000000");
ColorWithValueParameter highnoonColorParam = ColorWithValueParameter("12Uhr Farbe", "highnoonColorParam", highnoonColorParamValue, COLOR_ATTR_LENGTH, "#1E2823"); ColorWithValueParameter highnoonColorParam = ColorWithValueParameter("12Uhr Farbe", "highnoonColorParam", highnoonColorParamValue, COLOR_ATTR_LENGTH, "#C0C0C0");
ColorWithValueParameter backlightColorParam = ColorWithValueParameter("Hintergrundfarbe", "backlightColorParam", backlightColorParamValue, COLOR_ATTR_LENGTH, "#1E2823"); ColorWithValueParameter backlightColorParam = ColorWithValueParameter("Hintergrundfarbe", "backlightColorParam", backlightColorParamValue, COLOR_ATTR_LENGTH, "#1E2823");
ColorWithValueParameter hourMarkingColorParam = ColorWithValueParameter("Stundenmarkierung", "hourMarkingColorParam", hourMarkingColorParamValue, COLOR_ATTR_LENGTH, "#787878"); ColorWithValueParameter hourMarkingColorParam = ColorWithValueParameter("Stundenmarkierung", "hourMarkingColorParam", hourMarkingColorParamValue, COLOR_ATTR_LENGTH, "#787878");
@ -332,6 +333,7 @@ bool getLocalTime(struct tm * info, uint32_t ms)
String printLocalTime() { String printLocalTime() {
if (!getLocalTime(&timeinfo, 200)) { if (!getLocalTime(&timeinfo, 200)) {
Serial.println("Failed to obtain time"); Serial.println("Failed to obtain time");
NTPreachable = false;
return ""; return "";
} }
//Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
@ -339,6 +341,7 @@ String printLocalTime() {
char timeStringBuff[50]; //50 chars should be enough char timeStringBuff[50]; //50 chars should be enough
strftime(timeStringBuff, sizeof(timeStringBuff), "%A, %B %d %Y %H:%M:%S", &timeinfo); strftime(timeStringBuff, sizeof(timeStringBuff), "%A, %B %d %Y %H:%M:%S", &timeinfo);
//Serial.println(timeStringBuff); //Serial.println(timeStringBuff);
NTPreachable = true;
return timeStringBuff; return timeStringBuff;
} }
@ -390,7 +393,7 @@ void iotWebConfHandleRoot() {
s += sTemp; s += sTemp;
s += ";\"><td></tr>"; s += ";\"><td></tr>";
if (singleSecond) { if (singleSecond) {
s += "<tr><td>Seconds Color: </td><td style=\"border: 1px solid #000000; background-color:"; s += "<tr><td>Seconds color: </td><td style=\"border: 1px solid #000000; background-color:";
transformtoHtmlColor ((char*)&sTemp, &secondsColor); transformtoHtmlColor ((char*)&sTemp, &secondsColor);
s += sTemp; s += sTemp;
s += ";\"><td></tr>"; s += ";\"><td></tr>";
@ -482,17 +485,19 @@ void syncNTP() {
//init and get the time //init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServerParamValue); configTime(gmtOffset_sec, daylightOffset_sec, ntpServerParamValue);
Serial.println(printLocalTime()); Serial.println(printLocalTime());
//inverted logic - remaining time if (NTPreachable) {
currentSec = 60 - timeinfo.tm_sec; //inverted logic - remaining time
currentMin = 60 - timeinfo.tm_min; currentSec = 60 - timeinfo.tm_sec;
currentHour = 12 - MOD(timeinfo.tm_hour, 12); currentMin = 60 - timeinfo.tm_min;
Serial.println("NTP mapped: " + String(currentHour) + ":" + String(currentMin) + ":" + String(currentSec)); currentHour = 12 - MOD(timeinfo.tm_hour, 12);
bootAnim.disable(); Serial.println("NTP mapped: " + String(currentHour) + ":" + String(currentMin) + ":" + String(currentSec));
ledRefresh.enable(); bootAnim.disable();
clockTick.enable(); ledRefresh.enable();
clockTick.enable();
#ifdef LDR_PIN #ifdef LDR_PIN
brightness.enable(); brightness.enable();
#endif #endif
}
} }
} }
@ -514,12 +519,6 @@ void setup() {
Serial.print("MAC address: "); Serial.print("MAC address: ");
Serial.println(WiFi.macAddress()); //Get CPU clock Serial.println(WiFi.macAddress()); //Get CPU clock
Serial.println("-----------------------\nSettings\n-----------------------");
Serial.printf("Show single second: \t%s\n", singleSecond ? "yes" : "no");
Serial.printf("Lighten up all LEDs: \t%s\n", allDotsOn ? "yes" : "no");
Serial.printf("Following Hour: \t%s\n\n", followingHour ? "yes" : "no");
strip.Begin(); strip.Begin();
strip.SetBrightness( MINIMAL_BRIGHTNESS ); strip.SetBrightness( MINIMAL_BRIGHTNESS );
strip.ClearTo(white); strip.ClearTo(white);
@ -580,6 +579,9 @@ void clockTickCallback() {
if (currentSec < 0) { if (currentSec < 0) {
currentSec = 59; currentSec = 59;
currentMin--; currentMin--;
if (!NTPreachable) {
syncNTP();
}
if (currentMin < 0) { if (currentMin < 0) {
currentMin = 59; currentMin = 59;
currentHour--; currentHour--;
@ -603,6 +605,13 @@ void bootAnimCallback() {
if (currentSec < 0) { if (currentSec < 0) {
currentSec = 59; currentSec = 59;
} }
if (iotWebConf.getState() == IOTWEBCONF_STATE_ONLINE && !NTPreachable) {
strip.ClearTo(white);
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), black);
strip.SetPixelColor(MOD((currentSec - 1), NUM_LEDS), black);
strip.SetPixelColor(MOD((currentSec - 2), NUM_LEDS), black);
}
if (iotWebConf.getState() == IOTWEBCONF_STATE_CONNECTING) { if (iotWebConf.getState() == IOTWEBCONF_STATE_CONNECTING) {
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), white); strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), white);
strip.SetPixelColor(MOD((currentSec - 1), NUM_LEDS), whiter); strip.SetPixelColor(MOD((currentSec - 1), NUM_LEDS), whiter);