Browse Source

Merge pull request #5314 from thinkyhead/case_light_menu_fix

Fix and optimize case-light code
pull/1/head
Scott Lahteine 8 years ago
committed by GitHub
parent
commit
f45b6a7762
  1. 38
      Marlin/Marlin_main.cpp
  2. 23
      Marlin/ultralcd.cpp

38
Marlin/Marlin_main.cpp

@ -881,27 +881,6 @@ void setup_homepin(void) {
#endif
}
#if HAS_CASE_LIGHT
void setup_case_light() {
digitalWrite(CASE_LIGHT_PIN,
#if ENABLED(CASE_LIGHT_DEFAULT_ON)
255
#else
0
#endif
);
analogWrite(CASE_LIGHT_PIN,
#if ENABLED(CASE_LIGHT_DEFAULT_ON)
255
#else
0
#endif
);
}
#endif
void setup_powerhold() {
#if HAS_SUICIDE
OUT_WRITE(SUICIDE_PIN, HIGH);
@ -7279,6 +7258,13 @@ inline void gcode_M907() {
#if HAS_CASE_LIGHT
uint8_t case_light_brightness = 255;
void update_case_light() {
digitalWrite(CASE_LIGHT_PIN, case_light_on ? HIGH : LOW);
analogWrite(CASE_LIGHT_PIN, case_light_on ? case_light_brightness : 0);
}
/**
* M355: Turn case lights on/off and set brightness
*
@ -7286,13 +7272,9 @@ inline void gcode_M907() {
* P<byte> Set case light brightness (PWM pin required)
*/
inline void gcode_M355() {
static uint8_t case_light_brightness = 255;
if (code_seen('P')) case_light_brightness = code_value_byte();
if (code_seen('S')) {
case_light_on = code_value_bool();
digitalWrite(CASE_LIGHT_PIN, case_light_on ? HIGH : LOW);
analogWrite(CASE_LIGHT_PIN, case_light_on ? case_light_brightness : 0);
}
if (code_seen('S')) case_light_on = code_value_bool();
update_case_light();
SERIAL_ECHO_START;
SERIAL_ECHOPGM("Case lights ");
case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off");
@ -10020,7 +10002,7 @@ void setup() {
#endif
#if HAS_CASE_LIGHT
setup_case_light();
update_case_light();
#endif
#if HAS_BED_PROBE

23
Marlin/ultralcd.cpp

@ -110,9 +110,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
#if HAS_POWER_SWITCH
extern bool powersupply;
#endif
#if HAS_CASE_LIGHT
extern bool case_light_on;
#endif
const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
void lcd_main_menu();
void lcd_tune_menu();
@ -580,6 +578,19 @@ void kill_screen(const char* lcd_msg) {
#endif //SDSUPPORT
#if HAS_CASE_LIGHT && ENABLED(MENU_ITEM_CASE_LIGHT)
extern bool case_light_on;
extern void update_case_light();
void toggle_case_light() {
case_light_on = !case_light_on;
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
update_case_light();
}
#endif // MENU_ITEM_CASE_LIGHT
/**
*
* "Main" menu
@ -594,10 +605,10 @@ void kill_screen(const char* lcd_msg) {
// Switch case light on/off
//
#if HAS_CASE_LIGHT && ENABLED(MENU_ITEM_CASE_LIGHT)
if (case_light_on == 0)
MENU_ITEM(gcode, MSG_LIGHTS_ON, PSTR("M355 S1"));
if (case_light_on)
MENU_ITEM(function, MSG_LIGHTS_OFF, toggle_case_light);
else
MENU_ITEM(gcode, MSG_LIGHTS_OFF, PSTR("M355 S0"));
MENU_ITEM(function, MSG_LIGHTS_ON, toggle_case_light);
#endif
#if ENABLED(BLTOUCH)

Loading…
Cancel
Save