// Shared pieces for the themed ESPHome pages (cyberpunk.cpp, konosuba.cpp): the // Home Assistant values they show, and small drawing helpers. #pragma once #include #include #include #include #include #include #include "esphome/components/display/display.h" namespace esphome::el512 { struct Reading { std::string name; float value{NAN}; }; // Home Assistant values shown on the pages; NAN or "" when unknown. Filled // from YAML (see the cp_home global in el512-panel.yaml). struct HomeData { std::string weather; // condition, e.g. "partlycloudy" float temp{NAN}; // °C float humidity{NAN}; // % float wind{NAN}; // km/h float solar{NAN}; // W float solar_today{NAN}; // Wh produced today float house{NAN}; // W float grid{NAN}; // W, > 0 = import std::string agenda; // sensor.el512_agenda events: "day|time|title;..." Reading rooms[4]; }; namespace fx { // Integer hash for repeatable pseudo-random effects (lowbias32). inline uint32_t hash(uint32_t x) { x ^= x >> 16; x *= 0x7feb352d; x ^= x >> 15; x *= 0x846ca68b; x ^= x >> 16; return x; } inline uint32_t hash(uint32_t a, uint32_t b) { return hash(a * 0x9e3779b9u ^ hash(b)); } inline std::string str(const char *fmt, ...) __attribute__((format(printf, 1, 2))); inline std::string str(const char *fmt, ...) { char buf[128]; va_list args; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); return buf; } inline std::string upper(std::string s) { for (auto &c : s) c = (char) toupper((unsigned char) c); return s; } inline int text_width(display::Display &it, display::BaseFont *font, const char *text) { int x, y, w, h; it.get_text_bounds(0, 0, text, font, display::TextAlign::TOP_LEFT, &x, &y, &w, &h); return w; } } // namespace fx } // namespace esphome::el512