Add about command to menu and restructure code. Delete preliminary code from mainloop. Better code will follow
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
#include <reflow-controller/oven-driver.h>
|
||||
#include <reflow-controller/safety-adc.h>
|
||||
#include <fatfs/ff.h>
|
||||
#include <reflow-controller/lcd-menu.h>
|
||||
#include <reflow-controller/reflow-menu.h>
|
||||
|
||||
static void setup_nvic_priorities()
|
||||
{
|
||||
@@ -60,9 +60,6 @@ static void setup_nvic_priorities()
|
||||
}
|
||||
|
||||
/* Process parameters are defined static globally to be watched in debugger from any context */
|
||||
static float pt1000_value;
|
||||
static volatile int pt1000_value_status;
|
||||
static uint32_t rot;
|
||||
static float target_temperature;
|
||||
static struct pid_controller pid;
|
||||
|
||||
@@ -96,7 +93,7 @@ static shellmatta_retCode_t write_shell_callback(const char *data, uint32_t len)
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
static inline void setup_sell_uart(struct stm_uart *uart)
|
||||
static inline void setup_shell_uart(struct stm_uart *uart)
|
||||
{
|
||||
uart->rx = 1;
|
||||
uart->tx = 1;
|
||||
@@ -176,7 +173,7 @@ static inline void setup_system()
|
||||
safety_adc_init();
|
||||
|
||||
uart_gpio_config();
|
||||
setup_sell_uart(&shell_uart);
|
||||
setup_shell_uart(&shell_uart);
|
||||
|
||||
setup_unused_pins();
|
||||
}
|
||||
@@ -187,28 +184,36 @@ static void handle_shell_uart_input(shellmatta_handle_t shell_handle)
|
||||
const char *uart_input;
|
||||
size_t uart_input_len;
|
||||
|
||||
/* Handle uart input for shell */
|
||||
/* Handle UART input for shell */
|
||||
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
|
||||
if (uart_receive_status >= 0)
|
||||
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
||||
}
|
||||
|
||||
extern char _sccmram;
|
||||
extern char _eccmram;
|
||||
static void zero_ccm_ram(void)
|
||||
{
|
||||
uint32_t len;
|
||||
uint32_t i;
|
||||
uint32_t *ptr = (uint32_t *)&_sccmram;
|
||||
|
||||
len = (uint32_t)&_eccmram - (uint32_t)&_sccmram;
|
||||
for (i = 0; i < len; i++)
|
||||
ptr[i] = 0UL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool sd_card_mounted = false;
|
||||
shellmatta_handle_t shell_handle;
|
||||
uint64_t pid_timestamp = 0ULL;
|
||||
bool pid_controller_active = false;
|
||||
int32_t pid_controller_output;
|
||||
uint64_t display_timestamp = 0ULL;
|
||||
int temp_status;
|
||||
float current_temp;
|
||||
int menu_wait_request;
|
||||
uint64_t quarter_sec_timestamp = 0ULL;
|
||||
enum safety_adc_check_result safety_adc_status;
|
||||
|
||||
target_temperature = 25.0f;
|
||||
|
||||
zero_ccm_ram();
|
||||
setup_system();
|
||||
|
||||
shell_handle = shell_init(write_shell_callback);
|
||||
@@ -217,46 +222,14 @@ int main()
|
||||
pid_init(&pid, 0.1, 0.1, 4.0, 0.0, 100.0, 40.0, 0.25);
|
||||
pid_zero(&pid);
|
||||
|
||||
|
||||
while (1) {
|
||||
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
||||
|
||||
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
||||
|
||||
if (systick_ticks_have_passed(pid_timestamp, 250)) {
|
||||
|
||||
(void)handle_safety_adc();
|
||||
|
||||
pid_timestamp = systick_get_global_tick();
|
||||
|
||||
temp_status = temp_converter_convert_resistance_to_temp(pt1000_value,
|
||||
¤t_temp);
|
||||
|
||||
if (pt1000_value_status >= 0 && pid_controller_active)
|
||||
pid_controller_output = handle_pid_controller(&pid, target_temperature, current_temp);
|
||||
|
||||
/* Blink red led in case of temp error */
|
||||
if (pt1000_value_status < 0)
|
||||
led_set(0, !led_get(0));
|
||||
else
|
||||
led_set(0, 0);
|
||||
if(systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
||||
safety_adc_status = handle_safety_adc();
|
||||
quarter_sec_timestamp = systick_get_global_tick();
|
||||
}
|
||||
|
||||
/* Handle error in case PID controller should be active, but temperature measurement failed */
|
||||
if (pid_controller_active && pt1000_value_status < 0) {
|
||||
/* Disable the oven controller */
|
||||
oven_driver_set_power(0U);
|
||||
|
||||
/* Activate loundspeaker permanently */
|
||||
loudspeaker_set(100);
|
||||
} else if (pid_controller_active) {
|
||||
/* In case temperature measurement is okay and controlelr is working, write output power */
|
||||
oven_driver_set_power(pid_controller_output < 0 ? 0U : (uint8_t)pid_controller_output);
|
||||
}
|
||||
|
||||
|
||||
oven_driver_set_power(rot > 100U ? 100U : rot);
|
||||
|
||||
handle_shell_uart_input(shell_handle);
|
||||
|
||||
menu_wait_request = reflow_menu_handle();
|
||||
|
||||
Reference in New Issue
Block a user