@@ -50,11 +50,6 @@ static const std::map<std::string, FnCreateDispDrvTft> FactoryDrvDispTft = {
5050 return new dispDrvSt7789 (cs, dc, mosi, sck, rst, miso);
5151 }},
5252 {" st7789" ,
53- [](int16_t cs, int16_t dc, int16_t mosi, int16_t sck, int16_t rst,
54- int16_t miso) -> dispDrvBase * {
55- return new dispDrvSt7789 (cs, dc, mosi, sck, rst, miso);
56- }},
57- {" st7789-large" ,
5853 [](int16_t cs, int16_t dc, int16_t mosi, int16_t sck, int16_t rst,
5954 int16_t miso) -> dispDrvBase * {
6055 return new dispDrvSt7789 (cs, dc, mosi, sck, rst, miso);
@@ -93,6 +88,20 @@ dispDrvBase *CreateDrvDispEpd(const char *driver_name, int16_t dc, int16_t rst,
9388 name.
9489 @param driver_name
9590 The name of the SPI TFT display driver to create.
91+ @param cs
92+ Chip Select pin number.
93+ @param dc
94+ Data/Command pin number.
95+ @param mosi
96+ MOSI pin number.
97+ @param sck
98+ SCK pin number.
99+ @param rst
100+ Optional Reset pin number (default: -1).
101+ @param miso
102+ Optional MISO pin number (default: -1).
103+ @return Pointer to the created display driver instance, or nullptr if the
104+ driver name is not recognized.
96105*/
97106dispDrvBase *CreateDrvDispTft (const char *driver_name, int16_t cs, int16_t dc,
98107 int16_t mosi, int16_t sck, int16_t rst = -1 ,
@@ -244,6 +253,18 @@ bool DisplayHardware::beginEPD(
244253 return true ;
245254}
246255
256+ /* !
257+ @brief Removes a suffix from the hardware instance name, if it exists.
258+ @param suffix
259+ The suffix to remove (e.g., "-lg", "-md", "-sm").
260+ */
261+ void DisplayHardware::removeSuffix (const char *suffix) {
262+ char *suffix_pos = strstr (_name, suffix);
263+ if (suffix_pos) {
264+ *suffix_pos = ' \0 ' ; // Truncate string at suffix position
265+ }
266+ }
267+
247268/* !
248269 @brief Attempts to configure and initialize a TFT display
249270 @param config
@@ -282,24 +303,33 @@ bool DisplayHardware::beginTft(
282303 miso = parsePin (spi_config->pin_miso );
283304 }
284305
306+ // Configure text size based on suffix in driver name
307+ uint8_t text_sz; // Default text size
308+ if (strstr (_name, " -lg" ) != nullptr ) {
309+ // Larger text size for displays with -lg suffix
310+ text_sz = 4 ;
311+ removeSuffix (" -lg" );
312+ } else if (strstr (_name, " -md" ) != nullptr ) {
313+ // Larger text size for displays with -md suffix
314+ text_sz = 3 ;
315+ removeSuffix (" -md" );
316+ } else {
317+ text_sz = 1 ;
318+ }
319+
285320 // Create display driver object using the factory function
286321 _drvDisp = CreateDrvDispTft (_name, cs, dc, mosi, sck, rst, miso);
287322 if (!_drvDisp) {
288323 WS_DEBUG_PRINTLN (" [display] Failed to create display driver!" );
289324 return false ;
290325 }
291326
292- // Check if name has -large suffix, and if so, set a larger default text size
293- if (strstr (_name, " -large" ) != nullptr ) {
294- _drvDisp->setTextSize (3 ); // Large text size for -large displays
295- }
296-
297327 _drvDisp->setWidth (config->width );
298328 _drvDisp->setHeight (config->height );
299329 _drvDisp->setRotation (config->rotation );
300330 _drvDisp->begin ();
331+ _drvDisp->setTextSize (text_sz);
301332
302- WS_DEBUG_PRINTLN (" [display] TFT display initialized successfully!" );
303333 return true ;
304334}
305335
0 commit comments