@@ -24,39 +24,64 @@ DisplayController::DisplayController() {
2424/* !
2525 @brief Destructor
2626*/
27- DisplayController::DisplayController () {
27+ DisplayController::~ DisplayController () {
2828 // TODO
2929}
3030
3131/* !
3232 @brief Handles a Display_AddOrReplace message.
3333 @param msgAdd
3434 Pointer to a DisplayAddOrReplace message structure.
35- @return True if the display was added or replaced successfully, false otherwise.
35+ @return True if the display was added or replaced successfully, false
36+ otherwise.
3637*/
37- bool DisplayController::Handle_Display_AddOrReplace (wippersnapper_display_v1_DisplayAddOrReplace *msgAdd) {
38- DisplayHardware *display = new DisplayHardware (msgAdd->name );
39-
40- // Configure display type
41- display->setType (msgAdd->type );
42-
43- // Attempt to initialize display hardware instance
44- bool did_begin = false ;
45- if (msgAdd->which_config == wippersnapper_display_v1_DisplayAddOrReplace_epd_config_tag) {
46- did_begin = display->beginEPD (&msgAdd->config .epd_config , &msgAdd->interface_type .spi_epd );
47- } else {
48- WS_DEBUG_PRINTLN (" [display] Unsupported display configuration type!" );
49- return false ;
50- }
38+ bool DisplayController::Handle_Display_AddOrReplace (
39+ wippersnapper_display_v1_DisplayAddOrReplace *msgAdd) {
40+ DisplayHardware *display = new DisplayHardware (msgAdd->name );
5141
52- // Check if the display began successfully
53- if (!did_begin) {
54- WS_DEBUG_PRINTLN (" [display] Failed to initialize display!" );
55- delete display; // Clean up if initialization failed
56- return false ;
57- }
42+ // Configure display type
43+ display->setType (msgAdd->type );
44+
45+ // Attempt to initialize display hardware instance
46+ bool did_begin = false ;
47+ if (msgAdd->which_config ==
48+ wippersnapper_display_v1_DisplayAddOrReplace_epd_config_tag) {
49+ did_begin = display->beginEPD (&msgAdd->config .epd_config ,
50+ &msgAdd->interface_type .spi_epd );
51+ } else {
52+ WS_DEBUG_PRINTLN (" [display] Unsupported display configuration type!" );
53+ return false ;
54+ }
55+
56+ // Check if the display began successfully
57+ if (!did_begin) {
58+ WS_DEBUG_PRINTLN (" [display] Failed to initialize display!" );
59+ delete display; // Clean up if initialization failed
60+ return false ;
61+ }
5862
59- _hw_instances.push_back (display); // Store the display instance
60- WS_DEBUG_PRINTLN (" [display] Display added or replaced successfully!" );
61- return true ; // Placeholder
63+ _hw_instances.push_back (display); // Store the display instance
64+ WS_DEBUG_PRINTLN (" [display] Display added or replaced successfully!" );
65+ return true ; // Placeholder
6266}
67+
68+ /* !
69+ @brief Handles a Display_Remove message.
70+ @param msgRemove
71+ Pointer to a DisplayRemove message structure.
72+ @return True if the display was removed successfully, false otherwise.
73+ */
74+ bool DisplayController::Handle_Display_Remove (
75+ wippersnapper_display_v1_DisplayRemove *msgRemove) {
76+ // Find the display instance by name
77+ for (auto it = _hw_instances.begin (); it != _hw_instances.end (); ++it) {
78+ if (strcmp ((*it)->getName (), msgRemove->name ) == 0 ) {
79+ delete *it;
80+ _hw_instances.erase (it);
81+ WS_DEBUG_PRINTLN (" [display] Display removed successfully!" );
82+ return true ;
83+ }
84+ }
85+ WS_DEBUG_PRINTLN (" [display] Could not remove display, not found!" );
86+ return false ;
87+ }
0 commit comments