Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sfrwmaker authored Apr 24, 2020
1 parent 43293b4 commit 90cb620
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
20 changes: 17 additions & 3 deletions cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void IRON_CFG::init(void) {
}
removeTipDuplication();
tip_index = selectTip(Config.tip);
memcpy(&previous_cfg, &Config, sizeof(struct cfg));
}

void IRON_CFG::setLowPower(uint16_t low_temp, uint8_t low_to, bool reed) {
Expand Down Expand Up @@ -241,7 +242,7 @@ bool IRON_CFG::savePresetTempHuman(uint16_t temp) {
Config.temp = temp;
// When the tip changed, tip_index updated, but congiguration data remained the same
Config.tip = tip_index;
return CONFIG::save();
return save();
}

bool IRON_CFG::savePresetTemp(uint16_t temp) {
Expand Down Expand Up @@ -272,14 +273,14 @@ void IRON_CFG::saveConfig(uint8_t off, bool cels, bool buzzer, bool ambient) {
if (cfg_celsius != cels) { // Need to translate preset temperature
if (cels) { // Convert the preset temperature from Fahrenheit to Celsius
Config.temp = map(Config.temp, temp_minF, temp_maxF, temp_minC, temp_maxC);
Config.bit_mask |= CFG_CELSIUS;
} else { // Convert the preset temperature from Celsius to Fahrenheit
Config.temp = map(Config.temp, temp_minC, temp_maxC, temp_minF, temp_maxF);
}
}
if (cels) Config.bit_mask |= CFG_CELSIUS;
if (buzzer) Config.bit_mask |= CFG_BUZZER;
if (ambient) Config.bit_mask |= CFG_THERM;
CONFIG::save(); // Save new data into the EEPROM
save(); // Save new data into the EEPROM
}

void IRON_CFG::getCalibrationData(uint16_t tip[3]) {
Expand Down Expand Up @@ -380,6 +381,19 @@ bool IRON_CFG::toggleTipActivation(uint8_t global_index) {
return tip_data.mask & TIP_ACTIVE;
}

bool IRON_CFG::save(void) {
if (memcmp(&Config, &previous_cfg, sizeof(struct cfg)) != 0) {
Serial.print(F("update temp: ")); Serial.print(Config.temp);
Serial.print(F(", tip: ")); Serial.print(Config.tip);
Serial.print(F(", lo_temp: ")); Serial.print(Config.low_temp);
Serial.print(F(", lo_to: ")); Serial.print(Config.low_to);
Serial.print(F(", off: ")); Serial.print(Config.off_timeout);
Serial.print(F(", mask: ")); Serial.println(Config.bit_mask, BIN);
CONFIG::save();
memcpy(&previous_cfg, &Config, sizeof(struct cfg));
}
}

bool IRON_CFG::checkTipCRC(TIP& tip_data, bool write) {
uint8_t *buff = (uint8_t *)&tip_data;
uint8_t summ = 17; // Do not allow all-zero data
Expand Down
2 changes: 2 additions & 0 deletions cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class IRON_CFG : public CONFIG, public TIPS {
bool isTipActive(uint8_t global_index);
bool toggleTipActivation(uint8_t global_index);
private:
bool save(void); // Save configuration data (if updated)
bool checkTipCRC(TIP& tip_data, bool write = false);
bool loadTipData(TIP* tip_data, uint8_t index);
bool validateTip(TIP& tip_data); // Validate the IRON tip calibration
Expand All @@ -94,6 +95,7 @@ class IRON_CFG : public CONFIG, public TIPS {
int8_t emptyTipSlot(void); // Unused Tip slot idex in EEPROM area or -1 if not found
void removeTipDuplication(void);
char tip_name[tip_name_sz+1];
struct cfg previous_cfg; // The loaded config
uint16_t t_tip[3] = {0}; // The current tip calibration
uint8_t tip_index = 0; // The current tip index (EEPROM customized array)
uint8_t tip_mask = 0; // The current tip status (see TIP_STATUS in iron_tips.h)
Expand Down
13 changes: 6 additions & 7 deletions hakko_t12.ino
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ bool IRON::checkIron(void) {
void IRON::keepTemp(void) {
uint16_t ambient = analogRead(aPIN); // Update ambient temperature
amb_int.update(ambient);
uint16_t t = analogRead(sPIN); // Reat the IRON temperature
uint16_t t = analogRead(sPIN); // Read the IRON temperature
volatile uint16_t t_set = temp_set; // The preset temperature depends on usual/low power mode
if (temp_low) t_set = temp_low;

Expand Down Expand Up @@ -354,7 +354,6 @@ void IRON::keepTemp(void) {
}
p = PID::reqPower(t_set, t);
p = constrain(p, 0, max_power);
if (disconnected) p = 0; // Do not supply power if iron disconnected
break;
case POWER_FIXED:
p = fix_power;
Expand Down Expand Up @@ -803,7 +802,7 @@ SCREEN* workSCREEN::show(void) {
int ap = pIron->getAvgPower();
uint16_t low_temp = pCfg->lowTemp(); // 'Standby temperature' setup in the main menu

if ((abs(temp_set - temp) < 3) && (pIron->tempDispersion() <= 5) && (ap > 0)) {
if ((abs(temp_set - temp) < 3) && (pIron->tempDispersion() <= 10) && (ap > 0)) {
if (!ready) {
pBz->shortBeep();
ready = true;
Expand All @@ -824,10 +823,10 @@ SCREEN* workSCREEN::show(void) {
if (low_temp && ready && pCfg->getOffTimeout()) { // The IRON has reaches the preset temperature
hwTimeout(low_temp, tilt_active); // Use hardware tilt switch to turn low power mode
}

if (!lowpower_mode && pCfg->isAmbientSensor())
adjustPresetTemp();

uint32_t to = (time_to_return - millis()) / 1000;
if (ready) {
if (scr_timeout > 0 && (to < 100)) {
Expand Down Expand Up @@ -1653,10 +1652,10 @@ SCREEN *pCurrentScreen = &offScr;
* The timer1 overflow interrupt handler.
* Activates the procedure for IRON current check or for IRON temperature check
* Interrupt routine on Timer1 overflow, @31250 Hz, 32 microseconds is a timer period
* keepTemp() function takes 353 mks, about 12 ticks of TIMER1; For sure, we use 15
* keepTemp() function takes 353 mks, about 12 ticks of TIMER1;
* We should wait for 33 timer ticks before checking the temperature after iron was powered off
*/
const uint32_t period_ticks = (31250 * temp_check_period)/1000-33-15;
const uint32_t period_ticks = (31250 * temp_check_period)/1000-33-12;
ISR(TIMER1_OVF_vect) {
if (iron_off) { // The IRON is switched off, we need to check the temperature
if (++tmr1_count >= 33) { // about 1 millisecond
Expand Down

0 comments on commit 90cb620

Please sign in to comment.