diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,6 @@ #include "interrupts.h" -therm_settings_t set; therm_status_t status; pid_state_t pid_state; @@ -38,15 +37,7 @@ int main(void) ssd1306_drawlogo(); - watchdog_init(); - //just some example code for getting flash values -// flash_getsettings()->values.can_id = 67; -// -// if(flash_getsettings()->values.can_id == 12); - -// ssd1306_drawstring(const char *dataPtr, unsigned char row, unsigned char xPos) -// ssd1306_drawstring("[ ProtoFuse ]", 0, 0); // Default status status.temp = 0; @@ -59,15 +50,10 @@ int main(void) pid_init(&pid_state); flash_init(); + watchdog_init(); - float temp_counter = 0; - - // Software timers - uint32_t last_screen_update_time = HAL_GetTick(); - - - // Soft timers + // Soft timers uint32_t last_ssr_on = 0; uint32_t last_vcp_tx = 0; uint32_t last_led = 0; @@ -80,7 +66,7 @@ int main(void) while (1) { - if(set.val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD)) + if(flash_getsettings()->val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD)) { // #ifdef MAX31865_RTD_SENSOR @@ -93,9 +79,9 @@ int main(void) if(status.pid_enabled) { // Get ssr output for next time - int16_t power_percent = pid_update(&set, &status, &pid_state); + int16_t power_percent = pid_update(flash_getsettings(), &status, &pid_state); - if(set.val.plant_type == PLANT_HEATER) + if(flash_getsettings()->val.plant_type == PLANT_HEATER) power_percent *= -1; //power-percent is 0-1000? @@ -144,7 +130,7 @@ int main(void) // Thermostatic control - if(set.val.control_mode == MODE_THERMOSTAT && HAL_GetTick() - last_thermostat > SSR_PERIOD) + if(flash_getsettings()->val.control_mode == MODE_THERMOSTAT && HAL_GetTick() - last_thermostat > SSR_PERIOD) { // #ifdef MAX31865_RTD_SENSOR @@ -160,14 +146,14 @@ int main(void) // EMZ FIXME: This could be way simpler - if(set.val.plant_type == PLANT_HEATER && status.setpoint * 10 < temp - set.val.hysteresis * 10) + if(flash_getsettings()->val.plant_type == PLANT_HEATER && status.setpoint * 10 < temp - flash_getsettings()->val.hysteresis * 10) thermostat_plant_on = 1; - else if(set.val.plant_type == PLANT_HEATER && status.setpoint * 10 > temp + set.val.hysteresis * 10) + else if(flash_getsettings()->val.plant_type == PLANT_HEATER && status.setpoint * 10 > temp + flash_getsettings()->val.hysteresis * 10) thermostat_plant_on = 0; - if(set.val.plant_type == PLANT_COOLER && status.setpoint * 10 > temp + set.val.hysteresis * 10) + if(flash_getsettings()->val.plant_type == PLANT_COOLER && status.setpoint * 10 > temp + flash_getsettings()->val.hysteresis * 10) thermostat_plant_on = 1; - else if(set.val.plant_type == PLANT_COOLER && status.setpoint * 10 < temp - set.val.hysteresis * 10) + else if(flash_getsettings()->val.plant_type == PLANT_COOLER && status.setpoint * 10 < temp - flash_getsettings()->val.hysteresis * 10) thermostat_plant_on = 0; // EMZ: TODO: Refactor to output_enabled or something @@ -182,13 +168,13 @@ int main(void) - HAL_GPIO_WritePin(SSR_PIN, 1); - HAL_GPIO_WritePin(LED_POWER, 1); +// HAL_GPIO_WritePin(SSR_PIN, 1); + HAL_GPIO_WritePin(LED, 1); } else { - HAL_GPIO_WritePin(SSR_PIN, 0); - HAL_GPIO_WritePin(LED_POWER, 0); +// HAL_GPIO_WritePin(SSR_PIN, 0); + HAL_GPIO_WritePin(LED, 0); } last_thermostat = HAL_GetTick(); @@ -213,7 +199,7 @@ int main(void) // } // Run state machine - display_process(&set, &status); + display_process(&status); watchdog_feed(); }