Added clock-halt handling and improved display.

This commit is contained in:
Dirk Jahnke 2018-11-14 11:12:36 +01:00
parent 9292826f72
commit 708aeb2e72
6 changed files with 51 additions and 17 deletions

View File

@ -13,8 +13,8 @@ The tasks of the master clock / controller is:
## Links / References
- Digitrax Loconet PE: http://www.digitrax.com/static/apps/cms/media/documents/loconet/loconetpersonaledition.pdf
-- we do not support loconet yet, but it is an option to be added later
-- see page 14 ff. about FAST Clock definitions
- we do not support loconet yet, but it is an option to be added later
- see page 14 ff. about FAST Clock definitions
- Rocrail with a description of the loconet interface (German): https://wiki.rocrail.net/doku.php?id=loconet:ln-pe-de
- List of loconet interfaces: http://loconetovertcp.sourceforge.net/Client/index.html, and here especially the fast clock: http://loconetovertcp.cvs.sourceforge.net/loconetovertcp/tcp/client/Clock/
- FREMO had some discussions about fast clocks, see the forum (available to members only)

View File

@ -128,11 +128,17 @@ void Display::addLogMessage(const char *message) {
void Display::showDashboard(void) {
static unsigned long lastDisplayUpdate_ms = 0;
static unsigned long lastBlinkChange_ms = 0;
static bool blinkOnCycle = false; // toggles the on/off blinking phase
currentScreen = DashboardScreen;
// avoid flickering of the display:
if (millis() - lastDisplayUpdate_ms < TIME_BETWEEN_DISPLAY_UPDATES_ms) return;
lastDisplayUpdate_ms = millis();
if (lastDisplayUpdate_ms - lastBlinkChange_ms > BLINK_ON_OFF_TIME_ms) {
lastBlinkChange_ms = lastDisplayUpdate_ms;
blinkOnCycle = !blinkOnCycle;
}
u8g2.clearBuffer();
u8g2.setDrawColor(1);
@ -143,26 +149,28 @@ void Display::showDashboard(void) {
u8g2.print(clockName);
// ****** speed *****
setNormalTextSize();
u8g2.setCursor(55, 2*getTextHeight()-1);
setSmallTextSize();
u8g2.setCursor(55, 2*getTextHeight());
u8g2.print(clockSpeed);
// ***** time *****
setLargeTextSize();
u8g2.setCursor(0, u8g2.getDisplayHeight()-1);
if (clockHour < 10) u8g2.print("0");
u8g2.print(clockHour);
u8g2.print(":");
if (clockMinute < 10) u8g2.print("0");
u8g2.print(clockMinute);
if (!clockHalted || blinkOnCycle) {
setLargeTextSize();
u8g2.setCursor(0, u8g2.getDisplayHeight()-1);
if (clockHour < 10) u8g2.print("0");
u8g2.print(clockHour);
u8g2.print(":");
if (clockMinute < 10) u8g2.print("0");
u8g2.print(clockMinute);
}
// ***** halt/go *****
if (clockHalted) {
setSmallTextSize();
u8g2.setDrawColor(1);
u8g2.drawBox(55, u8g2.getDisplayHeight() - 2*getTextHeight()-3, 5*4+2, getTextHeight());
u8g2.setDrawColor(0);
u8g2.setCursor(57, u8g2.getDisplayHeight() - getTextHeight()-3);
u8g2.setDrawColor(blinkOnCycle ? 1 : 0);
u8g2.drawBox(55, u8g2.getDisplayHeight() - 2*getTextHeight()-4, 4*u8g2.getMaxCharWidth()+3, getTextHeight()+1);
u8g2.setDrawColor(blinkOnCycle ? 0 : 1);
u8g2.setCursor(57, u8g2.getDisplayHeight() - getTextHeight()-4);
u8g2.print("HALT");
u8g2.setDrawColor(1);
}

View File

@ -3,6 +3,7 @@
// avoid flickering of the display:
#define TIME_BETWEEN_DISPLAY_UPDATES_ms 200
#define BLINK_ON_OFF_TIME_ms 1000
#define MAX_CLOCK_NAME_LEN 8
#define MAX_CLOCK_SPEED_LEN 8

View File

@ -53,6 +53,7 @@ void Fastclock::loop(void) {
msPerModelSecond = 500;
}
if (newTimeTick - lastTimeTickUsed < MIN_TIME_ms_BETWEEN_CLOCK_UPDATES) return;
if (halted) { lastTimeTickUsed = newTimeTick; return; }
int fastclockTimeAdvance = (newTimeTick - lastTimeTickUsed) * 1000 / msPerModelSecond;
oldMinute = minute;
@ -72,4 +73,9 @@ void Fastclock::loop(void) {
void Fastclock::begin(void) {
lastTimeTickUsed = millis();
Serial.print("*** Setting up Fastclock, init lastSentTimeTick="); Serial.println(lastTimeTickUsed);
// following setters do not change anything, but they update the display as well
setClockSpeed(msPerModelSecond);
display->setClockHalted(halted);
display->setTime(hour, minute);
}

View File

@ -4,10 +4,11 @@
#include "display.h"
#define MIN_TIME_ms_BETWEEN_CLOCK_UPDATES 200
#define DEFAULT_ms_PER_MODEL_SECOND 250
class Fastclock {
public:
Fastclock(Display *d): display(d) { weekday=0; hour=0; minute=0; second=0; millisecond=0; msPerModelSecond=500; };
Fastclock(Display *d): display(d) { weekday=0; hour=0; minute=0; second=0; millisecond=0; msPerModelSecond=DEFAULT_ms_PER_MODEL_SECOND; halted = true; };
void begin(void);
void loop(void);
void incrementClockByMilliseconds(int amount);
@ -16,6 +17,7 @@ public:
void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds) { hour = hours; minute = minutes; second = seconds; millisecond = 0; };
void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t milliseconds) { hour = hours; minute = minutes; second = seconds; millisecond = milliseconds; };
void setWeekday(uint8_t _weekday) { weekday = _weekday; };
void setClockHalted(bool setToHalt) { halted = setToHalt; display->setClockHalted(halted); };
private:
Display *display;
unsigned long lastTimeTickUsed; // used to calculate model time
@ -25,6 +27,7 @@ private:
uint8_t minute;
uint8_t second;
uint16_t millisecond;
bool halted;
};

View File

@ -15,6 +15,8 @@
#include "display.h"
#include "fastclock.h"
#define AUTOSTART_CLOCK_AFTER_ms 10000
//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char mqtt_server[40] = "";
@ -229,6 +231,20 @@ void loop(void)
return;
}
#if defined(AUTOSTART_CLOCK_AFTER_ms)
#if AUTOSTART_CLOCK_AFTER_ms > 0
static unsigned long autostart_ms = 0;
static bool autostartDone = false;
if (autostart_ms == 0) {
autostart_ms = millis() + AUTOSTART_CLOCK_AFTER_ms;
} else if (!autostartDone && millis() > autostart_ms) {
autostartDone = true;
fastclock.setClockHalted(false);
Serial.println("Clock started automatically");
}
#endif
#endif
fastclock.loop();
display.showDashboard();