Commit 9f9a1921 authored by MagoKimbra's avatar MagoKimbra

Merge remote-tracking branch 'refs/remotes/origin/master' into dev

parents 2ac78c47 b2dc21a6
...@@ -1032,12 +1032,10 @@ ...@@ -1032,12 +1032,10 @@
// With ENDSTOPS_ONLY_FOR_HOMING you must send "M120" to enable endstops. // With ENDSTOPS_ONLY_FOR_HOMING you must send "M120" to enable endstops.
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
//This enable the firmware to write some configuration that require frequent update, on the SD card // This enable the firmware to write some configuration that require frequent update, on the SD card
//#define SD_SETTINGS //Uncomment to enable //#define SD_SETTINGS // Uncomment to enable
#define SD_CFG_SECONDS 300 //seconds between update #define SD_CFG_SECONDS 300 // seconds between update
#define CFG_SD_FILE "INFO.CFG" //name of the configuration file #define CFG_SD_FILE "INFO.CFG" // name of the configuration file
#define CFG_SD_MAX_KEY_LEN 3+1 //icrease this if you add key name longer than the actual value.
#define CFG_SD_MAX_VALUE_LEN 12+1 //this should be enought for int, long and float if you need to retrive strings increase this carefully
/*****************************************************************************************/ /*****************************************************************************************/
......
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
bool Running = true; bool Running = true;
bool Printing = false; bool Printing = false;
uint8_t debugLevel = DEBUG_INFO|DEBUG_ERRORS; uint8_t debugLevel = DEBUG_ERRORS;
static float feedrate = 1500.0, saved_feedrate; static float feedrate = 1500.0, saved_feedrate;
float current_position[NUM_AXIS] = { 0.0 }; float current_position[NUM_AXIS] = { 0.0 };
...@@ -309,6 +309,7 @@ bool target_direction; ...@@ -309,6 +309,7 @@ bool target_direction;
bool software_endstops = true; bool software_endstops = true;
unsigned long printer_usage_seconds; unsigned long printer_usage_seconds;
double printer_usage_filament;
#if !MECH(DELTA) #if !MECH(DELTA)
int xy_travel_speed = XY_TRAVEL_SPEED; int xy_travel_speed = XY_TRAVEL_SPEED;
...@@ -3011,6 +3012,8 @@ void gcode_get_destination() { ...@@ -3011,6 +3012,8 @@ void gcode_get_destination() {
if (next_feedrate > 0.0) feedrate = next_feedrate; if (next_feedrate > 0.0) feedrate = next_feedrate;
} }
printer_usage_filament += (destination[E_AXIS] - current_position[E_AXIS]);
#if ENABLED(NEXTION_GFX) #if ENABLED(NEXTION_GFX)
if((code_seen(axis_codes[X_AXIS]) || code_seen(axis_codes[Y_AXIS])) && code_seen(axis_codes[E_AXIS])) if((code_seen(axis_codes[X_AXIS]) || code_seen(axis_codes[Y_AXIS])) && code_seen(axis_codes[E_AXIS]))
gfx_line_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS]); gfx_line_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS]);
......
...@@ -132,7 +132,9 @@ extern bool axis_known_position[3]; ...@@ -132,7 +132,9 @@ extern bool axis_known_position[3];
extern float zprobe_zoffset; extern float zprobe_zoffset;
// Lifetime stats // Lifetime stats
extern unsigned long printer_usage_seconds; //this can old about 136 year before go overflow. If you belive that you can live more than this please contact me. extern unsigned long printer_usage_seconds; // this can old about 136 year before go overflow. If you belive that you can live more than this please contact me.
// Filament stats
extern double printer_usage_filament;
#if ENABLED(PREVENT_DANGEROUS_EXTRUDE) #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
extern float extrude_min_temp; extern float extrude_min_temp;
......
...@@ -875,19 +875,30 @@ void Config_ResetDefault() { ...@@ -875,19 +875,30 @@ void Config_ResetDefault() {
void ConfigSD_PrintSettings(bool forReplay) { void ConfigSD_PrintSettings(bool forReplay) {
// Always have this function, even with SD_SETTINGS disabled, the current values will be shown // Always have this function, even with SD_SETTINGS disabled, the current values will be shown
#if HAS(POWER_CONSUMPTION_SENSOR) #if HAS(POWER_CONSUMPTION_SENSOR)
if (!forReplay) { if (!forReplay) {
ECHO_LM(DB, "Watt/h consumed:"); ECHO_LM(DB, "Watt/h consumed:");
} }
ECHO_LVM(OK, power_consumption_hour," Wh"); ECHO_LVM(OK, power_consumption_hour," Wh");
#endif #endif
if (!forReplay) { if (!forReplay) {
ECHO_LM(DB, "Power on time:"); ECHO_LM(DB, "Power on time:");
} }
char time[30]; char time[30];
int day = printer_usage_seconds / 60 / 60 / 24, hours = (printer_usage_seconds / 60 / 60) % 24, minutes = (printer_usage_seconds / 60) % 60; unsigned int day = printer_usage_seconds / 60 / 60 / 24, hours = (printer_usage_seconds / 60 / 60) % 24, minutes = (printer_usage_seconds / 60) % 60;
sprintf_P(time, PSTR(" %i " MSG_END_DAY " %i " MSG_END_HOUR " %i " MSG_END_MINUTE), day, hours, minutes); sprintf_P(time, PSTR(" %i " MSG_END_DAY " %i " MSG_END_HOUR " %i " MSG_END_MINUTE), day, hours, minutes);
ECHO_LV(DB, time); ECHO_LV(DB, time);
if (!forReplay) {
ECHO_LM(DB, "Filament printed:");
}
char lung[30];
unsigned int kmeter = (long)printer_usage_filament / 1000 / 1000, meter = ((long)printer_usage_filament / 1000) % 1000,
centimeter = ((long)printer_usage_filament / 10) % 100, millimeter = ((long)printer_usage_filament) % 10;
sprintf_P(lung, PSTR(" %i Km %i m %i cm %i mm"), kmeter, meter, centimeter, millimeter);
ECHO_LV(DB, lung);
} }
#endif // !DISABLE_M503 #endif // !DISABLE_M503
...@@ -903,24 +914,27 @@ void ConfigSD_ResetDefault() { ...@@ -903,24 +914,27 @@ void ConfigSD_ResetDefault() {
power_consumption_hour = 0; power_consumption_hour = 0;
#endif #endif
printer_usage_seconds = 0; printer_usage_seconds = 0;
printer_usage_filament = 0;
ECHO_LM(OK, "Hardcoded SD Default Settings Loaded"); ECHO_LM(OK, "Hardcoded SD Default Settings Loaded");
} }
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS) #if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
static const char *cfgSD_KEY[] = { //Keep this in lexicographical order for better search performance(O(Nlog2(N)) insted of O(N*N)) (if you don't keep this sorted, the algorithm for find the key index won't work, keep attention.) static const char *cfgSD_KEY[] = { // Keep this in lexicographical order for better search performance(O(Nlog2(N)) insted of O(N*N)) (if you don't keep this sorted, the algorithm for find the key index won't work, keep attention.)
#if HAS(POWER_CONSUMPTION_SENSOR) #if HAS(POWER_CONSUMPTION_SENSOR)
"PWR", "PWR",
#endif #endif
"TME", "FIL",
"TME"
}; };
enum cfgSD_ENUM { //This need to be in the same order as cfgSD_KEY enum cfgSD_ENUM { // This need to be in the same order as cfgSD_KEY
#if HAS(POWER_CONSUMPTION_SENSOR) #if HAS(POWER_CONSUMPTION_SENSOR)
SD_CFG_PWR, SD_CFG_PWR,
#endif #endif
SD_CFG_TME, SD_CFG_FIL,
SD_CFG_END //Leave this always as the last SD_CFG_TME,
}; SD_CFG_END // Leave this always as the last
};
void ConfigSD_StoreSettings() { void ConfigSD_StoreSettings() {
if(!IS_SD_INSERTED || card.isFileOpen() || card.sdprinting) return; if(!IS_SD_INSERTED || card.isFileOpen() || card.sdprinting) return;
...@@ -929,12 +943,14 @@ void ConfigSD_ResetDefault() { ...@@ -929,12 +943,14 @@ void ConfigSD_ResetDefault() {
card.openFile((char *)CFG_SD_FILE, false, true, false); card.openFile((char *)CFG_SD_FILE, false, true, false);
char buff[CFG_SD_MAX_VALUE_LEN]; char buff[CFG_SD_MAX_VALUE_LEN];
#if HAS(POWER_CONSUMPTION_SENSOR) #if HAS(POWER_CONSUMPTION_SENSOR)
ltoa(power_consumption_hour,buff,10); ltoa(power_consumption_hour, buff, 10);
card.unparseKeyLine(cfgSD_KEY[SD_CFG_PWR], buff); card.unparseKeyLine(cfgSD_KEY[SD_CFG_PWR], buff);
#endif #endif
ltoa(printer_usage_seconds,buff,10); ltoa(printer_usage_seconds, buff, 10);
card.unparseKeyLine(cfgSD_KEY[SD_CFG_TME], buff); card.unparseKeyLine(cfgSD_KEY[SD_CFG_TME], buff);
ltoa(printer_usage_filament, buff, 10);
card.unparseKeyLine(cfgSD_KEY[SD_CFG_FIL], buff);
card.closeFile(false); card.closeFile(false);
card.setlast(); card.setlast();
config_last_update = millis(); config_last_update = millis();
...@@ -953,9 +969,9 @@ void ConfigSD_ResetDefault() { ...@@ -953,9 +969,9 @@ void ConfigSD_ResetDefault() {
k_len = CFG_SD_MAX_KEY_LEN; k_len = CFG_SD_MAX_KEY_LEN;
v_len = CFG_SD_MAX_VALUE_LEN; v_len = CFG_SD_MAX_VALUE_LEN;
card.parseKeyLine(key, value, k_len, v_len); card.parseKeyLine(key, value, k_len, v_len);
if(k_len == 0 || v_len == 0) break; //no valid key or value founded if(k_len == 0 || v_len == 0) break; // no valid key or value founded
k_idx = ConfigSD_KeyIndex(key); k_idx = ConfigSD_KeyIndex(key);
if(k_idx == -1) continue; //unknow key ignore it if(k_idx == -1) continue; // unknow key ignore it
switch(k_idx) { switch(k_idx) {
#if HAS(POWER_CONSUMPTION_SENSOR) #if HAS(POWER_CONSUMPTION_SENSOR)
case SD_CFG_PWR: { case SD_CFG_PWR: {
...@@ -969,6 +985,11 @@ void ConfigSD_ResetDefault() { ...@@ -969,6 +985,11 @@ void ConfigSD_ResetDefault() {
else printer_usage_seconds = (unsigned long)atol(value); else printer_usage_seconds = (unsigned long)atol(value);
} }
break; break;
case SD_CFG_FIL: {
if(addValue) printer_usage_filament += (unsigned long)atol(value);
else printer_usage_filament = (unsigned long)atol(value);
}
break;
} }
} }
card.closeFile(false); card.closeFile(false);
...@@ -977,7 +998,7 @@ void ConfigSD_ResetDefault() { ...@@ -977,7 +998,7 @@ void ConfigSD_ResetDefault() {
unset_sd_dot(); unset_sd_dot();
} }
int ConfigSD_KeyIndex(char *key) { //At the moment a binary search algorithm is used for simplicity, if it will be necessary (Eg. tons of key), an hash search algorithm will be implemented. int ConfigSD_KeyIndex(char *key) { // At the moment a binary search algorithm is used for simplicity, if it will be necessary (Eg. tons of key), an hash search algorithm will be implemented.
int begin = 0, end = SD_CFG_END - 1, middle, cond; int begin = 0, end = SD_CFG_END - 1, middle, cond;
while(begin <= end) { while(begin <= end) {
middle = (begin + end) / 2; middle = (begin + end) / 2;
......
...@@ -23,6 +23,8 @@ FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_Prin ...@@ -23,6 +23,8 @@ FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_Prin
#endif #endif
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS) #if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
#define CFG_SD_MAX_KEY_LEN 3+1 // icrease this if you add key name longer than the actual value.
#define CFG_SD_MAX_VALUE_LEN 30+1 // this should be enought for int, long and float if you need to retrive strings increase this carefully
void ConfigSD_StoreSettings(); void ConfigSD_StoreSettings();
void ConfigSD_RetrieveSettings(bool addValue = false); void ConfigSD_RetrieveSettings(bool addValue = false);
int ConfigSD_KeyIndex(char *key); int ConfigSD_KeyIndex(char *key);
......
...@@ -629,12 +629,6 @@ ...@@ -629,12 +629,6 @@
#if DISABLED(CFG_SD_FILE) #if DISABLED(CFG_SD_FILE)
#error DEPENDENCY ERROR: Missing setting CFG_SD_FILE #error DEPENDENCY ERROR: Missing setting CFG_SD_FILE
#endif #endif
#if DISABLED(CFG_SD_MAX_KEY_LEN)
#error DEPENDENCY ERROR: Missing setting CFG_SD_MAX_KEY_LEN
#endif
#if DISABLED(CFG_SD_MAX_VALUE_LEN)
#error DEPENDENCY ERROR: Missing setting CFG_SD_MAX_VALUE_LEN
#endif
#endif #endif
#endif #endif
#if DISABLED(DISPLAY_CHARSET_HD44780_JAPAN) && DISABLED(DISPLAY_CHARSET_HD44780_WESTERN) && DISABLED(DISPLAY_CHARSET_HD44780_CYRILLIC) #if DISABLED(DISPLAY_CHARSET_HD44780_JAPAN) && DISABLED(DISPLAY_CHARSET_HD44780_WESTERN) && DISABLED(DISPLAY_CHARSET_HD44780_CYRILLIC)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment