Skip to content

Commit e8fbd87

Browse files
committed
Checkin Display Write handler code
1 parent 12d2354 commit e8fbd87

File tree

26 files changed

+79
-38
lines changed

26 files changed

+79
-38
lines changed

src/Wippersnapper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ bool Wippersnapper::generateWSTopics() {
24242424

24252425
// /display topic //
24262426

2427-
// Pre-determine topic size
2427+
// Pre-determine topic size
24282428
topicLen = strlen(WS._config.aio_user) + strlen("/") + strlen(_device_uid) +
24292429
strlen("/wprsnpr/") + strlen(TOPIC_SIGNALS) + strlen("broker") +
24302430
strlen(TOPIC_DISPLAY) + 1;
@@ -2449,7 +2449,10 @@ bool Wippersnapper::generateWSTopics() {
24492449
// Subscribe to signal's DISPLAY sub-topic and set callback
24502450
_topic_signal_display_sub =
24512451
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_signal_display_brkr, 1);
2452+
WS_DEBUG_PRINTLN("Subscribing to DISPLAY topic: ");
2453+
WS_DEBUG_PRINTLN(WS._topic_signal_display_brkr);
24522454
WS._mqtt->subscribe(_topic_signal_display_sub);
2455+
WS_DEBUG_PRINTLN("Subscribed to DISPLAY topic!");
24532456
_topic_signal_display_sub->setCallback(cbDisplayMessage);
24542457

24552458
// Calculate length of the topic for device-to-broker DISPLAY topic

src/Wippersnapper_demo.ino.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 1 "/var/folders/ff/dmzflvf52tq9kzvt6g8jglxw0000gn/T/tmplty6x38x"
2+
#include <Arduino.h>
3+
# 1 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
4+
# 16 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
5+
#include "Wippersnapper_Networking.h"
6+
Wippersnapper_WiFi wipper;
7+
8+
9+
#define WS_DEBUG
10+
void setup();
11+
void loop();
12+
#line 22 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo.ino"
13+
void setup() {
14+
15+
wipper.provision();
16+
17+
Serial.begin(115200);
18+
19+
20+
wipper.connect();
21+
22+
}
23+
24+
void loop() {
25+
wipper.run();
26+
}

src/components/display/controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ DisplayController::~DisplayController() {
3838
bool DisplayController::Handle_Display_AddOrReplace(
3939
wippersnapper_display_v1_DisplayAddOrReplace *msgAdd) {
4040
DisplayHardware *display = new DisplayHardware(msgAdd->name);
41+
WS_DEBUG_PRINT("[display] Adding or replacing display: ");
42+
WS_DEBUG_PRINTLN(msgAdd->name);
4143

4244
// Configure display type
4345
display->setType(msgAdd->type);
@@ -97,6 +99,9 @@ bool DisplayController::Handle_Display_Write(
9799
// Get the driver instance for the display
98100
DisplayHardware *display = nullptr;
99101
for (auto &hw_instance : _hw_instances) {
102+
// print hte _hw_instances name
103+
WS_DEBUG_PRINT("[display] Checking hardware instance: ");
104+
WS_DEBUG_PRINTLN(hw_instance->getName());
100105
if (strcmp(hw_instance->getName(), msgWrite->name) == 0) {
101106
display = hw_instance;
102107
break;

src/components/display/drivers/dispDrvThinkInkGrayscale4Eaamfgn.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file src/components/display/drivers/drvDispThinkInkGrayscale4Eaamfgn.h
33
*
4-
* Driver for ThinkInk 2.9" Grayscale 4-level EAAMFGN display (2025 MagTag).
4+
* Driver for ThinkInk 2.9" Grayscale 4-level EAAMFGN display (present on the 2025 version of the Adafruit MagTag)
55
*
66
* Adafruit invests time and resources providing this open source code,
77
* please support Adafruit and open-source hardware by purchasing
@@ -41,6 +41,7 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
4141
// Clear the display buffer
4242
_display->clearBuffer();
4343
_display->display();
44+
_text_sz = 3; // Configure default magTag text size
4445

4546
return true;
4647
}
@@ -55,8 +56,8 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
5556
_display->clearDisplay();
5657
_display->setTextSize(_text_sz);
5758
_display->setTextColor(EPD_BLACK);
59+
_display->setTextWrap(true);
5860
_display->setCursor(0, y_idx);
59-
_display->display();
6061

6162
// Calculate the line height based on the text size (NOTE: base height is
6263
// 8px)
@@ -81,13 +82,12 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
8182
}
8283
} else if (message[i] == 0xC2 && message[i + 1] == 0xB0) {
8384
_display->write(char(248));
84-
_display->display();
8585
i++;
8686
} else {
8787
_display->print(message[i]);
88-
_display->display();
8988
}
9089
}
90+
_display->display();
9191
}
9292

9393
private:

src/components/display/hardware.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
2727
[](int16_t dc, int16_t rst, int16_t cs, int16_t sram_cs,
2828
int16_t busy) -> dispDrvBase * {
2929
return new drvDispThinkInkGrayscale4Eaamfgn(dc, rst, cs, sram_cs, busy);
30-
}}};
30+
}},
31+
{"magtag_2025",
32+
[](int16_t dc, int16_t rst, int16_t cs, int16_t sram_cs,
33+
int16_t busy) -> dispDrvBase * {
34+
return new drvDispThinkInkGrayscale4Eaamfgn(dc, rst, cs, sram_cs, busy);
35+
}}
36+
};
3137

