Skip to content

Commit 7ee745b

Browse files
committed
πŸ§‘β€πŸ’» TFT GLCD "panel_detected"
1 parent 3696cc3 commit 7ee745b

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed

β€ŽMarlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static unsigned char framebuffer[FBSIZE];
135135
static unsigned char *fb;
136136
static uint8_t cour_line;
137137
static uint8_t picBits, ledBits, hotBits;
138-
static uint8_t PanelDetected = 0;
138+
static bool panel_detected = false;
139139

140140
// Different platforms use different SPI methods
141141
#if ANY(__AVR__, TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
@@ -169,13 +169,13 @@ void TFTGLCD::clear_buffer() {
169169

170170
// Clear panel's screen
171171
void TFTGLCD::clr_screen() {
172-
if (!PanelDetected) return;
172+
if (!panel_detected) return;
173173
#if ENABLED(TFTGLCD_PANEL_SPI)
174174
WRITE(TFTGLCD_CS, LOW);
175175
SPI_SEND_ONE(CLR_SCREEN);
176176
WRITE(TFTGLCD_CS, HIGH);
177177
#else
178-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
178+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS)); //set I2C device address
179179
Wire.write(CLR_SCREEN);
180180
Wire.endTransmission(); //transmit data
181181
#endif
@@ -199,15 +199,15 @@ void TFTGLCD::print(const char *line) {
199199

200200
// For menu
201201
void TFTGLCD::print_line() {
202-
if (!PanelDetected) return;
202+
if (!panel_detected) return;
203203
#if ENABLED(TFTGLCD_PANEL_SPI)
204204
WRITE(TFTGLCD_CS, LOW);
205205
SPI_SEND_ONE(LCD_PUT);
206206
SPI_SEND_ONE(cour_line);
207207
SPI_SEND_SOME(framebuffer, LCD_WIDTH, cour_line * LCD_WIDTH);
208208
WRITE(TFTGLCD_CS, HIGH);
209209
#else
210-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
210+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS)); //set I2C device address
211211
Wire.write(LCD_PUT);
212212
Wire.write(cour_line);
213213
Wire.write(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); //transfer 1 line to txBuffer
@@ -217,7 +217,7 @@ void TFTGLCD::print_line() {
217217
}
218218

