Commit 48e1664e authored by MagoKimbra's avatar MagoKimbra

Merge pull request #34 from simone97/master

Power Consumption LCD Update + code clean
parents 2f1d9332 5f46d324
...@@ -437,5 +437,11 @@ ...@@ -437,5 +437,11 @@
#define WRITE_FAN(v) WRITE(FAN_PIN, v) #define WRITE_FAN(v) WRITE(FAN_PIN, v)
#endif #endif
/**
* Shorthand for sensor test for ultralcd.cpp, dogm_lcd_implementation.h, ultralcd_implementation_hitachi_HD44780.h
*/
#define HAS_LCD_FILAMENT_SENSOR (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY))
#define HAS_LCD_POWER_SENSOR (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY))
#endif //CONFIGURATION_LCD #endif //CONFIGURATION_LCD
#endif //CONDITIONALS_H #endif //CONDITIONALS_H
...@@ -41,7 +41,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) { ...@@ -41,7 +41,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
// wrong data being written to the variables. // wrong data being written to the variables.
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
#define EEPROM_VERSION "V17" #define EEPROM_VERSION "V18"
#ifdef EEPROM_SETTINGS #ifdef EEPROM_SETTINGS
void Config_StoreSettings() { void Config_StoreSettings() {
...@@ -133,6 +133,10 @@ void Config_StoreSettings() { ...@@ -133,6 +133,10 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR(i, idleoozing_enabled); EEPROM_WRITE_VAR(i, idleoozing_enabled);
#endif #endif
#if defined(POWER_CONSUMPTION) && defined(STORE_CONSUMPTION)
EEPROM_WRITE_VAR(i, power_consumption_hour);
#endif
int storageSize = i; int storageSize = i;
char ver2[4] = EEPROM_VERSION; char ver2[4] = EEPROM_VERSION;
...@@ -256,6 +260,10 @@ void Config_RetrieveSettings() ...@@ -256,6 +260,10 @@ void Config_RetrieveSettings()
EEPROM_READ_VAR(i, idleoozing_enabled); EEPROM_READ_VAR(i, idleoozing_enabled);
#endif #endif
#if defined(POWER_CONSUMPTION) && defined(STORE_CONSUMPTION)
EEPROM_READ_VAR(i, power_consumption_hour);
#endif
// Call updatePID (similar to when we have processed M301) // Call updatePID (similar to when we have processed M301)
updatePID(); updatePID();
SERIAL_ECHO_START; SERIAL_ECHO_START;
...@@ -401,6 +409,10 @@ void Config_ResetDefault() ...@@ -401,6 +409,10 @@ void Config_ResetDefault()
idleoozing_enabled = true; idleoozing_enabled = true;
#endif #endif
#if defined(POWER_CONSUMPTION) && defined(STORE_CONSUMPTION)
power_consumption_hour = 0;
#endif
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded"); SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
} }
......
...@@ -307,6 +307,8 @@ extern int fanSpeed; ...@@ -307,6 +307,8 @@ extern int fanSpeed;
#if HAS_POWER_CONSUMPTION_SENSOR #if HAS_POWER_CONSUMPTION_SENSOR
extern float power_consumption_meas; //holds the power consumption as accurately measured extern float power_consumption_meas; //holds the power consumption as accurately measured
extern unsigned long power_consumption_hour; //holds the power consumption per hour as accurately measured extern unsigned long power_consumption_hour; //holds the power consumption per hour as accurately measured
extern unsigned long startpower;
extern unsigned long stoppower;
#endif #endif
#ifdef IDLE_OOZING_PREVENT #ifdef IDLE_OOZING_PREVENT
......
...@@ -340,8 +340,10 @@ uint8_t debugLevel = 0; ...@@ -340,8 +340,10 @@ uint8_t debugLevel = 0;
#endif #endif
#if HAS_POWER_CONSUMPTION_SENSOR #if HAS_POWER_CONSUMPTION_SENSOR
float power_consumption_meas = 0; float power_consumption_meas = 0.0;
unsigned long power_consumption_hour = 0.0; unsigned long power_consumption_hour = 0;
unsigned long startpower = 0;
unsigned long stoppower = 0;
#endif #endif
#ifdef LASERBEAM #ifdef LASERBEAM
...@@ -927,13 +929,18 @@ void get_command() ...@@ -927,13 +929,18 @@ void get_command()
{ {
if(card.eof()){ if(card.eof()){
SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED); SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
stoptime=millis(); stoptime = millis();
stoppower = power_consumption_hour-startpower;
char time[30]; char time[30];
unsigned long t=(stoptime-starttime)/1000; unsigned long t = (stoptime-starttime) / 1000;
int hours, minutes; int hours, minutes;
minutes=(t/60)%60; minutes=(t/60)%60;
hours=t/60/60; hours=t/60/60;
sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE),hours, minutes); #if HAS_POWER_CONSUMPTION_SENSOR
sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE" %i Wh"), hours, minutes, stoppower);
#else
sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE), hours, minutes);
#endif
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN(time); SERIAL_ECHOLN(time);
lcd_setstatus(time, true); lcd_setstatus(time, true);
...@@ -3625,6 +3632,7 @@ inline void gcode_G92() { ...@@ -3625,6 +3632,7 @@ inline void gcode_G92() {
inline void gcode_M24() { inline void gcode_M24() {
card.startFileprint(); card.startFileprint();
starttime = millis(); starttime = millis();
startpower = power_consumption_hour;
} }
// M25: Pause SD Print // M25: Pause SD Print
...@@ -3715,8 +3723,10 @@ inline void gcode_M31() { ...@@ -3715,8 +3723,10 @@ inline void gcode_M31() {
card.setIndex(code_value_long()); card.setIndex(code_value_long());
card.startFileprint(); card.startFileprint();
if (!call_procedure) if (!call_procedure) {
starttime = millis(); //procedure calls count as normal print time. starttime = millis(); //procedure calls count as normal print time.
startpower = power_consumption_hour;
}
} }
} }
......
...@@ -280,11 +280,24 @@ static void lcd_implementation_status_screen() { ...@@ -280,11 +280,24 @@ static void lcd_implementation_status_screen() {
u8g.setPrintPos(80,48); u8g.setPrintPos(80,48);
if (starttime != 0) { if (starttime != 0) {
#if HAS_LCD_POWER_SENSOR
if (millis() < print_millis + 1000) {
uint16_t time = (millis() - starttime) / 60000; uint16_t time = (millis() - starttime) / 60000;
lcd_print(itostr2(time/60)); lcd_print(itostr2(time/60));
lcd_print(':'); lcd_print(':');
lcd_print(itostr2(time%60)); lcd_print(itostr2(time%60));
} }
else {
lcd_print(itostr4(power_consumption_hour-startpower));
lcd_print('Wh');
}
#else
uint16_t time = (millis() - starttime) / 60000;
lcd_print(itostr2(time/60));
lcd_print(':');
lcd_print(itostr2(time%60));
#endif
}
else { else {
lcd_printPGM(PSTR("--:--")); lcd_printPGM(PSTR("--:--"));
} }
...@@ -358,12 +371,13 @@ static void lcd_implementation_status_screen() { ...@@ -358,12 +371,13 @@ static void lcd_implementation_status_screen() {
#else #else
u8g.setPrintPos(0,63); u8g.setPrintPos(0,63);
#endif #endif
#if HAS_FILAMENT_SENSOR || HAS_POWER_CONSUMPTION_SENSOR
#if HAS_LCD_FILAMENT_SENSOR || HAS_LCD_POWER_SENSOR
if (millis() < message_millis + 5000) { //Display both Status message line and Filament display on the last line if (millis() < message_millis + 5000) { //Display both Status message line and Filament display on the last line
lcd_print(lcd_status_message); lcd_print(lcd_status_message);
} }
#if HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY) #if HAS_LCD_POWER_SENSOR
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY) #if HAS_LCD_FILAMENT_SENSOR
else if (millis() < message_millis + 10000) else if (millis() < message_millis + 10000)
#else #else
else else
...@@ -376,7 +390,7 @@ static void lcd_implementation_status_screen() { ...@@ -376,7 +390,7 @@ static void lcd_implementation_status_screen() {
lcd_printPGM(PSTR("Wh")); lcd_printPGM(PSTR("Wh"));
} }
#endif #endif
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY) #if HAS_LCD_FILAMENT_SENSOR
else { else {
lcd_printPGM(PSTR("D:")); lcd_printPGM(PSTR("D:"));
lcd_print(ftostr12ns(filament_width_meas)); lcd_print(ftostr12ns(filament_width_meas));
......
...@@ -33,10 +33,14 @@ int gumPreheatFanSpeed; ...@@ -33,10 +33,14 @@ int gumPreheatFanSpeed;
const long baudrates[] = {9600,14400,19200,28800,38400,56000,115200,250000}; const long baudrates[] = {9600,14400,19200,28800,38400,56000,115200,250000};
int baudrate_position = -1; int baudrate_position = -1;
#if (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY)) || (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY)) #if HAS_LCD_FILAMENT_SENSOR || HAS_LCD_POWER_SENSOR
unsigned long message_millis = 0; unsigned long message_millis = 0;
#endif #endif
#if HAS_LCD_POWER_SENSOR
unsigned long print_millis = 0;
#endif
/* !Configuration settings */ /* !Configuration settings */
//Function pointer to menu functions. //Function pointer to menu functions.
...@@ -315,6 +319,21 @@ static void lcd_status_screen() ...@@ -315,6 +319,21 @@ static void lcd_status_screen()
lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */ lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
} }
#if HAS_LCD_POWER_SENSOR
if (millis() > print_millis + 2000) print_millis = millis();
#endif
#if HAS_LCD_FILAMENT_SENSOR || HAS_LCD_POWER_SENSOR
#if HAS_LCD_FILAMENT_SENSOR && HAS_LCD_POWER_SENSOR
if (millis() > message_millis + 15000)
#else
if (millis() > message_millis + 10000)
#endif
{
message_millis = millis();
}
#endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
bool current_click = LCD_CLICKED; bool current_click = LCD_CLICKED;
...@@ -343,16 +362,6 @@ static void lcd_status_screen() ...@@ -343,16 +362,6 @@ static void lcd_status_screen()
currentMenu == lcd_status_screen currentMenu == lcd_status_screen
#endif #endif
); );
#if (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY)) || (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY))
#if (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY)) && (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY))
if (millis() > message_millis + 15000)
#else
if (millis() > message_millis + 10000)
#endif
{
message_millis = millis();
}
#endif
} }
#ifdef ULTIPANEL_FEEDMULTIPLY #ifdef ULTIPANEL_FEEDMULTIPLY
...@@ -1618,10 +1627,6 @@ void lcd_finishstatus(bool persist=false) { ...@@ -1618,10 +1627,6 @@ void lcd_finishstatus(bool persist=false) {
#endif #endif
#endif #endif
lcdDrawUpdate = 2; lcdDrawUpdate = 2;
#ifdef FILAMENT_LCD_DISPLAY
message_millis = millis(); //get status message to show up for a while
#endif
} }
#if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0 #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
......
...@@ -586,13 +586,27 @@ static void lcd_implementation_status_screen() ...@@ -586,13 +586,27 @@ static void lcd_implementation_status_screen()
#endif //SDSUPPORT #endif //SDSUPPORT
#endif //LCD_WIDTH > 19 #endif //LCD_WIDTH > 19
lcd.setCursor(LCD_WIDTH - 6, 2); lcd.setCursor(LCD_WIDTH - 6, 2);
lcd.print(LCD_STR_CLOCK[0]);
if(starttime != 0) if(starttime != 0)
{ {
#if HAS_LCD_POWER_SENSOR
if (millis() < print_millis + 1000) {
lcd.print(LCD_STR_CLOCK[0]);
uint16_t time = millis()/60000 - starttime/60000;
lcd.print(itostr2(time/60));
lcd.print(':');
lcd.print(itostr2(time%60));
}
else {
lcd.print(itostr4(power_consumption_hour-startpower));
lcd.print('Wh');
}
#else
lcd.print(LCD_STR_CLOCK[0]);
uint16_t time = millis()/60000 - starttime/60000; uint16_t time = millis()/60000 - starttime/60000;
lcd.print(itostr2(time/60)); lcd.print(itostr2(time/60));
lcd.print(':'); lcd.print(':');
lcd.print(itostr2(time%60)); lcd.print(itostr2(time%60));
#endif
} }
else { else {
lcd_printPGM(PSTR("--:--")); lcd_printPGM(PSTR("--:--"));
...@@ -627,12 +641,12 @@ static void lcd_implementation_status_screen() ...@@ -627,12 +641,12 @@ static void lcd_implementation_status_screen()
#endif //LCD_PROGRESS_BAR #endif //LCD_PROGRESS_BAR
//Display both Status message line and Filament display on the last line //Display both Status message line and Filament display on the last line
#if (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY)) || (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY)) #if HAS_LCD_FILAMENT_SENSOR || HAS_LCD_POWER_SENSOR
if (millis() < message_millis + 5000) { //Display both Status message line and Filament display on the last line if (millis() < message_millis + 5000) { //Display both Status message line and Filament display on the last line
lcd_print(lcd_status_message); lcd_print(lcd_status_message);
} }
#if HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY) #if HAS_LCD_POWER_SENSOR
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY) #if HAS_LCD_FILAMENT_SENSOR
else if (millis() < message_millis + 10000) else if (millis() < message_millis + 10000)
#else #else
else else
...@@ -645,7 +659,7 @@ static void lcd_implementation_status_screen() ...@@ -645,7 +659,7 @@ static void lcd_implementation_status_screen()
lcd_printPGM(PSTR("Wh")); lcd_printPGM(PSTR("Wh"));
} }
#endif #endif
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY) #if HAS_LCD_FILAMENT_SENSOR
else { else {
lcd_printPGM(PSTR("D:")); lcd_printPGM(PSTR("D:"));
lcd.print(ftostr12ns(filament_width_meas)); lcd.print(ftostr12ns(filament_width_meas));
......
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