6#include "helper/light_controller.h"
7#include "helper/mup_gfx_display.h"
8#include "hardware/max72xx_matrix.h"
43 static const char *version;
50 LightController light;
69 display(csPin, hDisplays, vDisplays, rotation) {
77 void begin(Scheduler *_pSched,
bool initialState =
false) {
79 tID = pSched->add([
this]() { this->loop(); }, name, 10000L);
81 pSched->subscribe(tID, name +
"/display/#", [
this](String topic, String msg, String orig) {
82 this->commandParser(topic.substring(name.length() + 9), msg, name +
"/display");
84 pSched->subscribe(tID, name +
"/light/#", [
this](String topic, String msg, String orig) {
85 this->light.commandParser(topic.substring(name.length() + 7), msg);
90#ifdef USTD_FEATURE_PROGRAMPLAYER
95 display.setTextWrap(
false);
98 light.
begin([
this](
bool state,
double level,
bool control,
99 bool notify) { this->onLightControl(state, level, control, notify); },
106#ifdef USTD_FEATURE_PROGRAMPLAYER
111 void onLightControl(
bool state,
double level,
bool control,
bool notify) {
112 uint8_t intensity = (level * 15000) / 1000;
120 pSched->publish(name +
"/light/unitbrightness", String(level, 3));
121 pSched->publish(name +
"/light/state", state ?
"on" :
"off");
126 virtual void getDimensions(int16_t &width, int16_t &height) {
127 width = display.width();
128 height = display.height();
131 virtual bool getTextWrap() {
135 virtual void setTextWrap(
bool wrap) {
136 display.setTextWrap(wrap);
139 virtual void setTextFont(uint8_t font, int16_t baseLineAdjustment) {
140 display.setFont(fonts[font]);
141 if (baseLineAdjustment) {
143 display.setCursor(display.
getCursorX(), y + baseLineAdjustment);
147 virtual void setTextColor(uint16_t fg, uint16_t bg) {
148 display.setTextColor(fg, bg);
151 virtual void getCursor(int16_t &x, int16_t &y) {
156 virtual void setCursor(int16_t x, int16_t y) {
157 display.setCursor(x, y);
160 virtual void displayClear(int16_t x, int16_t y, int16_t w, int16_t h) {
161 display.fillRect(x, y, w, h, 0);
165 virtual void displayClear(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t bg) {
166 display.fillRect(x, y, w, h, bg);
170 virtual void displayPrint(String content,
bool ln =
false) {
172 display.println(content);
174 display.print(content);
179 virtual bool displayFormat(int16_t x, int16_t y, int16_t w, int16_t align, String content,
180 uint8_t font, uint16_t color, uint16_t bg) {
181 display.setFont(fonts[font]);
182 display.setTextColor(color, bg);
183 bool ret = display.
printFormatted(x, y, w, align, content, sizes[font].baseLine,
184 sizes[font].yAdvance);
186 display.setTextColor(current_fg, current_bg);
187 display.setFont(fonts[current_font]);
192 void getTextDimensions(uint8_t font,
const char *content, int16_t &width, int16_t &height) {
193 if (!content || !*content) {
200 uint8_t old_font = current_font;
202 display.setFont(fonts[font]);
203 display.setTextWrap(
false);
204 display.getTextBounds(content, 0, sizes[font].baseLine, &x, &y, &w, &h);
205 display.setTextWrap(old_wrap);
206 display.setFont(fonts[old_font]);
212const char *DisplayMatrixMAX72XX::version =
"0.1.0";
mupplet-display MAX7219/MAX7221 Led Matrix Display class
Definition: display_matrix_max72xx.h:41
DisplayMatrixMAX72XX(String name, uint8_t csPin, uint8_t hDisplays=1, uint8_t vDisplays=1, uint8_t rotation=0)
Definition: display_matrix_max72xx.h:66
void begin(Scheduler *_pSched, bool initialState=false)
Definition: display_matrix_max72xx.h:77
The MAX72XX Matrix Display Class.
Definition: max72xx_matrix.h:19
void setIntensity(uint8_t intensity)
Definition: max72xx_matrix.h:90
void begin()
Definition: max72xx_matrix.h:65
void write()
Definition: max72xx_matrix.h:108
bool getTextWrap() const
Definition: max72xx_matrix.h:153
int16_t getCursorY() const
Definition: max72xx_matrix.h:167
int16_t getCursorX() const
Definition: max72xx_matrix.h:160
void setPowerSave(bool powersave)
Definition: max72xx_matrix.h:83
bool printFormatted(int16_t x, int16_t y, int16_t w, int16_t align, String content, uint8_t baseLine, uint8_t yAdvance=0)
Definition: max72xx_matrix.h:206
The base class for all matrix display mupplets.
Definition: mup_gfx_display.h:14
The muwerk namespace.
Definition: display_digits_max72xx.h:10