fix smaller bugs in Menu code and implement first test of main menu with one functional sunbmenu for the safety parameters

This commit is contained in:
2020-06-12 01:35:37 +02:00
parent d6e489bb61
commit e627cb67a5
6 changed files with 187 additions and 50 deletions

View File

@@ -34,21 +34,19 @@
#include <reflow-controller/systick.h>
#include <reflow-controller/adc-meas.h>
#include <reflow-controller/shell.h>
#include <reflow-controller/ui/lcd.h>
#include <reflow-controller/digio.h>
#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
#include <reflow-controller/temp-converter.h>
#include <reflow-controller/rotary-encoder.h>
#include <reflow-controller/pid-controller.h>
#include <stm-periph/stm32-gpio-macros.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/uart.h>
#include <reflow-controller/shell-uart-config.h>
#include <helper-macros/helper-macros.h>
#include <reflow-controller/button.h>
#include <reflow-controller/oven-driver.h>
#include <reflow-controller/safety-adc.h>
#include <fatfs/ff.h>
#include <reflow-controller/lcd-menu.h>
static void setup_nvic_priorities()
{
@@ -67,7 +65,6 @@ static volatile int pt1000_value_status;
static uint32_t rot;
static float target_temperature;
static struct pid_controller pid;
static volatile enum button_state button;
FATFS fs;
FATFS *fs_ptr = &fs;
@@ -175,9 +172,7 @@ static inline void setup_system()
digio_setup_default_all();
led_setup();
loudspeaker_setup();
rotary_encoder_setup();
button_init();
lcd_init();
reflow_menu_init();
safety_adc_init();
uart_gpio_config();
@@ -204,15 +199,13 @@ 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;
char disp[4][21] = {0};
enum lcd_fsm_ret lcd_ret = LCD_FSM_NOP;
int temp_status;
float current_temp;
int menu_wait_request;
target_temperature = 25.0f;
@@ -224,13 +217,10 @@ int main()
pid_init(&pid, 0.1, 0.1, 4.0, 0.0, 100.0, 40.0, 0.25);
pid_zero(&pid);
snprintf(&disp[2][0], 17, " \xBC\xCF\xAF\xC0 Reflow");
while (1) {
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
snprintf(&disp[0][0], 17, "SD %smounted", sd_card_mounted ? "" : "un");
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
if (systick_ticks_have_passed(pid_timestamp, 250)) {
@@ -250,9 +240,6 @@ int main()
led_set(0, !led_get(0));
else
led_set(0, 0);
snprintf(&disp[3][0], 17, "Temp: %s%.1f ""\xDF""C", (temp_status == 0 ? "" : temp_status < 0 ? "<" : ">")
, current_temp);
}
/* Handle error in case PID controller should be active, but temperature measurement failed */
@@ -267,35 +254,15 @@ int main()
oven_driver_set_power(pid_controller_output < 0 ? 0U : (uint8_t)pid_controller_output);
}
button = button_read_event();
if (button == BUTTON_SHORT_RELEASED) {
rotary_encoder_zero();
} else if (button == BUTTON_LONG_RELEASED) {
adc_pt1000_clear_error();
}
rot = rotary_encoder_get_abs_val();
oven_driver_set_power(rot > 100U ? 100U : rot);
/* TODO: handle gui */
snprintf(&disp[1][0], 17, "Rot: %u %s", (unsigned int)rot, (button == BUTTON_SHORT ? "SHORT" : (button == BUTTON_LONG ? "LONG" : "")));
handle_shell_uart_input(shell_handle);
if (systick_ticks_have_passed(display_timestamp, 2) || lcd_ret == LCD_FSM_CALL_AGAIN) {
lcd_ret = lcd_fsm_write_buffer(disp);
display_timestamp = systick_get_global_tick();
}
if (lcd_ret == LCD_FSM_CALL_AGAIN) {
/* Nothing */
} else {
menu_wait_request = reflow_menu_handle();
if (!menu_wait_request)
__WFI();
}
}
}