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