muwerk mupplet Display Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::GfxPanel Class Reference

gfx_panel mupplet for oled and tft panels to display sensor values More...

#include <mup_gfx_panel.h>

Public Member Functions

 GfxPanel (String name, GfxDrivers::DisplayType displayType, uint16_t resX, uint16_t resY, uint8_t i2cAddress, TwoWire *pWire=&Wire, String locale="C")
 
 GfxPanel (String name, GfxDrivers::DisplayType displayType, uint16_t resX, uint16_t resY, uint8_t csPin, uint8_t dcPin, uint8_t rstPin=-1, String locale="C")
 
void setSlotCaption (uint16_t slot, String caption)
 
void publishSlotCaption (uint16_t slot)
 
void setSlotText (uint16_t slot, String text)
 
void publishSlotText (uint16_t slot)
 
void setSlotTopic (uint16_t slot, String topic)
 
void publishSlotTopic (uint16_t slot)
 
void setSlotFormat (uint16_t slot, String format)
 
void publishSlotFormat (uint16_t slot)
 
void setSlotHistorySampleRateMs (uint16_t slot, uint32_t rate)
 
void publishSlotHistorySampleRateMs (uint16_t slot)
 
void begin (ustd::Scheduler *_pSched, bool _useCanvas=false)
 
void begin (ustd::Scheduler *_pSched, String combined_layout, ustd::array< String > _topics, ustd::array< String > _captions, bool _useCanvas=false)
 
void begin (ustd::Scheduler *_pSched, String combined_layout, uint16_t _slots, const char *_topics[], const char *_captions[], bool _useCanvas=false)
 

Detailed Description

gfx_panel mupplet for oled and tft panels to display sensor values

The mup_gfx_panel mupplet supports SSD1306 oled and ST7735 tft style displays.

Hardware: ST7735 tft display.

Hardware: SSD1306 oled display.

Messages sent by gamma_gdk101 mupplet:

messages are prefixed by omu/<hostname>:

topic message body comment
<mupplet-name>/display/slot/<slot_index>/caption caption text caption text for slot_index
<mupplet-name>/display/slot/<slot_index>/topic topic subscription topic for slot_index
<mupplet-name>/display/slot/<slot_index>/text main slot text text for slot_index
<mupplet-name>/display/slot/<slot_index>/format format specifier slot format specifier for slot_index

Messages received by gfx_panel mupplet:

Need to be prefixed by <hostname>/:

topic message body comment
<mupplet-name>/display/slot/<slot_index>/caption/set <new-caption-text> Causes caption text of slot 0..<slots be set to <new-caption-text>.
<mupplet-name>/display/slot/<slot_index>/caption/get Returns the caption text of slot 0..<slots.
<mupplet-name>/display/slot/<slot_index>/text/set <new-slot-text> String. Causes slot text of slot 0..<slots be set to <new-slot-text>.
<mupplet-name>/display/slot/<slot_index>/text/get Returns the slot text of slot 0..<slots.
<mupplet-name>/display/slot/<slot_index>/topic/set <new-subs-topic> String. Causes new subscription of <new-subs-topic> for slot 0..<slots.
<mupplet-name>/display/slot/<slot_index>/topic/get Returns the subscription topic of slot 0..<slots.
<mupplet-name>/display/slot/<slot_index>/format/set <format-spec> String. Sets <format-spec> for slot 0..<slots.
<mupplet-name>/display/slot/<slot_index>/format/get Returns the format-spec of slot 0..<slots.

Sample code

