2026-10-15 19:43:59 +02:00
|
|
|
#include "display/page_resources.h"
|
|
|
|
|
|
2026-10-15 21:01:14 +02:00
|
|
|
#include <Arduino.h>
|
2026-10-20 22:22:32 +02:00
|
|
|
#include <sys/time.h>
|
2026-10-15 21:01:14 +02:00
|
|
|
|
2026-10-15 19:43:59 +02:00
|
|
|
#include "display/bitmap_store.h"
|
|
|
|
|
#include "display/font_store.h"
|
2026-10-16 22:03:18 +02:00
|
|
|
#include "display/icon_store.h"
|
2026-10-20 17:52:25 +02:00
|
|
|
#include "display/life_player.h"
|
2026-10-15 19:43:59 +02:00
|
|
|
#include "net/ha_api.h"
|
|
|
|
|
|
2026-10-15 21:01:14 +02:00
|
|
|
Stopwatch stopwatch;
|
|
|
|
|
StoredPageResources pageResources(stopwatch);
|
2026-10-15 19:43:59 +02:00
|
|
|
|
|
|
|
|
bool StoredPageResources::background(const char *name, uint8_t *bitmap)
|
|
|
|
|
{
|
2026-10-16 22:03:18 +02:00
|
|
|
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;
|
2026-10-15 19:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Font StoredPageResources::font(const char *name)
|
|
|
|
|
{
|
|
|
|
|
return findFont(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *StoredPageResources::haValue(const PageElement &element)
|
|
|
|
|
{
|
|
|
|
|
return haApiValue(element.entity, element.attribute);
|
|
|
|
|
}
|
2026-10-15 21:01:14 +02:00
|
|
|
|
2026-10-20 22:22:32 +02:00
|
|
|
uint64_t StoredPageResources::stopwatchMs()
|
2026-10-15 21:01:14 +02:00
|
|
|
{
|
2026-10-20 22:22:32 +02:00
|
|
|
return _stopwatch.elapsed(epochMs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t epochMs()
|
|
|
|
|
{
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
gettimeofday(&tv, nullptr);
|
|
|
|
|
return (int64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
2026-10-15 21:01:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StoredPageResources::stopwatchRunning()
|
|
|
|
|
{
|
|
|
|
|
return _stopwatch.running();
|
|
|
|
|
}
|
2026-10-20 17:52:25 +02:00
|
|
|
|
|
|
|
|
const LifeRunner *StoredPageResources::life(const PageElement &element)
|
|
|
|
|
{
|
|
|
|
|
return lifePlayer.runner(element);
|
|
|
|
|
}
|