219219
void TFTGLCD::print_screen() {
220-
if (!PanelDetected) return;
220+
if (!panel_detected) return;
221221
framebuffer[FBSIZE - 2] = picBits & PIC_MASK;
222222
framebuffer[FBSIZE - 1] = ledBits;
223223
#if ENABLED(TFTGLCD_PANEL_SPI)
@@ -229,33 +229,33 @@ void TFTGLCD::print_screen() {
229229
#else
230230
uint8_t r;
231231
// Send framebuffer to panel by line
232-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
232+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
233233
// First line
234234
Wire.write(LCD_WRITE);
235235
Wire.write(&framebuffer[0], LCD_WIDTH);
236236
Wire.endTransmission();
237237
for (r = 1; r < (LCD_HEIGHT - 1); r++) {
238-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
238+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
239239
Wire.write(&framebuffer[r * LCD_WIDTH], LCD_WIDTH);
240240
Wire.endTransmission();
241241
}
242242
// Last line
243-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
243+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
244244
Wire.write(&framebuffer[r * LCD_WIDTH], LCD_WIDTH);
245245
Wire.write(&framebuffer[FBSIZE - 2], 2);
246246
Wire.endTransmission();
247247
#endif
248248
}
249249

250250
void TFTGLCD::setContrast(uint16_t contrast) {
251-
if (!PanelDetected) return;
251+
if (!panel_detected) return;
252252
#if ENABLED(TFTGLCD_PANEL_SPI)
253253
WRITE(TFTGLCD_CS, LOW);
254254
SPI_SEND_ONE(CONTRAST);
255255
SPI_SEND_ONE((uint8_t)contrast);
256256
WRITE(TFTGLCD_CS, HIGH);
257257
#else
258-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
258+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
259259
Wire.write(CONTRAST);
260260
Wire.write((uint8_t)contrast);
261261
Wire.endTransmission();
@@ -266,7 +266,7 @@ extern volatile int8_t encoderDiff;
266266

267267
// Read buttons and encoder states
268268
uint8_t MarlinUI::read_slow_buttons() {
269-
if (!PanelDetected) return 0;
269+
if (!panel_detected) return 0;
270270
#if ENABLED(TFTGLCD_PANEL_SPI)
271271
uint8_t b = 0;
272272
WRITE(TFTGLCD_CS, LOW);
@@ -283,13 +283,13 @@ uint8_t MarlinUI::read_slow_buttons() {
283283
WRITE(TFTGLCD_CS, HIGH);
284284
return b;
285285
#else
286-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
286+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
287287
Wire.write(READ_ENCODER);
288288
Wire.endTransmission();
289289
#ifdef __AVR__
290-
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1);
290+
Wire.requestFrom(uint8_t(LCD_I2C_ADDRESS), 2, 0, 0, 1);
291291
#elif defined(STM32F1)
292-
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2);
292+
Wire.requestFrom(uint8_t(LCD_I2C_ADDRESS), uint8_t(2));
293293
#elif ANY(STM32F4xx, TARGET_LPC1768)
294294
Wire.requestFrom(LCD_I2C_ADDRESS, 2);
295295
#endif
@@ -300,7 +300,7 @@ uint8_t MarlinUI::read_slow_buttons() {
300300

301301
// Duration in ms, freq in Hz
302302
void MarlinUI::buzz(const long duration, const uint16_t freq/*=0*/) {
303-
if (!PanelDetected) return;
303+
if (!panel_detected) return;
304304
if (!sound_on) return;
305305
#if ENABLED(TFTGLCD_PANEL_SPI)
306306
WRITE(TFTGLCD_CS, LOW);
@@ -309,20 +309,19 @@ void MarlinUI::buzz(const long duration, const uint16_t freq/*=0*/) {
309309
SPI_SEND_TWO(freq);
310310
WRITE(TFTGLCD_CS, HIGH);
311311
#else
312-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
312+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
313313
Wire.write(BUZZER);
314-
Wire.write((uint8_t)(duration >> 8));
315-
Wire.write((uint8_t)duration);
316-
Wire.write((uint8_t)(freq >> 8));
317-
Wire.write((uint8_t)freq);
314+
Wire.write(uint8_t(duration >> 8));
315+
Wire.write(uint8_t(duration));
316+
Wire.write(uint8_t(freq >> 8));
317+
Wire.write(uint8_t(freq));
318318
Wire.endTransmission();
319319
#endif
320320
}
321321

322322
void MarlinUI::init_lcd() {
323-
uint8_t t;
324323
lcd.clear_buffer();
325-
t = 0;
324+
uint8_t t = 0;
326325
#if ENABLED(TFTGLCD_PANEL_SPI)
327326
// SPI speed must be less 10MHz
328327
SET_OUTPUT(TFTGLCD_CS);
@@ -335,43 +334,40 @@ void MarlinUI::init_lcd() {
335334
#ifdef TARGET_LPC1768
336335
Wire.begin(); //init twi/I2C
337336
#else
338-
Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C
337+
Wire.begin(uint8_t(LCD_I2C_ADDRESS)); //init twi/I2C
339338
#endif
340-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
341-
Wire.write((uint8_t)GET_LCD_ROW); // put command to buffer
339+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
340+
Wire.write(uint8_t(GET_LCD_ROW)); // put command to buffer
342341
Wire.endTransmission(); // send buffer
343342
#ifdef __AVR__
344-
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1);
343+
Wire.requestFrom(uint8_t(LCD_I2C_ADDRESS), 1, 0, 0, 1);
345344
#elif ANY(STM32F1, STM32F4xx, TARGET_LPC1768)
346345
Wire.requestFrom(LCD_I2C_ADDRESS, 1);
347346
#endif
348347
t = (uint8_t)Wire.read();
349348
#endif
350349

351-
if (t == LCD_HEIGHT) {
352-
PanelDetected = 1;
350+
panel_detected = (t == LCD_HEIGHT);
351+
352+
if (panel_detected) {
353353
#if ENABLED(TFTGLCD_PANEL_SPI)
354354
SPI_SEND_ONE(INIT_SCREEN);
355355
SPI_SEND_ONE(Marlin);
356356
WRITE(TFTGLCD_CS, HIGH);
357357
#else
358-
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
359-
Wire.write((uint8_t)INIT_SCREEN);
358+
Wire.beginTransmission(uint8_t(LCD_I2C_ADDRESS));
359+
Wire.write(uint8_t(INIT_SCREEN));
360360
Wire.write(Marlin);
361361
Wire.endTransmission();
362362
#endif
363363
}
364-
else
365-
PanelDetected = 0;
366364
safe_delay(100);
367365
}
368366

369-
bool MarlinUI::detected() {
370-
return PanelDetected;
371-
}
367+
bool MarlinUI::detected() { return panel_detected; }
372368

373369
void MarlinUI::clear_lcd() {
374-
if (!PanelDetected) return;
370+
if (!panel_detected) return;
375371
lcd.clr_screen();
376372
lcd.clear_buffer();
377373
}
@@ -395,7 +391,7 @@ static void center_text(FSTR_P const fstart, const uint8_t y) {
395391
#if ENABLED(SHOW_BOOTSCREEN)
396392

397393
void MarlinUI::show_bootscreen() {
398-
if (!PanelDetected) return;
394+
if (!panel_detected) return;
399395
//
400396
// Show the Marlin logo, splash line1, and splash line 2
401397
//
@@ -418,7 +414,7 @@ static void center_text(FSTR_P const fstart, const uint8_t y) {
418414
#endif // SHOW_BOOTSCREEN
419415

420416
void MarlinUI::draw_kill_screen() {
421-
if (!PanelDetected) return;
417+
if (!panel_detected) return;
422418
lcd.clear_buffer();
423419
lcd_moveto(0, 3); lcd.write(COLOR_ERROR);
424420
lcd_moveto((LCD_WIDTH - status_message.glyphs()) / 2 + 1, 3);
@@ -655,7 +651,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
655651
#if ENABLED(LCD_PROGRESS_BAR)
656652

657653
void MarlinUI::draw_progress_bar(const uint8_t percent) {
658-
if (!PanelDetected) return;
654+
if (!panel_detected) return;
659655
if (fb == &framebuffer[0] + LCD_WIDTH * 2) { // For status screen
660656
lcd.write('%'); lcd.write(percent);
661657
}
@@ -672,7 +668,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
672668
#endif // LCD_PROGRESS_BAR
673669

674670
void MarlinUI::draw_status_message(const bool blink) {
675-
if (!PanelDetected) return;
671+
if (!panel_detected) return;
676672
lcd_moveto(0, 3);
677673
#if ALL(FILAMENT_LCD_DISPLAY, HAS_MEDIA)
678674

@@ -812,7 +808,7 @@ Equal to 24x10 text LCD
812808
*/
813809

814810
void MarlinUI::draw_status_screen() {
815-
if (!PanelDetected) return;
811+
if (!panel_detected) return;
816812

817813
const bool blink = get_blink();
818814

@@ -959,7 +955,7 @@ void MarlinUI::draw_status_screen() {
959955
#if ENABLED(ADVANCED_PAUSE_FEATURE)
960956

961957
void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
962-
if (!PanelDetected) return;
958+
if (!panel_detected) return;
963959
lcd_moveto((LCD_WIDTH - 14) / 2, row + 1);
964960
lcd.write(LCD_STR_THERMOMETER[0]); lcd_put_u8str(F(" E")); lcd.write('1' + extruder); lcd.write(' ');
965961
lcd.print(i16tostr3rj(thermalManager.wholeDegHotend(extruder))); lcd.write(LCD_STR_DEGREE[0]); lcd.write('/');
@@ -971,7 +967,7 @@ void MarlinUI::draw_status_screen() {
971967

972968
// Draw a static item with no left-right margin required. Centered by default.
973969
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
974-
if (!PanelDetected) return;
970+
if (!panel_detected) return;
975971
lcd_moveto(0, row);
976972

977973
uint8_t n = LCD_WIDTH;
@@ -1019,7 +1015,7 @@ void MarlinUI::draw_status_screen() {
10191015

10201016
// Draw a generic menu item with pre_char (if selected) and post_char
10211017
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
1022-
if (!PanelDetected) return;
1018+
if (!panel_detected) return;
10231019
lcd_moveto(0, row);
10241020
lcd.write(sel ? pre_char : ' ');
10251021
uint8_t n = LCD_WIDTH - 2;
@@ -1031,7 +1027,7 @@ void MarlinUI::draw_status_screen() {
10311027

10321028
// Draw a menu item with a (potentially) editable value
10331029
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
1034-
if (!PanelDetected) return;
1030+
if (!panel_detected) return;
10351031
const uint8_t vlen = inStr ? (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)) : 0;
10361032
lcd_moveto(0, row);
10371033
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
@@ -1048,7 +1044,7 @@ void MarlinUI::draw_status_screen() {
10481044
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
10491045
// This line moves to the last line of the screen for UBL plot screen on the panel side
10501046
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
1051-
if (!PanelDetected) return;
1047+
if (!panel_detected) return;
10521048
ui.encoder_direction_normal();
10531049
const uint8_t y = TERN0(AUTO_BED_LEVELING_UBL, ui.external_control) ? LCD_HEIGHT - 1 : MIDDLE_Y;
10541050
lcd_moveto(0, y);
@@ -1066,7 +1062,7 @@ void MarlinUI::draw_status_screen() {
10661062

10671063
// The Select Screen presents a prompt and two "buttons"
10681064
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const fpre, const char * const string, FSTR_P const fsuf) {
1069-
if (!PanelDetected) return;
1065+
if (!panel_detected) return;
10701066
ui.draw_select_screen_prompt(fpre, string, fsuf);
10711067
lcd.write(COLOR_EDIT);
10721068
if (no) {
@@ -1083,7 +1079,7 @@ void MarlinUI::draw_status_screen() {
10831079
#if HAS_MEDIA
10841080

10851081
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
1086-
if (!PanelDetected) return;
1082+
if (!panel_detected) return;
10871083
lcd_moveto(0, row);
10881084
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
10891085
uint8_t n = LCD_WIDTH - 2;
@@ -1116,7 +1112,7 @@ void MarlinUI::draw_status_screen() {
11161112
* |____________________|
11171113
*/
11181114
void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
1119-
if (!PanelDetected) return;
1115+
if (!panel_detected) return;
11201116

11211117
#define _LCD_W_POS 12
11221118

0 commit comments

Comments
Β (0)