@@ -28,13 +28,35 @@ DisplayController::DisplayController() {
2828 // TODO
2929}
3030
31+ /* !
32+ @brief Handles a Display_AddOrReplace message.
33+ @param msgAdd
34+ Pointer to a DisplayAddOrReplace message structure.
35+ @return True if the display was added or replaced successfully, false otherwise.
36+ */
3137bool DisplayController::Handle_Display_AddOrReplace (wippersnapper_display_v1_DisplayAddOrReplace *msgAdd) {
32- DisplayHardware *display = new DisplayHardware ();
38+ DisplayHardware *display = new DisplayHardware (msgAdd->name );
39+
3340 // Configure display type
3441 display->setType (msgAdd->type );
35- // Configure display based on config type
42+
43+ // Attempt to initialize display hardware instance
44+ bool did_begin = false ;
3645 if (msgAdd->which_config == wippersnapper_display_v1_DisplayAddOrReplace_epd_config_tag) {
37- display->configureEPD (&msgAdd->config .epd_config , &msgAdd->interface_type .spi_epd );
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 ;
3850 }
51+
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+ }
58+
59+ _hw_instances.push_back (display); // Store the display instance
60+ WS_DEBUG_PRINTLN (" [display] Display added or replaced successfully!" );
3961 return true ; // Placeholder
4062}
0 commit comments