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 #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() { void setup_powerhold() {
#if HAS_SUICIDE #if HAS_SUICIDE
OUT_WRITE(SUICIDE_PIN, HIGH); OUT_WRITE(SUICIDE_PIN, HIGH);
@ -7279,6 +7258,13 @@ inline void gcode_M907() {
#if HAS_CASE_LIGHT #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 * 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) * P<byte> Set case light brightness (PWM pin required)
*/ */
inline void gcode_M355() { inline void gcode_M355() {
static uint8_t case_light_brightness = 255;
if (code_seen('P')) case_light_brightness = code_value_byte(); if (code_seen('P')) case_light_brightness = code_value_byte();
if (code_seen('S')) { if (code_seen('S')) case_light_on = code_value_bool();
case_light_on = code_value_bool(); update_case_light();
digitalWrite(CASE_LIGHT_PIN, case_light_on ? HIGH : LOW);
analogWrite(CASE_LIGHT_PIN, case_light_on ? case_light_brightness : 0);
}
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM("Case lights "); SERIAL_ECHOPGM("Case lights ");
case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off"); case_light_on ? SERIAL_ECHOLNPGM("on") : SERIAL_ECHOLNPGM("off");
@ -10020,7 +10002,7 @@ void setup() {
#endif #endif
#if HAS_CASE_LIGHT #if HAS_CASE_LIGHT
setup_case_light(); update_case_light();
#endif #endif
#if HAS_BED_PROBE #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 #if HAS_POWER_SWITCH
extern bool powersupply; extern bool powersupply;
#endif #endif
#if HAS_CASE_LIGHT
extern bool case_light_on;
#endif
const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE; const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
void lcd_main_menu(); void lcd_main_menu();
void lcd_tune_menu(); void lcd_tune_menu();
@ -580,6 +578,19 @@ void kill_screen(const char* lcd_msg) {
#endif //SDSUPPORT #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 * "Main" menu
@ -594,10 +605,10 @@ void kill_screen(const char* lcd_msg) {
// Switch case light on/off // Switch case light on/off
// //
#if HAS_CASE_LIGHT && ENABLED(MENU_ITEM_CASE_LIGHT) #if HAS_CASE_LIGHT && ENABLED(MENU_ITEM_CASE_LIGHT)
if (case_light_on == 0) if (case_light_on)
MENU_ITEM(gcode, MSG_LIGHTS_ON, PSTR("M355 S1")); MENU_ITEM(function, MSG_LIGHTS_OFF, toggle_case_light);
else else
MENU_ITEM(gcode, MSG_LIGHTS_OFF, PSTR("M355 S0")); MENU_ITEM(function, MSG_LIGHTS_ON, toggle_case_light);
#endif #endif
#if ENABLED(BLTOUCH) #if ENABLED(BLTOUCH)

Loading…
Cancel
Save