3238
/*!
3339
@brief Creates a new display driver instance based on the driver name.
@@ -50,17 +56,18 @@ dispDrvBase *CreateDrvDisp(const char *driver_name, int16_t dc, int16_t rst,
5056
int16_t cs, int16_t sram_cs = -1,
5157
int16_t busy = -1) {
5258
auto it = FactoryDrvDisp.find(driver_name);
53-
if (it == FactoryDrvDisp.end()) {
59+
if (it == FactoryDrvDisp.end())
5460
return nullptr;
55-
}
61+
5662
return it->second(dc, rst, cs, sram_cs, busy);
5763
}
5864

5965
/*!
6066
@brief Constructs a new DisplayHardware object
6167
*/
6268
DisplayHardware::DisplayHardware(const char *name) {
63-
_name = name; ///< Set the name of the hardware instance
69+
strncpy(_name, name, sizeof(_name) - 1);
70+
_name[sizeof(_name) - 1] = '\0';
6471
_type = wippersnapper_display_v1_DisplayType_DISPLAY_TYPE_UNSPECIFIED;
6572
}
6673

src/components/display/hardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DisplayHardware {
5050
void writeMessage(const char *message);
5151

5252
private:
53-
const char *_name; ///< Identifies the hardware instance
53+
char _name[64]; ///< Identifies the hardware instance
5454
wippersnapper_display_v1_DisplayType _type; ///< Display type
5555
dispDrvBase *_disp_drv_base = nullptr; ///< Base display driver
5656
};

src/wippersnapper/description/v1/description.pb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Automatically generated nanopb constant definitions */
2-
/* Generated by nanopb-0.4.5-dev at Mon Aug 18 18:41:06 2025. */
2+
/* Generated by nanopb-0.4.5-dev at Tue Aug 19 17:48:25 2025. */
33

44
#include "wippersnapper/description/v1/description.pb.h"
55
#if PB_PROTO_HEADER_VERSION != 40

src/wippersnapper/description/v1/description.pb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Automatically generated nanopb header */
2-
/* Generated by nanopb-0.4.5-dev at Mon Aug 18 18:41:06 2025. */
2+
/* Generated by nanopb-0.4.5-dev at Tue Aug 19 17:48:25 2025. */
33