#include "ustd_platform.h"
#include "scheduler.h"
#include "net.h"
#include "mqtt.h"
#include "ota.h"
#include "jsonfile.h"
#include "mup_gfx_panelxx.h"
void appLoop();
ustd::Scheduler sched(10, 16, 32);
ustd::Net net(LED_BUILTIN);
ustd::Mqtt mqtt;
ustd::Ota ota;
// requires a display config file "display1.json"
ustd::GfxPanel displayTft("display1", ustd::GfxDrivers::DisplayType::ST7735, 128, 128, D4, D3, (uint8_t)-1, "DE");
// requires a display config file "display2.json"
ustd::GfxPanel displayOled("display2", ustd::GfxDrivers::DisplayType::SSD1306, 128,64, 0x3c, &Wire, "DE");
void setup() {
con.begin(&sched);
net.begin(&sched);
mqtt.begin(&sched);
ota.begin(&sched);
displayTft.begin(&sched,&mqtt);
displayOled.begin(&sched,&mqtt);
sched.add(appLoop, "main", 1000000);
}
void appLoop() {
}
// Never add code to this loop, use appLoop() instead.
void loop() {
sched.loop();
}
gfx_panel mupplet for oled and tft panels to display sensor values
Definition: mup_gfx_panel.h:463

The data area of the ESP32 or ESP8266 must contain a json file with the name of SensorDisplay Object given as first parameter to the object instantiation, "display1" or "display2" in the example above. The file display1,2.json should contain:

{
"layout": "S|ff",
"topics": ["clock/timeinfo", "!hastates/sensor/temperature/state", "!hastates/sensor/netatmo_temperature2/state"],
"captions": ["Time", "Out C", "Studio C"],
}

layout contains a string defining 1-n lines separated by |, marking display-slots by S for string (message as-is), or I (int),P(val * 100 as %),F (one decimal float),D (two decimals),T (three decimals) for numbers, G for graphical plot. Uppercase letters generate a 64x32 slot, lowercase letters generate a 32x32 slot. topics gives a list of MQTT topics that are going to be displayed. A layout S|ff|G has four display slots (line 1: large string, line 2: two small numbers), line 3: large plot and requires 4 topics and 4 captions. A topic starting with '!' creates an external MQTT subscription (which allows displaying values from external devices), while topics without starting '!' subscribe to device-local messages only via muwerk's scheduler. A special topic clock/timeinfo is provided by this mupplet and displays day of week and time. captions are the small-print titles for each display slot. Default is bold font. '_' switches between bold and normal font.

Constructor & Destructor Documentation

◆ GfxPanel() [1/2]

ustd::GfxPanel::GfxPanel ( String  name,
GfxDrivers::DisplayType  displayType,
uint16_t  resX,
uint16_t  resY,
uint8_t  i2cAddress,
TwoWire *  pWire = &Wire,
String  locale = "C" 
)
inline
Parameters
nameThe display's name. A file name.json must exist in the format above to define the display slots and corresponding MQTT messages.
displayTypeA GfxDrivers::DisplayType, e.g. GfxDrivers::DisplayType::SSD1306, GfxDrivers::DisplayType::ST7735.
resXHorizontal resolution.
resYVertical resolution.
i2cAddressI2C address of display
pWirePointer to a TwoWire I2C structure, default is &Wire.
localeLocale for date strings, current 'C' (default) or 'DE'.

◆ GfxPanel() [2/2]

ustd::GfxPanel::GfxPanel ( String  name,
GfxDrivers::DisplayType  displayType,
uint16_t  resX,
uint16_t  resY,
uint8_t  csPin,
uint8_t  dcPin,
uint8_t  rstPin = -1,
String  locale = "C" 
)
inline
Parameters
nameThe display's name. A file name.json must exist in the format above to define the display slots and corresponding MQTT messages.
displayTypeA DisplayDriver DisplayType, e.g. GfxDrivers::DisplayType::SSD1306, GfxDrivers::DisplayType::ST7735.
resXHorizontal resolution.
resYVertical resolution.
csPinCS Pin for SPI.
dcPinDC Pin for SPI.
rstPinRST Pin for SPI. (default unused, -1)
localeLocale for date strings, current 'C' (default) or 'DE'.

Member Function Documentation

◆ begin() [1/3]

void ustd::GfxPanel::begin ( ustd::Scheduler *  _pSched,
bool  _useCanvas = false 
)
inline

Activate display and begin receiving updates for the display slots

