Files
Flipdot-display/src/esp32/display/page_resources.cpp
T
mangavalkandClaude Opus 5.5 0166d0ee46 Stopwatch counts in real time from a start date, kept over a restart
The stopwatch counted with millis(), so it started at 0 after every
restart and would overflow after 49 days. It now keeps the real start
time (UTC ms) and the time counted before a pause, stored in NVS
(system/stopwatch_store) on every change, so it keeps counting while
the display is off or restarting. Stop pauses, Start continues, and the
Stopwatch tab can set the start to a date and time (local, summer time
by mktime) to count from, e.g. days since an event. Start, stop and set
need the synced time.

New page formats: 12d 4:05:09 and 3w 2d.

Version 2.19.0, tested on the display over OTA (set start, future and
invalid dates refused, pause, restart).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 22:22:32 +02:00

57 lines
1.2 KiB
C++

#include "display/page_resources.h"
#include <Arduino.h>
#include <sys/time.h>
#include "display/bitmap_store.h"
#include "display/font_store.h"
#include "display/icon_store.h"
#include "display/life_player.h"
#include "net/ha_api.h"
Stopwatch stopwatch;
StoredPageResources pageResources(stopwatch);
bool StoredPageResources::background(const char *name, uint8_t *bitmap)
{
if (loadBitmap(name, bitmap))
return true;
Icon icon;
if (!loadIcon(name, icon))
return false;
iconToBitmap(icon, bitmap); // at the top left: images are drawn from their x, y
return true;
}
Font StoredPageResources::font(const char *name)
{
return findFont(name);
}
const char *StoredPageResources::haValue(const PageElement &element)
{
return haApiValue(element.entity, element.attribute);
}
uint64_t StoredPageResources::stopwatchMs()
{
return _stopwatch.elapsed(epochMs());
}
int64_t epochMs()
{
struct timeval tv;
gettimeofday(&tv, nullptr);
return (int64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
bool StoredPageResources::stopwatchRunning()
{
return _stopwatch.running();
}
const LifeRunner *StoredPageResources::life(const PageElement &element)
{
return lifePlayer.runner(element);
}