@@ -168,7 +168,6 @@ class FourLineDisplayUsermod : public Usermod {
168168 // network here
169169 void setup () {
170170 if (type == NONE) return ;
171- byte i;
172171 if (type == SSD1306_SPI || type == SSD1306_SPI64) {
173172 PinManagerPinType pins[5 ] = { { ioPin[0 ], true }, { ioPin[1 ], true }, { ioPin[2 ], true }, { ioPin[3 ], true }, { ioPin[4 ], true }};
174173 if (!pinManager.allocateMultiplePins (pins, 5 , PinOwner::UM_FourLineDisplay)) { type=NONE; return ; }
@@ -242,17 +241,14 @@ class FourLineDisplayUsermod : public Usermod {
242241 }
243242 if (nullptr == u8x8) {
244243 DEBUG_PRINTLN (F (" Display init failed." ));
245- pinManager.deallocatePin (sclPin, PinOwner::UM_FourLineDisplay);
246- pinManager.deallocatePin (sdaPin, PinOwner::UM_FourLineDisplay);
247- sclPin = -1 ;
248- sdaPin = -1 ;
244+ for (byte i=0 ; i<5 && ioPin[i]>=0 ; i++) pinManager.deallocatePin (ioPin[i], PinOwner::UM_FourLineDisplay);
249245 type = NONE;
250246 return ;
251247 }
252248
253249 initDone = true ;
254250 DEBUG_PRINTLN (F (" Starting display." ));
255- ( static_cast <U8X8*>( u8x8)) ->begin (); // why a static cast here? variable is of this type...
251+ u8x8->begin ();
256252 setFlipMode (flip);
257253 setContrast (contrast); // Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
258254 setPowerSave (0 );
@@ -278,40 +274,40 @@ class FourLineDisplayUsermod : public Usermod {
278274 */
279275 void setFlipMode (uint8_t mode) {
280276 if (type==NONE) return ;
281- ( static_cast <U8X8*>( u8x8)) ->setFlipMode (mode);
277+ u8x8->setFlipMode (mode);
282278 }
283279 void setContrast (uint8_t contrast) {
284280 if (type==NONE) return ;
285- ( static_cast <U8X8*>( u8x8)) ->setContrast (contrast);
281+ u8x8->setContrast (contrast);
286282 }
287283 void drawString (uint8_t col, uint8_t row, const char *string, bool ignoreLH=false ) {
288284 if (type==NONE) return ;
289- ( static_cast <U8X8*>( u8x8)) ->setFont (u8x8_font_chroma48medium8_r);
290- if (!ignoreLH && lineHeight==2 ) ( static_cast <U8X8*>( u8x8)) ->draw1x2String (col, row, string);
291- else ( static_cast <U8X8*>( u8x8)) ->drawString (col, row, string);
285+ u8x8->setFont (u8x8_font_chroma48medium8_r);
286+ if (!ignoreLH && lineHeight==2 ) u8x8->draw1x2String (col, row, string);
287+ else u8x8->drawString (col, row, string);
292288 }
293289 void draw2x2String (uint8_t col, uint8_t row, const char *string) {
294290 if (type==NONE) return ;
295- ( static_cast <U8X8*>( u8x8)) ->setFont (u8x8_font_chroma48medium8_r);
296- ( static_cast <U8X8*>( u8x8)) ->draw2x2String (col, row, string);
291+ u8x8->setFont (u8x8_font_chroma48medium8_r);
292+ u8x8->draw2x2String (col, row, string);
297293 }
298294 void drawGlyph (uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false ) {
299295 if (type==NONE) return ;
300- ( static_cast <U8X8*>( u8x8)) ->setFont (font);
301- if (!ignoreLH && lineHeight==2 ) ( static_cast <U8X8*>( u8x8)) ->draw1x2Glyph (col, row, glyph);
302- else ( static_cast <U8X8*>( u8x8)) ->drawGlyph (col, row, glyph);
296+ u8x8->setFont (font);
297+ if (!ignoreLH && lineHeight==2 ) u8x8->draw1x2Glyph (col, row, glyph);
298+ else u8x8->drawGlyph (col, row, glyph);
303299 }
304300 uint8_t getCols () {
305301 if (type==NONE) return 0 ;
306- return ( static_cast <U8X8*>( u8x8)) ->getCols ();
302+ return u8x8->getCols ();
307303 }
308304 void clear () {
309305 if (type==NONE) return ;
310- ( static_cast <U8X8*>( u8x8)) ->clear ();
306+ u8x8->clear ();
311307 }
312308 void setPowerSave (uint8_t save) {
313309 if (type==NONE) return ;
314- ( static_cast <U8X8*>( u8x8)) ->setPowerSave (save);
310+ u8x8->setPowerSave (save);
315311 }
316312
317313 void center (String &line, uint8_t width) {
@@ -726,7 +722,7 @@ class FourLineDisplayUsermod : public Usermod {
726722 bool pinsChanged = false ;
727723 for (byte i=0 ; i<5 ; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true ; break ; }
728724 if (pinsChanged || type!=newType) {
729- if (type != NONE) delete ( static_cast <U8X8*>( u8x8)) ;
725+ if (type != NONE) delete u8x8;
730726 for (byte i=0 ; i<5 ; i++) {
731727 if (ioPin[i]>=0 ) pinManager.deallocatePin (ioPin[i], PinOwner::UM_FourLineDisplay);
732728 ioPin[i] = newPin[i];
@@ -736,9 +732,7 @@ class FourLineDisplayUsermod : public Usermod {
736732 return true ;
737733 } else type = newType;
738734 setup ();
739- if (sclPin >= 0 && sdaPin >= 0 ) {
740- needsRedraw |= true ;
741- }
735+ needsRedraw |= true ;
742736 }
743737 setContrast (contrast);
744738 setFlipMode (flip);
0 commit comments