From efc198f952a54323dbcb4d0c480d6fa9a64edb9b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Jun 2017 17:41:38 -0500 Subject: [PATCH] Spacing, const, comments --- Marlin/Conditionals_LCD.h | 2 +- Marlin/Configuration_adv.h | 12 ++--- Marlin/Marlin_main.cpp | 88 ++++++++++++---------------------- Marlin/buzzer.h | 2 +- Marlin/configuration_store.cpp | 8 ++-- Marlin/temperature.cpp | 2 +- Marlin/ultralcd_impl_HD44780.h | 63 ++++++++++++------------ 7 files changed, 73 insertions(+), 104 deletions(-) diff --git a/Marlin/Conditionals_LCD.h b/Marlin/Conditionals_LCD.h index 3c39512a93..b33499e6bf 100644 --- a/Marlin/Conditionals_LCD.h +++ b/Marlin/Conditionals_LCD.h @@ -243,7 +243,7 @@ /* Custom characters defined in the first 8 characters of the LCD */ #define LCD_BEDTEMP_CHAR 0x00 // Print only as a char. This will have 'unexpected' results when used in a string! #define LCD_DEGREE_CHAR 0x01 - #define LCD_STR_THERMOMETER "\x02" // Too many places use preprocessor string concatination to change this to a char right now. + #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation #define LCD_UPLEVEL_CHAR 0x03 #define LCD_REFRESH_CHAR 0x04 #define LCD_STR_FOLDER "\x05" diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 2665bddb6f..0db274d13b 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -225,13 +225,11 @@ */ //#define CASE_LIGHT_ENABLE #if ENABLED(CASE_LIGHT_ENABLE) - #define CASE_LIGHT_PIN 4 // can be defined here or in the pins_XXX.h file for your board - // pins_XXX.h file overrides this one - #define INVERT_CASE_LIGHT false // set to true if case light is ON when pin is at 0 - #define CASE_LIGHT_DEFAULT_ON true // set default power up state to on or off - #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // set power up brightness 0-255 ( only used if on PWM - // and if CASE_LIGHT_DEFAULT is set to on - //#define MENU_ITEM_CASE_LIGHT // Uncomment to have a Case Light entry in main menu + //#define CASE_LIGHT_PIN 4 // Override the default pin if needed + #define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW + #define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin) + //#define MENU_ITEM_CASE_LIGHT // Add a Case Light option to the LCD main menu #endif //=========================================================================== diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1717026b3f..c4866d89a5 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -458,7 +458,7 @@ volatile bool wait_for_heatup = true; volatile bool wait_for_user = false; #endif -const char axis_codes[XYZE] = {'X', 'Y', 'Z', 'E'}; +const char axis_codes[XYZE] = { 'X', 'Y', 'Z', 'E' }; // Number of characters read in the current line of serial input static int serial_count = 0; @@ -1394,7 +1394,7 @@ bool get_target_extruder_from_command(int code) { * * Callers must sync the planner position after calling this! */ -static void set_axis_is_at_home(AxisEnum axis) { +static void set_axis_is_at_home(const AxisEnum axis) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR(">>> set_axis_is_at_home(", axis_codes[axis]); @@ -1496,7 +1496,7 @@ static void set_axis_is_at_home(AxisEnum axis) { /** * Some planner shorthand inline functions */ -inline float get_homing_bump_feedrate(AxisEnum axis) { +inline float get_homing_bump_feedrate(const AxisEnum axis) { int constexpr homing_bump_divisor[] = HOMING_BUMP_DIVISOR; int hbd = homing_bump_divisor[axis]; if (hbd < 1) { @@ -1507,20 +1507,19 @@ inline float get_homing_bump_feedrate(AxisEnum axis) { return homing_feedrate_mm_s[axis] / hbd; } -// -// line_to_current_position -// Move the planner to the current position from wherever it last moved -// (or from wherever it has been told it is located). -// +/** + * Move the planner to the current position from wherever it last moved + * (or from wherever it has been told it is located). + */ inline void line_to_current_position() { planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate_mm_s, active_extruder); } -// -// line_to_destination -// Move the planner, not necessarily synced with current_position -// -inline void line_to_destination(float fr_mm_s) { +/** + * Move the planner to the position stored in the destination array, which is + * used by G0/G1/G2/G3/G5 and many other functions to set a destination. + */ +inline void line_to_destination(const float fr_mm_s) { planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], fr_mm_s, active_extruder); } inline void line_to_destination() { line_to_destination(feedrate_mm_s); } @@ -2751,7 +2750,7 @@ static void clean_up_after_endstop_or_probe_move() { /** * Home an individual linear axis */ -static void do_homing_move(const AxisEnum axis, float distance, float fr_mm_s=0.0) { +static void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm_s=0.0) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { @@ -4907,7 +4906,7 @@ void home_all_axes() { gcode_G28(true); } if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER)) && NEAR(current_position[Y_AXIS], yProbe - (Y_PROBE_OFFSET_FROM_EXTRUDER)) ) { - float simple_z = current_position[Z_AXIS] - measured_z; + const float simple_z = current_position[Z_AXIS] - measured_z; #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR("Z from Probe:", simple_z); @@ -7667,45 +7666,32 @@ void report_current_position() { #ifdef M114_DETAIL - static const char axis_char[XYZE] = {'X','Y','Z','E'}; - - void report_xyze(const float pos[XYZE], uint8_t n = 4, uint8_t precision = 3) { + void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) { char str[12]; - for(uint8_t i=0; itick(); thermalManager.manage_heater(); diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index f1c1b82e2b..d9d71ce4b4 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -457,10 +457,10 @@ void MarlinSettings::postprocess() { #endif #if DISABLED(ULTIPANEL) - const int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND }, - lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED }, - lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED }; - #endif // !ULTIPANEL + constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND }, + lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED }, + lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED }; + #endif EEPROM_WRITE(lcd_preheat_hotend_temp); EEPROM_WRITE(lcd_preheat_bed_temp); diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 40df64b67a..ea3a9a91f2 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -52,7 +52,7 @@ #endif #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) - static void* heater_ttbl_map[2] = {(void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE }; + static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE }; static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN }; #else static void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS((void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE, (void*)HEATER_2_TEMPTABLE, (void*)HEATER_3_TEMPTABLE, (void*)HEATER_4_TEMPTABLE); diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index d1ddd3ba1b..ed7d630b47 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -193,18 +193,19 @@ extern volatile uint8_t buttons; //an extended version of the last checked butt static void lcd_implementation_update_indicators(); #endif - -static void createChar_P(char c, PROGMEM byte *ptr) { +static void createChar_P(const char c, const byte * const ptr) { byte temp[8]; - int8_t i; - - for(i=0; i<8; i++) { + for (uint8_t i = 0; i < 8; i++) temp[i] = pgm_read_byte(&ptr[i]); - } lcd.createChar(c, temp); } -const static PROGMEM byte bedTemp[8] = { +static void lcd_set_custom_characters( + #if ENABLED(LCD_PROGRESS_BAR) + const bool info_screen_charset = true + #endif +) { + const static PROGMEM byte bedTemp[8] = { B00000, B11111, B10101, @@ -213,9 +214,9 @@ const static PROGMEM byte bedTemp[8] = { B11111, B00000, B00000 -}; + }; -const static PROGMEM byte degree[8] = { + const static PROGMEM byte degree[8] = { B01100, B10010, B10010, @@ -226,7 +227,7 @@ const static PROGMEM byte degree[8] = { B00000 }; -const static PROGMEM byte thermometer[8] = { + const static PROGMEM byte thermometer[8] = { B00100, B01010, B01010, @@ -237,7 +238,7 @@ const static PROGMEM byte thermometer[8] = { B01110 }; -const static PROGMEM byte uplevel[8] = { + const static PROGMEM byte uplevel[8] = { B00100, B01110, B11111, @@ -246,9 +247,9 @@ const static PROGMEM byte uplevel[8] = { B00000, B00000, B00000 -}; + }; -const static PROGMEM byte feedrate[8] = { + const static PROGMEM byte feedrate[8] = { B11100, B10000, B11000, @@ -257,9 +258,9 @@ const static PROGMEM byte feedrate[8] = { B00110, B00101, B00000 -}; + }; -const static PROGMEM byte clock[8] = { + const static PROGMEM byte clock[8] = { B00000, B01110, B10011, @@ -268,10 +269,10 @@ const static PROGMEM byte clock[8] = { B01110, B00000, B00000 -}; + }; -#if ENABLED(SDSUPPORT) - const static PROGMEM byte refresh[8] = { + #if ENABLED(SDSUPPORT) + const static PROGMEM byte refresh[8] = { B00000, B00110, B11001, @@ -280,8 +281,8 @@ const static PROGMEM byte clock[8] = { B10011, B01100, B00000, - }; - const static PROGMEM byte folder[8] = { + }; + const static PROGMEM byte folder[8] = { B00000, B11100, B11111, @@ -290,10 +291,10 @@ const static PROGMEM byte clock[8] = { B11111, B00000, B00000 - }; + }; - #if ENABLED(LCD_PROGRESS_BAR) - const static PROGMEM byte progress[3][8] = { { + #if ENABLED(LCD_PROGRESS_BAR) + const static PROGMEM byte progress[3][8] = { { B00000, B10000, B10000, @@ -321,14 +322,8 @@ const static PROGMEM byte clock[8] = { B10101, B00000 } }; + #endif #endif -#endif - -static void lcd_set_custom_characters( - #if ENABLED(LCD_PROGRESS_BAR) - const bool info_screen_charset = true - #endif -) { createChar_P(LCD_BEDTEMP_CHAR, bedTemp); createChar_P(LCD_DEGREE_CHAR, degree); @@ -638,10 +633,12 @@ FORCE_INLINE void _draw_heater_status(const int8_t heater, const char prefix, co #if ENABLED(LCD_PROGRESS_BAR) inline void lcd_draw_progress_bar(const uint8_t percent) { - int tix = (int)(percent * (LCD_WIDTH) * 3) / 100, - cel = tix / 3, rem = tix % 3, i = LCD_WIDTH; + const int tix = (int)(percent * (LCD_WIDTH) * 3) / 100, + cel = tix / 3, + rem = tix % 3; + uint8_t i = LCD_WIDTH; char msg[LCD_WIDTH + 1], b = ' '; - msg[i] = '\0'; + msg[LCD_WIDTH] = '\0'; while (i--) { if (i == cel - 1) b = LCD_STR_PROGRESS[2];