Skip to content

Commit

Permalink
Improved LCD contrast handling
Browse files Browse the repository at this point in the history
Based on MarlinFirmware/MarlinDev#200 from @eboston
  • Loading branch information
thinkyhead committed Jun 2, 2016
1 parent b703fa9 commit efa7209
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
16 changes: 14 additions & 2 deletions Marlin/Conditionals.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@
#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.

#if ENABLED(miniVIKI)
#define LCD_CONTRAST_MIN 75
#define LCD_CONTRAST_MAX 115
#define DEFAULT_LCD_CONTRAST 95
#elif ENABLED(VIKI2)
#define DEFAULT_LCD_CONTRAST 40
#elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
#define LCD_CONTRAST_MIN 90
#define LCD_CONTRAST_MAX 130
#define DEFAULT_LCD_CONTRAST 110
#define U8GLIB_LM6059_AF
#define SD_DETECT_INVERTED
Expand Down Expand Up @@ -246,8 +250,16 @@
*/
#if ENABLED(DOGLCD)
#define HAS_LCD_CONTRAST (DISABLED(U8GLIB_ST7920) && DISABLED(U8GLIB_SSD1306) && DISABLED(U8GLIB_SH1106))
#if HAS_LCD_CONTRAST && !defined(DEFAULT_LCD_CONTRAST)
#define DEFAULT_LCD_CONTRAST 32
#if HAS_LCD_CONTRAST
#ifndef LCD_CONTRAST_MIN
#define LCD_CONTRAST_MIN 0
#endif
#ifndef LCD_CONTRAST_MAX
#define LCD_CONTRAST_MAX 63
#endif
#ifndef DEFAULT_LCD_CONTRAST
#define DEFAULT_LCD_CONTRAST 32
#endif
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5636,7 +5636,7 @@ inline void gcode_M226() {
* M250: Read and optionally set the LCD contrast
*/
inline void gcode_M250() {
if (code_seen('C')) lcd_setcontrast(code_value_short() & 0x3F);
if (code_seen('C')) set_lcd_contrast(code_value_short());
SERIAL_PROTOCOLPGM("lcd contrast value: ");
SERIAL_PROTOCOL(lcd_contrast);
SERIAL_EOL;
Expand Down
25 changes: 10 additions & 15 deletions Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,23 +1716,18 @@ static void lcd_control_volumetric_menu() {
static void lcd_set_contrast() {
ENCODER_DIRECTION_NORMAL();
if (encoderPosition) {
#if ENABLED(U8GLIB_LM6059_AF)
lcd_contrast += encoderPosition;
lcd_contrast &= 0xFF;
#else
lcd_contrast -= encoderPosition;
lcd_contrast &= 0x3F;
#endif
set_lcd_contrast(lcd_contrast + encoderPosition);
encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
u8g.setContrast(lcd_contrast);
}
if (lcdDrawUpdate) {
#if ENABLED(U8GLIB_LM6059_AF)
lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
#else
lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
#endif
lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
#if LCD_CONTRAST_MAX >= 100
itostr3(lcd_contrast)
#else
itostr2(lcd_contrast)
#endif
);
}
if (LCD_CLICKED) lcd_goto_previous_menu(true);
}
Expand Down Expand Up @@ -2384,8 +2379,8 @@ void lcd_setalertstatuspgm(const char* message) {
void lcd_reset_alert_level() { lcd_status_message_level = 0; }

#if HAS_LCD_CONTRAST
void lcd_setcontrast(uint8_t value) {
lcd_contrast = value & 0x3F;
void set_lcd_contrast(int value) {
lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
u8g.setContrast(lcd_contrast);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#if ENABLED(DOGLCD)
extern int lcd_contrast;
void lcd_setcontrast(uint8_t value);
void set_lcd_contrast(int value);
#endif

#define LCD_MESSAGEPGM(x) lcd_setstatuspgm(PSTR(x))
Expand Down

0 comments on commit efa7209

Please sign in to comment.