44
#ifndef PB_WIPPERSNAPPER_DESCRIPTION_V1_WIPPERSNAPPER_DESCRIPTION_V1_DESCRIPTION_PB_H_INCLUDED
55
#define PB_WIPPERSNAPPER_DESCRIPTION_V1_WIPPERSNAPPER_DESCRIPTION_V1_DESCRIPTION_PB_H_INCLUDED

src/wippersnapper/display/v1/display.pb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Automatically generated nanopb constant definitions */
2-
/* Generated by nanopb-0.4.5-dev at Mon Aug 18 18:41:06 2025. */
2+
/* Generated by nanopb-0.4.5-dev at Tue Aug 19 17:48:25 2025. */
33

44
#include "wippersnapper/display/v1/display.pb.h"
55
#if PB_PROTO_HEADER_VERSION != 40
@@ -21,7 +21,7 @@ PB_BIND(wippersnapper_display_v1_DisplayAddOrReplace, wippersnapper_display_v1_D
2121
PB_BIND(wippersnapper_display_v1_DisplayRemove, wippersnapper_display_v1_DisplayRemove, AUTO)
2222

2323

24-
PB_BIND(wippersnapper_display_v1_DisplayWrite, wippersnapper_display_v1_DisplayWrite, AUTO)
24+
PB_BIND(wippersnapper_display_v1_DisplayWrite, wippersnapper_display_v1_DisplayWrite, 2)
2525

2626

2727
PB_BIND(wippersnapper_display_v1_DisplayAddedorReplaced, wippersnapper_display_v1_DisplayAddedorReplaced, AUTO)

src/wippersnapper/display/v1/display.pb.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Automatically generated nanopb header */
2-
/* Generated by nanopb-0.4.5-dev at Mon Aug 18 18:41:06 2025. */
2+
/* Generated by nanopb-0.4.5-dev at Tue Aug 19 17:48:25 2025. */
33

44
#ifndef PB_WIPPERSNAPPER_DISPLAY_V1_WIPPERSNAPPER_DISPLAY_V1_DISPLAY_PB_H_INCLUDED
55
#define PB_WIPPERSNAPPER_DISPLAY_V1_WIPPERSNAPPER_DISPLAY_V1_DISPLAY_PB_H_INCLUDED
@@ -41,7 +41,7 @@ typedef struct _wippersnapper_display_v1_DisplayAddedorReplaced {
4141
} wippersnapper_display_v1_DisplayAddedorReplaced;
4242

4343
typedef struct _wippersnapper_display_v1_DisplayRemove {
44-
char name[6];
44+
char name[64];
4545
} wippersnapper_display_v1_DisplayRemove;
4646

4747
typedef struct _wippersnapper_display_v1_DisplayRemoved {
@@ -82,8 +82,8 @@ typedef struct _wippersnapper_display_v1_DisplayAddOrReplace {
8282
} wippersnapper_display_v1_DisplayAddOrReplace;
8383

8484
typedef struct _wippersnapper_display_v1_DisplayWrite {
85-
char name[6];
86-
char message[6];
85+
char name[64];
86+
char message[1024];
8787
pb_size_t which_options;
8888
union {
8989
wippersnapper_display_v1_EPDWriteOptions epd_options;
@@ -231,8 +231,8 @@ extern const pb_msgdesc_t wippersnapper_display_v1_DisplayRemoved_msg;
231231
#define wippersnapper_display_v1_EPDConfig_size 24
232232
#define wippersnapper_display_v1_EPDWriteOptions_size 13
233233
#define wippersnapper_display_v1_DisplayAddOrReplace_size 141
234-
#define wippersnapper_display_v1_DisplayRemove_size 7
235-
#define wippersnapper_display_v1_DisplayWrite_size 29
234+
#define wippersnapper_display_v1_DisplayRemove_size 65
235+
#define wippersnapper_display_v1_DisplayWrite_size 1106
236236
#define wippersnapper_display_v1_DisplayAddedorReplaced_size 2
237237
#define wippersnapper_display_v1_DisplayRemoved_size 2
238238

0 commit comments

Comments
 (0)