Clock display improved / cleaned up.

This commit is contained in:
Dirk Jahnke 2019-01-25 20:23:10 +01:00
parent 93a34e2918
commit 738ef9e512
1 changed files with 56 additions and 6 deletions

View File

@ -12,6 +12,8 @@
#define DISPLAY_CS_PIN D6 #define DISPLAY_CS_PIN D6
#define VERTICAL_BAR_STARTS_TOP false #define VERTICAL_BAR_STARTS_TOP false
#define DEBUG_RELAYS false #define DEBUG_RELAYS false
#define DEBUG_DISPLAY false
#define DEBUG_LVL 0
#include <Arduino.h> #include <Arduino.h>
#include <IOTAppStory.h> #include <IOTAppStory.h>
@ -58,7 +60,7 @@ WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
// Field default values // Field default values
char *clockName = "FastClk "; char *clockName = "FREMO";
char *clockSpeed_modelMsPerRealSec_String = "250"; char *clockSpeed_modelMsPerRealSec_String = "250";
int clockSpeed_modelMsPerRealSec = 250; int clockSpeed_modelMsPerRealSec = 250;
char *relay1Pin_String = "D1"; char *relay1Pin_String = "D1";
@ -68,7 +70,14 @@ char *relayHoldTime_ms_String = "200";
int relayHoldTime_ms = 200; int relayHoldTime_ms = 200;
char *relayMinOffTime_ms_String = "100"; char *relayMinOffTime_ms_String = "100";
int relayMinOffTime_ms = 100; int relayMinOffTime_ms = 100;
int displayRefresh_ms = 200;
// Clock Display Config Parameter
static char * displayClockNameEvery_ms_String = "16000";
static char * displayClockNameDuration_ms_String = "1200";
static uint32_t displayClockNameEvery_ms = 16000;
static uint32_t displayClockNameDuration_ms = 1200;
static uint32_t doNotShowClockNameBeforeAndAfterMinuteChange_s = 2;
void setupIAS(void) { void setupIAS(void) {
#if defined ESP8266 #if defined ESP8266
@ -87,6 +96,8 @@ void setupIAS(void) {
// define fields // define fields
IAS.addField(clockName, "Clock Name", 8, 'T'); IAS.addField(clockName, "Clock Name", 8, 'T');
IAS.addField(clockSpeed_modelMsPerRealSec_String, "Model MilliSec per Real Sec", 8, 'N'); IAS.addField(clockSpeed_modelMsPerRealSec_String, "Model MilliSec per Real Sec", 8, 'N');
IAS.addField(displayClockNameEvery_ms_String, "Display clock name every (ms)", 5, 'N');
IAS.addField(displayClockNameDuration_ms_String, "Display clock name duration (ms)", 5, 'N');
IAS.addField(relay1Pin_String, "Pin Relay 1", 2, 'P'); IAS.addField(relay1Pin_String, "Pin Relay 1", 2, 'P');
IAS.addField(relay2Pin_String, "Pin Relay 2", 2, 'P'); IAS.addField(relay2Pin_String, "Pin Relay 2", 2, 'P');
IAS.addField(relayHoldTime_ms_String, "Relay hold time (ms)", 3, 'N'); IAS.addField(relayHoldTime_ms_String, "Relay hold time (ms)", 3, 'N');
@ -148,6 +159,8 @@ void setupIAS(void) {
relay2Pin = IAS.dPinConv(relay2Pin_String); relay2Pin = IAS.dPinConv(relay2Pin_String);
relayHoldTime_ms = atoi(relayHoldTime_ms_String); relayHoldTime_ms = atoi(relayHoldTime_ms_String);
relayMinOffTime_ms = atoi(relayMinOffTime_ms_String); relayMinOffTime_ms = atoi(relayMinOffTime_ms_String);
displayClockNameEvery_ms = atoi(displayClockNameEvery_ms_String);
displayClockNameDuration_ms = atoi(displayClockNameDuration_ms_String);
Serial.println(F("Configuration used:")); Serial.println(F("Configuration used:"));
Serial.print(F("Relay1 Pin: ")); Serial.println(relay1Pin); Serial.print(F("Relay1 Pin: ")); Serial.println(relay1Pin);
@ -155,6 +168,9 @@ void setupIAS(void) {
Serial.print(F("Clock speed: ")); Serial.print(clockSpeed_modelMsPerRealSec); Serial.println(F(" model ms per real sec")); Serial.print(F("Clock speed: ")); Serial.print(clockSpeed_modelMsPerRealSec); Serial.println(F(" model ms per real sec"));
Serial.print(F("Relay hold time (ms): ")); Serial.println(relayHoldTime_ms); Serial.print(F("Relay hold time (ms): ")); Serial.println(relayHoldTime_ms);
Serial.print(F("Relay min off time (ms): ")); Serial.println(relayMinOffTime_ms); Serial.print(F("Relay min off time (ms): ")); Serial.println(relayMinOffTime_ms);
Serial.print(F("Clock speed (model ms per real time s): ")); Serial.println(clockSpeed_modelMsPerRealSec);
Serial.print(F("Show clock name every (ms): ")); Serial.println(displayClockNameEvery_ms);
Serial.print(F("Show clock name for (ms): ")); Serial.println(displayClockNameDuration_ms);
} }
void setupRelays(int relay1Pin, int relay2Pin) { void setupRelays(int relay1Pin, int relay2Pin) {
@ -191,14 +207,18 @@ void setupDisplay() {
1, 0xff, /* vertical bar completely set */ 1, 0xff, /* vertical bar completely set */
}; // columns from right to left, each byte is a single column }; // columns from right to left, each byte is a single column
#endif #endif
static uint8_t newZero[] = {0x05, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00};
P.begin(); P.begin();
// P.setZoneEffect(0, true, PA_FLIP_LR); // P.setZoneEffect(0, true, PA_FLIP_LR);
P.setIntensity(1); P.setIntensity(1);
for (charCode=1; charCode<=8; ++charCode) { for (charCode=1; charCode<=9; ++charCode) {
P.addChar(charCode, verticalBarFont+2*(charCode-1)); P.addChar(charCode, verticalBarFont+2*(charCode-1));
} }
char intro[] = {':', '-', ')', ' ', 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00}; char intro[] = {':', '-', ')', ' ', 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00};
// replace the 0 characters, we do not like the "slash"
P.addChar('0', newZero);
P.print(intro); P.print(intro);
} }
void setup(void) void setup(void)
@ -299,8 +319,9 @@ void loop(void)
minutes = (millis() / 60 * 1000) % 60; minutes = (millis() / 60 * 1000) % 60;
seconds = (millis() / 1000) % 60; seconds = (millis() / 1000) % 60;
} }
minuteProgressIndicator = seconds/7.5 + 1; // char code 1-8 show vertical bar minuteProgressIndicator = seconds/6.7 + 1; // char code 1-8 show vertical bar
snprintf(timeBuffer, 10, "%c %02d:%02d", minuteProgressIndicator, hours, minutes); if (minuteProgressIndicator > 9) minuteProgressIndicator = 9;
snprintf(timeBuffer, 10, "%c %2d:%02d", minuteProgressIndicator, hours, minutes);
/* DEBUG */ /* DEBUG */
#if DEBUG_RELAYS #if DEBUG_RELAYS
@ -327,6 +348,7 @@ void loop(void)
currentDisplayState = seconds / 5; // Value 0..11 currentDisplayState = seconds / 5; // Value 0..11
#if DEBUG_DISPLAY
static bool executed = false; static bool executed = false;
if (recentDisplayState != currentDisplayState) executed = false; if (recentDisplayState != currentDisplayState) executed = false;
@ -352,15 +374,43 @@ void loop(void)
break; break;
case 7: ExecOnce(P.print(timeBuffer)); break; case 7: ExecOnce(P.print(timeBuffer)); break;
case 8: case 8:
/*snprintf(debugMsg, MsgSize, "t%cr%c", timeClientInitialized ? 'x':'-', (relaysState == RELAY_STATE_OFF)?'-':(relaysState == RELAY_STATE_ON_EVEN_MINUTE?'e':'o')); snprintf(debugMsg, MsgSize, "t%cr%c", timeClientInitialized ? 'x':'-', (relaysState == RELAY_STATE_OFF)?'-':(relaysState == RELAY_STATE_ON_EVEN_MINUTE?'e':'o'));
ExecOnce(P.print(debugMsg)); ExecOnce(P.print(debugMsg));
break;*/ break;
case 9: ExecOnce(P.print(timeBuffer)); break; case 9: ExecOnce(P.print(timeBuffer)); break;
case 10: if (lastSeconds != seconds) P.printf("%c %d", minuteProgressIndicator, seconds); break; case 10: if (lastSeconds != seconds) P.printf("%c %d", minuteProgressIndicator, seconds); break;
case 11: ExecOnce(P.print(timeBuffer)); break; case 11: ExecOnce(P.print(timeBuffer)); break;
default: ExecOnce(P.print("default")); break; default: ExecOnce(P.print("default")); break;
} }
recentDisplayState = currentDisplayState; recentDisplayState = currentDisplayState;
#else
// standard procedure to display
static uint32_t last_clock_refresh = 0;
static uint32_t lastTimeClockNameShown = 0;
static boolean showingClockName = false;
if (showingClockName) {
if (millis() - lastTimeClockNameShown > displayClockNameDuration_ms) {
// stop showingClockName
showingClockName = false;
}
} else {
if ((millis() - lastTimeClockNameShown > displayClockNameEvery_ms)
&& (seconds < 60-doNotShowClockNameBeforeAndAfterMinuteChange_s)
&& (seconds > doNotShowClockNameBeforeAndAfterMinuteChange_s)) {
P.print(clockName);
lastTimeClockNameShown = millis();
showingClockName = true;
} else {
// showing clock
if (millis() - last_clock_refresh > displayRefresh_ms) {
P.print(timeBuffer);
last_clock_refresh = millis();
}
}
}
#endif
// toggle relays // toggle relays
if (lastMinutes != minutes) { if (lastMinutes != minutes) {