Commit f79c182b authored by MagoKimbra's avatar MagoKimbra

Add SDSETTINGS

parent 7e2bd53c
......@@ -432,6 +432,14 @@
//#define DISABLE_M503
//===========================================================================
//========================== EXTRA SETTINGS ON SD ===========================
// Uncomment SD SETTINGS to enable the firmware to write some configuration, that require frequent update, on the SD card.
//#define SD_SETTINGS
#define SD_CFG_SECONDS 300 //seconds between update
#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
//===========================================================================
//==================== Bowden Filament management ===========================
//#define EASY_LOAD
......
......@@ -259,7 +259,6 @@ extern float zprobe_zoffset;
// 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 millis_t config_last_update;
#ifdef PREVENT_DANGEROUS_EXTRUDE
extern float extrude_min_temp;
......@@ -312,6 +311,11 @@ extern int fanSpeed;
extern int laser_ttl_modulation;
#endif
#if defined(SDSUPPORT) && defined(SD_SETTINGS)
extern millis_t config_last_update;
extern bool config_readed;
#endif
extern millis_t print_job_start_ms;
extern millis_t print_job_stop_ms;
......
......@@ -282,6 +282,8 @@ static uint8_t target_extruder;
bool no_wait_for_cooling = true;
bool target_direction;
unsigned long printer_usage_seconds;
#ifndef DELTA
int xy_travel_speed = XY_TRAVEL_SPEED;
float zprobe_zoffset = 0;
......@@ -421,6 +423,10 @@ bool target_direction;
#ifdef SDSUPPORT
static bool fromsd[BUFSIZE];
#ifdef SD_SETTINGS
millis_t config_last_update = 0;
bool config_readed = false;
#endif
#endif
#ifdef FILAMENTCHANGEENABLE
......@@ -499,7 +505,7 @@ bool setTargetedHotend(int code);
return free_memory;
}
}
#endif //!SDSUPPORT
#endif // !SDSUPPORT
#endif
/**
......@@ -705,6 +711,9 @@ void setup() {
for (int8_t i = 0; i < BUFSIZE; i++) fromsd[i] = false;
#endif
// loads custom configuration from SDCARD if available else uses defaults
ConfigSD_RetrieveSettings();
// loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
Config_RetrieveSettings();
......@@ -7047,6 +7056,18 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
}
#endif
#if defined(SDSUPPORT) && defined(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
#ifdef TEMP_STAT_LEDS
handle_status_leds();
#endif
......
......@@ -150,7 +150,7 @@ void CardReader::initsd() {
}
else {
cardOK = true;
ECHO_LM(DB, MSG_SD_CARD_OK);
ECHO_LM(OK, MSG_SD_CARD_OK);
}
workDir = root;
curDir = &root;
......
This diff is collapsed.
......@@ -4,11 +4,14 @@
#include "Configuration.h"
void Config_ResetDefault();
void ConfigSD_ResetDefault();
#ifndef DISABLE_M503
void Config_PrintSettings(bool forReplay=false);
void Config_PrintSettings(bool forReplay = false);
void ConfigSD_PrintSettings(bool forReplay = false);
#else
FORCE_INLINE void Config_PrintSettings(bool forReplay=false) {}
FORCE_INLINE void ConfigSD_PrintSettings(bool forReplay = false) {}
#endif
#ifdef EEPROM_SETTINGS
......@@ -19,4 +22,27 @@ void Config_ResetDefault();
FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_PrintSettings(); }
#endif
#if defined(SDSUPPORT) && defined(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.)
#ifdef POWER_CONSUMPTION
"PWR",
#endif
"TME",
};
enum cfgSD_ENUM { //This need to be in the same order as cfgSD_KEY
#ifdef POWER_CONSUMPTION
SD_CFG_PWR,
#endif
SD_CFG_TME,
SD_CFG_END //Leave this always as the last
};
void ConfigSD_StoreSettings();
void ConfigSD_RetrieveSettings(bool addValue = false);
int ConfigSD_KeyIndex(char *key);
#else
FORCE_INLINE void ConfigSD_RetrieveSettings() { ConfigSD_ResetDefault(); }
#endif
#endif //CONFIGURATION_STORE_H
......@@ -48,4 +48,5 @@
//============================================================================
//============================================================================
......@@ -779,6 +779,7 @@ static float analog2tempBed(int raw) {
static void updateTemperaturesFromRawValues() {
static millis_t last_update = millis();
millis_t temp_last_update = millis();
millis_t from_last_update = temp_last_update - last_update;
#ifdef HEATER_0_USES_MAX6675
current_temperature_raw[0] = read_max6675();
#endif
......@@ -793,7 +794,6 @@ static void updateTemperaturesFromRawValues() {
filament_width_meas = analog2widthFil();
#endif
#if HAS_POWER_CONSUMPTION_SENSOR
millis_t from_last_update = temp_last_update - last_update;
static float watt_overflow = 0.0;
power_consumption_meas = analog2power();
//MYSERIAL.println(analog2current(),3);
......@@ -804,7 +804,16 @@ static void updateTemperaturesFromRawValues() {
}
#endif
//Reset the watchdog after we know we have a temperature measurement.
// Update printer usage
static unsigned int second_overflow = 0;
second_overflow += from_last_update;
if (second_overflow >= 1000) {
printer_usage_seconds++;
second_overflow -= 1000;
}
last_update = temp_last_update;
// Reset the watchdog after we know we have a temperature measurement.
watchdog_reset();
CRITICAL_SECTION_START;
......@@ -818,7 +827,7 @@ static void updateTemperaturesFromRawValues() {
// Convert raw Filament Width to millimeters
float analog2widthFil() {
return current_raw_filwidth / 16383.0 * 5.0;
//return current_raw_filwidth;
// return current_raw_filwidth;
}
// Convert raw Filament Width to a ratio
......@@ -849,7 +858,7 @@ static void updateTemperaturesFromRawValues() {
*/
void tp_init() {
#if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
//disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
// disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
MCUCR=BIT(JTD);
MCUCR=BIT(JTD);
#endif
......@@ -865,7 +874,7 @@ void tp_init() {
#ifdef PIDTEMPBED
temp_iState_min_bed = 0.0;
temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi;
#endif //PIDTEMPBED
#endif // PIDTEMPBED
}
#if HAS_HEATER_0
......@@ -906,7 +915,7 @@ void tp_init() {
OUT_WRITE(MAX6675_SS,HIGH);
#endif //HEATER_0_USES_MAX6675
#endif // HEATER_0_USES_MAX6675
#ifdef __SAM3X8E__
// Use timer0 for temperature measurement
......@@ -1025,7 +1034,7 @@ void tp_init() {
bed_maxttemp_raw += OVERSAMPLENR;
#endif
}
#endif //BED_MAXTEMP
#endif // BED_MAXTEMP
}
#ifdef THERMAL_PROTECTION_HOTENDS
......@@ -1169,8 +1178,8 @@ void disable_all_heaters() {
WRITE(MAX6675_SS, 0);
// ensure 100ns delay - a bit extra is fine
asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
asm("nop");// 50ns on 20Mhz, 62.5ns on 16Mhz
asm("nop");// 50ns on 20Mhz, 62.5ns on 16Mhz
// read MSB
SPDR = 0;
......@@ -1197,7 +1206,7 @@ void disable_all_heaters() {
return max6675_temp;
}
#endif //HEATER_0_USES_MAX6675
#endif // HEATER_0_USES_MAX6675
/**
* Stages in the ISR loop
......@@ -1429,7 +1438,7 @@ ISR(TIMER0_COMPB_vect) {
WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
}
if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
#endif //FAN_SOFT_PWM
#endif // FAN_SOFT_PWM
pwm_count += BIT(SOFT_PWM_SCALE);
pwm_count &= 0x7f;
......
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