Parameters
_pSchedPointer to the muwerk scheduler
_useCanvasUse the canvas for the display. Note: requires considerable memory for color displays!

◆ begin() [2/3]

void ustd::GfxPanel::begin ( ustd::Scheduler *  _pSched,
String  combined_layout,
uint16_t  _slots,
const char *  _topics[],
const char *  _captions[],
bool  _useCanvas = false 
)
inline

Activate display and begin receiving updates for the display slots

Parameters
_pSchedPointer to the muwerk scheduler
combined_layoutThe layout string, e.g. "ff|ff" (two lines, two short floats each).
_slotsNumber of slots to use, must be array dimension of both _captions and topics.
_topicsconst char *[] of topics to subscribe to. The number of topics must match the number of captions and the number of slot-qualifiers in the combined_layout string.
_captionsconst char *[] of captions to display for the topics. The number of captions must match the number of topics and the number of slot-qualifiers in the combined_layout string.
_useCanvasUse the canvas for the display. Note: requires considerable memory for color displays!

◆ begin() [3/3]

void ustd::GfxPanel::begin ( ustd::Scheduler *  _pSched,
String  combined_layout,
ustd::array< String >  _topics,
ustd::array< String >  _captions,
bool  _useCanvas = false 
)
inline

Activate display and begin receiving updates for the display slots

Parameters
_pSchedPointer to the muwerk scheduler
combined_layoutThe layout string, e.g. "ff|ff" (two lines, two short floats each).
_topicsstd::array<String> of topics to subscribe to. The number of topics must match the number of captions and the number of slot-qualifiers in the combined_layout string.
_captionsstd::array<String> of captions to display for the topics. The number of captions must match the number of topics and the number of slot-qualifiers in the combined_layout string.
_useCanvasUse the canvas for the display. Note: requires considerable memory for color displays!

◆ publishSlotCaption()

void ustd::GfxPanel::publishSlotCaption ( uint16_t  slot)
inline

Publish the caption for a slot.

Parameters
slotThe slot number, 0..<slots.

◆ publishSlotFormat()

void ustd::GfxPanel::publishSlotFormat ( uint16_t  slot)
inline

Publish the format for a slot.

Parameters
slotThe slot number, 0..<slots.

◆ publishSlotHistorySampleRateMs()

void ustd::GfxPanel::publishSlotHistorySampleRateMs ( uint16_t  slot)
inline

Publish the history sample rate for a slot.

Parameters
slotThe slot number, 0..<slots.

◆ publishSlotText()

void ustd::GfxPanel::publishSlotText ( uint16_t  slot)
inline

Publish the text for a slot.

Parameters
slotThe slot number, 0..<slots.

◆ publishSlotTopic()

void ustd::GfxPanel::publishSlotTopic ( uint16_t  slot)
inline

Publish the topic for a slot.

Parameters
slotThe slot number, 0..<slots.

◆ setSlotCaption()

void ustd::GfxPanel::setSlotCaption ( uint16_t  slot,
String  caption 
)
inline

Set the caption for a slot.

Parameters
slotThe slot number.
captionThe caption.

◆ setSlotFormat()

void ustd::GfxPanel::setSlotFormat ( uint16_t  slot,
String  format 
)
inline

Set the format for a slot.

Parameters
slotThe slot number.
formatThe format.

◆ setSlotHistorySampleRateMs()

void ustd::GfxPanel::setSlotHistorySampleRateMs ( uint16_t  slot,
uint32_t  rate 
)
inline

Set the history sample rate for a slot.

Parameters
slotThe slot number.
rateThe sample rate in milliseconds.

◆ setSlotText()

void ustd::GfxPanel::setSlotText ( uint16_t  slot,
String  text 
)
inline

Set the text for a slot.

Parameters
slotThe slot number.
textThe text.

◆ setSlotTopic()

void ustd::GfxPanel::setSlotTopic ( uint16_t  slot,
String  topic 
)
inline

Set the topic for a slot.

Parameters
slotThe slot number.
topicThe topic.

The documentation for this class was generated from the following file: