Commit 58e2369b authored by MagoKimbra's avatar MagoKimbra

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

parents 8e6da881 937fd2ed
...@@ -950,7 +950,6 @@ void ConfigSD_ResetDefault() { ...@@ -950,7 +950,6 @@ void ConfigSD_ResetDefault() {
card.closeFile(); card.closeFile();
card.setlast(); card.setlast();
config_last_update = millis();
unset_sd_dot(); unset_sd_dot();
} }
...@@ -1008,9 +1007,9 @@ void ConfigSD_ResetDefault() { ...@@ -1008,9 +1007,9 @@ void ConfigSD_ResetDefault() {
} }
} }
print_job_counter.loaded = true;
card.closeFile(); card.closeFile();
card.setlast(); card.setlast();
config_readed = true;
unset_sd_dot(); unset_sd_dot();
} }
......
...@@ -270,10 +270,6 @@ bool software_endstops = true; ...@@ -270,10 +270,6 @@ bool software_endstops = true;
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
static bool fromsd[BUFSIZE]; static bool fromsd[BUFSIZE];
#if ENABLED(SD_SETTINGS)
millis_t config_last_update = 0;
bool config_readed = false;
#endif
#endif #endif
#if ENABLED(IDLE_OOZING_PREVENT) #if ENABLED(IDLE_OOZING_PREVENT)
...@@ -8997,18 +8993,6 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) { ...@@ -8997,18 +8993,6 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
} }
#endif #endif
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
if(IS_SD_INSERTED && !IS_SD_PRINTING) {
if (!config_readed) {
ConfigSD_RetrieveSettings(true);
ConfigSD_StoreSettings();
}
else if((millis() - config_last_update) > SD_CFG_SECONDS * 1000UL) {
ConfigSD_StoreSettings();
}
}
#endif
#if ENABLED(TEMP_STAT_LEDS) #if ENABLED(TEMP_STAT_LEDS)
handle_status_leds(); handle_status_leds();
#endif #endif
......
...@@ -240,11 +240,6 @@ extern int fanSpeed; ...@@ -240,11 +240,6 @@ extern int fanSpeed;
extern int laser_ttl_modulation; extern int laser_ttl_modulation;
#endif #endif
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
extern millis_t config_last_update;
extern bool config_readed;
#endif
// Print job timer // Print job timer
extern PrintCounter print_job_counter; extern PrintCounter print_job_counter;
......
...@@ -35,9 +35,9 @@ Endstops endstops; ...@@ -35,9 +35,9 @@ Endstops endstops;
Endstops::Endstops() { Endstops::Endstops() {
enable_globally( enable_globally(
#if ENABLED(ENDSTOPS_ONLY_FOR_HOMING) #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
true
#else
false false
#else
true
#endif #endif
); );
enable(true); enable(true);
...@@ -159,7 +159,7 @@ void Endstops::report_state() { ...@@ -159,7 +159,7 @@ void Endstops::report_state() {
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT) #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
if (abort_on_endstop_hit) { if (abort_on_endstop_hit) {
card.sdprinting = false; card.sdprinting = false;
card.closefile(); card.closeFile();
quickStop(); quickStop();
disable_all_heaters(); // switch off all heaters. disable_all_heaters(); // switch off all heaters.
} }
......
...@@ -45,6 +45,32 @@ void PrintCounter::initStats() { ...@@ -45,6 +45,32 @@ void PrintCounter::initStats() {
this->data = { 0, 0, 0, 0, 0.0 }; this->data = { 0, 0, 0, 0, 0.0 };
} }
void PrintCounter::loadStats() {
#if ENABLED(DEBUG_PRINTCOUNTER)
PrintCounter::debug(PSTR("loadStats"));
#endif
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
// Checks if the SDCARD is inserted
if(IS_SD_INSERTED && !IS_SD_PRINTING) {
ConfigSD_RetrieveSettings(true);
}
#endif
}
void PrintCounter::saveStats() {
#if ENABLED(DEBUG_PRINTCOUNTER)
PrintCounter::debug(PSTR("saveStats"));
#endif
// Refuses to save data is object is not loaded
if (!this->loaded) return;
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
ConfigSD_StoreSettings();
#endif
}
void PrintCounter::showStats() { void PrintCounter::showStats() {
char temp[30]; char temp[30];
uint32_t day, hours, minutes; uint32_t day, hours, minutes;
...@@ -81,7 +107,7 @@ void PrintCounter::showStats() { ...@@ -81,7 +107,7 @@ void PrintCounter::showStats() {
void PrintCounter::tick() { void PrintCounter::tick() {
static uint32_t update_before = millis(), static uint32_t update_before = millis(),
eeprom_before = millis(); config_last_update = millis();
uint32_t now = millis(); uint32_t now = millis();
...@@ -100,27 +126,47 @@ void PrintCounter::tick() { ...@@ -100,27 +126,47 @@ void PrintCounter::tick() {
PrintCounter::debug(PSTR("tick")); PrintCounter::debug(PSTR("tick"));
#endif #endif
} }
#if ENABLED(SDSUPPORT) && ENABLED(SD_SETTINGS)
if (!this->loaded) {
this->loadStats();
this->saveStats();
}
else if (now - config_last_update >= this->saveInterval) {
config_last_update = now;
this->saveStats();
}
#endif
} }
void PrintCounter::start() { bool PrintCounter::start() {
#if ENABLED(DEBUG_PRINTCOUNTER) #if ENABLED(DEBUG_PRINTCOUNTER)
PrintCounter::debug(PSTR("start")); PrintCounter::debug(PSTR("start"));
#endif #endif
if (!this->isPaused()) this->data.numberPrints++; bool paused = this->isPaused();
super::start();
if (super::start()) {
if (!paused) {
this->data.numberPrints++;
this->lastDuration = 0;
}
return true;
}
else return false;
} }
void PrintCounter::stop() { bool PrintCounter::stop() {
#if ENABLED(DEBUG_PRINTCOUNTER) #if ENABLED(DEBUG_PRINTCOUNTER)
PrintCounter::debug(PSTR("stop")); PrintCounter::debug(PSTR("stop"));
#endif #endif
if (!this->isRunning()) return; if (super::stop()) {
super::stop();
this->data.completePrints++; this->data.completePrints++;
this->data.printTime += this->deltaDuration(); this->data.printTime += this->deltaDuration();
this->saveStats();
}
else return false;
} }
void PrintCounter::reset() { void PrintCounter::reset() {
...@@ -128,8 +174,8 @@ void PrintCounter::reset() { ...@@ -128,8 +174,8 @@ void PrintCounter::reset() {
PrintCounter::debug(PSTR("stop")); PrintCounter::debug(PSTR("stop"));
#endif #endif
this->lastDuration = 0;
super::reset(); super::reset();
this->lastDuration = 0;
} }
#if ENABLED(DEBUG_PRINTCOUNTER) #if ENABLED(DEBUG_PRINTCOUNTER)
......
...@@ -47,6 +47,12 @@ ...@@ -47,6 +47,12 @@
*/ */
const uint16_t updateInterval = 10; const uint16_t updateInterval = 10;
/**
* @brief Interval in seconds between SDCARD saves
* @details This const value defines what will be the time between each
*/
const uint32_t saveInterval = SD_CFG_SECONDS * 1000;
/** /**
* @brief Timestamp of the last call to deltaDuration() * @brief Timestamp of the last call to deltaDuration()
* @details Stores the timestamp of the last deltaDuration(), this is * @details Stores the timestamp of the last deltaDuration(), this is
...@@ -73,11 +79,11 @@ ...@@ -73,11 +79,11 @@
PrintCounter(); PrintCounter();
/** /**
* @brief Checks if Print Statistics has been loaded * @brief Stats were loaded from SDCARD
* @details Returns true if the statistical data has been loaded. * @details If set to true it indicates if the statistical data was already
* @return bool * loaded from the SDCARD.
*/ */
bool isLoaded(); bool loaded = false;
/** /**
* @brief Resets the Print Statistics * @brief Resets the Print Statistics
...@@ -86,6 +92,18 @@ ...@@ -86,6 +92,18 @@
*/ */
void initStats(); void initStats();
/**
* @brief Loads the Print Statistics
* @details Loads the statistics from SDCARD
*/
void loadStats();
/**
* @brief Saves the Print Statistics
* @details Saves the statistics to SDCARD
*/
void saveStats();
/** /**
* @brief Serial output the Print Statistics * @brief Serial output the Print Statistics
* @details This function may change in the future, for now it directly * @details This function may change in the future, for now it directly
...@@ -96,15 +114,15 @@ ...@@ -96,15 +114,15 @@
/** /**
* @brief Loop function * @brief Loop function
* @details This function should be called at loop, it will take care of * @details This function should be called at loop, it will take care of
* periodically save the statistical data to EEPROM and do time keeping. * periodically save the statistical data to SDCARD and do time keeping.
*/ */
void tick(); void tick();
/** /**
* The following functions are being overridden * The following functions are being overridden
*/ */
void start(); bool start();
void stop(); bool stop();
void reset(); void reset();
#if ENABLED(DEBUG_PRINTCOUNTER) #if ENABLED(DEBUG_PRINTCOUNTER)
......
...@@ -27,40 +27,46 @@ Stopwatch::Stopwatch() { ...@@ -27,40 +27,46 @@ Stopwatch::Stopwatch() {
this->reset(); this->reset();
} }
void Stopwatch::stop() { bool Stopwatch::stop() {
#if ENABLED(DEBUG_STOPWATCH) #if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("stop")); Stopwatch::debug(PSTR("stop"));
#endif #endif
if (!this->isRunning()) return; if (this->isRunning() || this->isPaused()) {
this->state = STOPWATCH_STOPPED;
this->state = STPWTCH_STOPPED;
this->stopTimestamp = millis(); this->stopTimestamp = millis();
return true;
}
else return false;
} }
void Stopwatch::pause() { bool Stopwatch::pause() {
#if ENABLED(DEBUG_STOPWATCH) #if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("pause")); Stopwatch::debug(PSTR("pause"));
#endif #endif
if (!this->isRunning()) return; if (this->isRunning()) {
this->state = STOPWATCH_PAUSED;
this->state = STPWTCH_PAUSED;
this->stopTimestamp = millis(); this->stopTimestamp = millis();
return true;
}
else return false;
} }
void Stopwatch::start() { bool Stopwatch::start() {
#if ENABLED(DEBUG_STOPWATCH) #if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("start")); Stopwatch::debug(PSTR("start"));
#endif #endif
if (this->isRunning()) return; if (!this->isRunning()) {
if (this->isPaused()) this->accumulator = this->duration(); if (this->isPaused()) this->accumulator = this->duration();
else this->reset(); else this->reset();
this->state = STPWTCH_RUNNING; this->state = STOPWATCH_RUNNING;
this->startTimestamp = millis(); this->startTimestamp = millis();
return true;
}
else return false;
} }
void Stopwatch::reset() { void Stopwatch::reset() {
...@@ -68,18 +74,18 @@ void Stopwatch::reset() { ...@@ -68,18 +74,18 @@ void Stopwatch::reset() {
Stopwatch::debug(PSTR("reset")); Stopwatch::debug(PSTR("reset"));
#endif #endif
this->state = STPWTCH_STOPPED; this->state = STOPWATCH_STOPPED;
this->startTimestamp = 0; this->startTimestamp = 0;
this->stopTimestamp = 0; this->stopTimestamp = 0;
this->accumulator = 0; this->accumulator = 0;
} }
bool Stopwatch::isRunning() { bool Stopwatch::isRunning() {
return (this->state == STPWTCH_RUNNING) ? true : false; return (this->state == STOPWATCH_RUNNING) ? true : false;
} }
bool Stopwatch::isPaused() { bool Stopwatch::isPaused() {
return (this->state == STPWTCH_PAUSED) ? true : false; return (this->state == STOPWATCH_PAUSED) ? true : false;
} }
uint16_t Stopwatch::duration() { uint16_t Stopwatch::duration() {
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
//#define DEBUG_STOPWATCH //#define DEBUG_STOPWATCH
enum StopwatchState { enum StopwatchState {
STPWTCH_STOPPED, STOPWATCH_STOPPED,
STPWTCH_RUNNING, STOPWATCH_RUNNING,
STPWTCH_PAUSED STOPWATCH_PAUSED
}; };
/** /**
...@@ -54,22 +54,25 @@ ...@@ -54,22 +54,25 @@
* @brief Stops the stopwatch * @brief Stops the stopwatch
* @details Stops the running timer, it will silently ignore the request if * @details Stops the running timer, it will silently ignore the request if
* no timer is currently running. * no timer is currently running.
* @return true is method was successful
*/ */
void stop(); bool stop();
/** /**
* @brief Pauses the stopwatch * @brief Pauses the stopwatch
* @details Pauses the running timer, it will silently ignore the request if * @details Pauses the running timer, it will silently ignore the request if
* no timer is currently running. * no timer is currently running.
* @return true is method was successful
*/ */
void pause(); bool pause();
/** /**
* @brief Starts the stopwatch * @brief Starts the stopwatch
* @details Starts the timer, it will silently ignore the request if the * @details Starts the timer, it will silently ignore the request if the
* timer is already running. * timer is already running.
* @return true is method was successful
*/ */
void start(); bool start();
/** /**
* @brief Resets the stopwatch * @brief Resets the stopwatch
...@@ -80,21 +83,21 @@ ...@@ -80,21 +83,21 @@
/** /**
* @brief Checks if the timer is running * @brief Checks if the timer is running
* @details Returns true if the timer is currently running, false otherwise. * @details Returns true if the timer is currently running, false otherwise.
* @return bool * @return true if stopwatch is running
*/ */
bool isRunning(); bool isRunning();
/** /**
* @brief Checks if the timer is paused * @brief Checks if the timer is paused
* @details Returns true if the timer is currently paused, false otherwise. * @details Returns true if the timer is currently paused, false otherwise.
* @return bool * @return true if stopwatch is paused
*/ */
bool isPaused(); bool isPaused();
/** /**
* @brief Gets the running time * @brief Gets the running time
* @details Returns the total number of seconds the timer has been running. * @details Returns the total number of seconds the timer has been running.
* @return uint16_t * @return the delta since starting the stopwatch
*/ */
uint16_t duration(); uint16_t duration();
...@@ -108,4 +111,4 @@ ...@@ -108,4 +111,4 @@
#endif #endif
}; };
#endif //STOPWATCH_H #endif // STOPWATCH_H
...@@ -1402,7 +1402,6 @@ void disable_all_heaters() { ...@@ -1402,7 +1402,6 @@ void disable_all_heaters() {
return (int)max6675_temp; return (int)max6675_temp;
} }
#endif // HEATER_0_USES_MAX6675 #endif // HEATER_0_USES_MAX6675
/** /**
......
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