Files
@ 752fd27f607a
Branch filter:
Location: therm-ng/src/main.c - annotation
752fd27f607a
2.5 KiB
text/plain
Basic code cleanup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | f94ab6abb81d f94ab6abb81d 02c66b160d15 f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d a710d1e0fc2a 2b4eb31dd8da f94ab6abb81d 2b4eb31dd8da a710d1e0fc2a f94ab6abb81d f94ab6abb81d 667b32311f8f 2b4eb31dd8da a710d1e0fc2a a710d1e0fc2a f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d a710d1e0fc2a f94ab6abb81d a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a 953c718ee4cf f94ab6abb81d f94ab6abb81d 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da f94ab6abb81d 2b4eb31dd8da 2b4eb31dd8da a710d1e0fc2a 72630eaa8151 2b4eb31dd8da a710d1e0fc2a 72630eaa8151 a710d1e0fc2a a710d1e0fc2a 9030f018bc25 953c718ee4cf a710d1e0fc2a 7fc667dd7f38 f153d4ca027c f94ab6abb81d f94ab6abb81d a710d1e0fc2a 9030f018bc25 9030f018bc25 9030f018bc25 9030f018bc25 9030f018bc25 9030f018bc25 953c718ee4cf 953c718ee4cf 953c718ee4cf 573011597aec 953c718ee4cf 953c718ee4cf 953c718ee4cf 72630eaa8151 a710d1e0fc2a 953c718ee4cf a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a 72630eaa8151 a710d1e0fc2a 953c718ee4cf a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a f153d4ca027c 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a a710d1e0fc2a f94ab6abb81d f94ab6abb81d f94ab6abb81d f94ab6abb81d | //
// Therm Firmware
// Copyright 2018 Ethan Zonca
// Author(s): Ethan Zonca
//
#include "stm32f3xx_hal.h"
#include "config.h"
#include "watchdog.h"
#include "system.h"
#include "display.h"
#include "thermostat.h"
#include "gpio.h"
#include "tempsense.h"
#include "pid.h"
#include "error.h"
#include "flash.h"
#include "ssd1306/ssd1306.h"
#include "pwmout.h"
int main(void)
{
sysclock_init();
hal_init();
gpio_init();
ssd1306_init();
// Startup screen
display_startup_screen();
HAL_Delay(2000);
ssd1306_clearscreen();
ssd1306_drawlogo();
// Default status
runtime_status()->temp = 0.0;
runtime_status()->state_resume = 0;
runtime_status()->state = STATE_IDLE;
runtime_status()->setpoint = 70;
runtime_status()->pid_enabled = 0;
pid_init();
pwmout_init();
flash_init();
watchdog_init();
tempsense_init();
// Soft timers
uint32_t last_pid = 0;
uint32_t last_thermostat = 0;
uint32_t last_1hz = 0;
uint32_t last_5hz = 0;
int16_t duty = 0;
while (1)
{
if(HAL_GetTick() - last_1hz > 750)
{
display_1hz();
last_1hz = HAL_GetTick();
}
if(HAL_GetTick() - last_5hz > 200)
{
tempsense_readtemp();
runtime_status()->temp = tempsense_gettemp();
last_5hz = HAL_GetTick();
}
if(flash_getsettings()->val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD))
{
duty = pid_process();
last_pid = HAL_GetTick();
}
// Thermostatic control
if(flash_getsettings()->val.control_mode == MODE_THERMOSTAT && HAL_GetTick() - last_thermostat > SSR_PERIOD)
{
duty = thermostat_process();
last_thermostat = HAL_GetTick();
}
pwmout_process((int16_t)duty);
display_process();
watchdog_feed();
// // Transmit temperature over USB-CDC on a regular basis
// if(HAL_GetTick() - last_vcp_tx > VCP_TX_FREQ)
// {
// // Print temp to cdc
// char tempstr[16];
// itoa_fp(status.temp, status.temp_frac, tempstr);
// uint8_t numlen = strlen(tempstr);
// tempstr[numlen] = '\r';
// tempstr[numlen+1] = '\n';
//
// // if(set.val.usb_plugged)
// // CDC_Transmit_FS(tempstr, numlen+2);
// // while(CDC_Transmit_FS("\r\n", 2) == USBD_BUSY);
//
// last_vcp_tx = HAL_GetTick();
// }
}
}
|