Public Access
Add four animated KonoSuba ESPHome pages
Megumin's daily explosion, the Adventurers' Guild quest board (agenda, weather, solar), Megumin's adventurer card and a party battle against a giant toad with a live-data battle log. Original 1-bit pixel art lives in tools/konosuba_sprites.py, which generates konosuba_sprites.h and can render a preview PNG. Home data and drawing helpers shared by the themed pages move to el512_pages.h; the display gains dither_mask() for a dissolve-in intro. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50ee17b3f6
commit
e9b91c5628
11 files changed
+1655
-61
No files matched your search
@@ -0,0 +1,72 @@
|
||||
// Shared pieces for the themed ESPHome pages (cyberpunk.cpp, konosuba.cpp): the
|
||||
// Home Assistant values they show, and small drawing helpers.
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#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
|
||||
Reference in new issue
Block a user