Add about command to menu and restructure code. Delete preliminary code from mainloop. Better code will follow

This commit is contained in:
Mario Hüttel 2020-06-13 22:47:45 +02:00
parent e627cb67a5
commit a6dc4f9b46
10 changed files with 122 additions and 94 deletions

View File

@ -41,7 +41,7 @@ CFILES += calibration.c
CFILES += temp-converter.c
CFILES += rotary-encoder.c button.c
CFILES += stack-check.c
CFILES += ui/lcd.c ui/menu.c lcd-menu.c
CFILES += ui/lcd.c ui/menu.c reflow-menu.c
#CFILES += onewire-temp-sensors.c
CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c
CFILES += pid-controller.c oven-driver.c
@ -124,7 +124,7 @@ qtproject-legacy:
find -name "*.h" | tr "\\n" " " >> $(target).pro
echo -ne "\nDEFINES += " >> $(target).pro
echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro
qtproject:
$(QUIET)rm -f $(target).files $(target).cflags $(target).config $(target).creator $(target).includes $(target).creator.user
echo "Generating source file list"
@ -134,13 +134,13 @@ qtproject:
$(QUIET)for dir in `echo $(INCLUDEPATH) | sed "s/-I//g"`; do \
find `echo "$${dir}"` -name "*.h" >> $(target).files; \
done
@echo "Generating CFLAGS File"
@echo "Generating $(target).cflags"
$(QUIET)echo "" > $(target).cflags
@echo "Generating includes files"
@echo "Generating $(target).includes"
$(QUIET)echo $(INCLUDEPATH) | sed "s/-I/,/g" | tr , '\n' | sed "/^$$/d" > $(target).includes;
@echo "Generating config file"
@echo "Generating $(target).config"
$(QUIET)echo $(DEFINES) | sed "s/-D/,#define /g" | tr , '\n' | sed "/^$$/d" > $(target).config
@echo "Generating creator file"
@echo "Generating $(target).creator"
$(QUIET)echo "[GENERAL]" > $(target).creator
-include $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d)

View File

@ -18,8 +18,8 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LCD_MENU_H__
#define __LCD_MENU_H__
#ifndef __REFLOW_MENU_H__
#define __REFLOW_MENU_H__
/**
* @brief Handle the reflow controller's LCD Menu
@ -29,4 +29,4 @@ int reflow_menu_handle(void);
void reflow_menu_init(void);
#endif /* __LCD_MENU_H__ */
#endif /* __REFLOW_MENU_H__ */

View File

@ -49,6 +49,11 @@ extern volatile uint32_t wait_tick_ms;
*/
extern volatile uint64_t global_tick_ms;
/**
* @brief Wait counter for the display. This must not be used anywhere else
*/
extern volatile uint32_t lcd_tick_ms;
/**
* @brief Setup the Systick timer to generate a 1 ms tick
*/

View File

@ -76,4 +76,6 @@ void menu_list_scroll_down(struct menu_list *list);
void menu_list_scroll_up(struct menu_list *list);
void menu_list_enter_selected_entry(struct menu_list *list, struct lcd_menu *menu);
#endif /* __MENU_H__ */

View File

@ -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,
&current_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();

View File

@ -18,18 +18,19 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/lcd-menu.h>
#include <reflow-controller/reflow-menu.h>
#include <reflow-controller/ui/menu.h>
#include <reflow-controller/ui/lcd.h>
#include <reflow-controller/rotary-encoder.h>
#include <reflow-controller/systick.h>
#include <reflow-controller/adc-meas.h>
#include <reflow-controller/safety-adc.h>
#include <reflow-controller/temp-converter.h>
#include <helper-macros/helper-macros.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include <reflow-controller/ui/lcd.h>
#include <reflow-controller/temp-converter.h>
#include <string.h>
static char __attribute__((section(".ccmram"))) display_buffer[4][21] = {0};
static struct lcd_menu reflow_menu;
@ -66,6 +67,7 @@ static void reflow_menu_monitor(struct lcd_menu *menu, enum menu_entry_func_entr
}
if (systick_ticks_have_passed(my_timestamp, 250)) {
my_timestamp = systick_get_global_tick();
adc_pt1000_get_current_resistance(&tmp);
snprintf(line, sizeof(line), "Res: %.1f", tmp);
menu->update_display(0, line);
@ -100,41 +102,71 @@ static void reflow_menu_monitor(struct lcd_menu *menu, enum menu_entry_func_entr
}
}
static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
{
static void *my_parent;
static bool button_ready;
char buff[20];
if (entry_type == MENU_ENTRY_FIRST_ENTER) {
my_parent = parent;
button_ready = false;
menu_display_clear(menu);
menu->update_display(0, LCD_SHIMATTA_STRING " Reflow");
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
menu->update_display(1, buff);
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
snprintf(buff, sizeof(buff), "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
menu->update_display(2, buff);
}
menu->update_display(3, __DATE__);
}
if (menu->inputs.push_button == BUTTON_IDLE)
button_ready = true;
if (button_ready &&
(menu->inputs.push_button == BUTTON_SHORT_RELEASED || menu->inputs.push_button == BUTTON_LONG)) {
menu_entry_dropback(menu, my_parent);
}
}
static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
{
(void)parent;
static struct menu_list list;
static bool button_valid;
static const char * const root_entries[] = {
"Device Info",
"Safety Monitor",
"Foo",
"bar",
"foobar",
static const char * const root_entry_names[] = {
"About",
"Monitoring",
NULL
};
static const menu_func_t root_entry_funcs[] = {
reflow_menu_about,
reflow_menu_monitor
};
if (entry_type != MENU_ENTRY_CONTINUE) {
menu_display_clear(menu);
button_valid = false;
list.entry_names = root_entries;
list.submenu_list = NULL;
list.update_display = menu->update_display;
list.currently_selected = 0;
menu_list_compute_count(&list);
update_display_buffer(0, "Main Menu");
if (entry_type == MENU_ENTRY_FIRST_ENTER) {
button_valid = false;
list.entry_names = root_entry_names;
list.submenu_list = root_entry_funcs;
list.update_display = menu->update_display;
list.currently_selected = 0;
menu_list_compute_count(&list);
}
}
if (menu->inputs.push_button == BUTTON_IDLE) {
button_valid = true;
} else if (button_valid && menu->inputs.push_button == BUTTON_SHORT_RELEASED) {
switch (list.currently_selected) {
case 1:
menu_entry_enter(menu, reflow_menu_monitor, false);
break;
default:
break;
}
/* Enter currently selected menu_entry */
menu_list_enter_selected_entry(&list, menu);
}
@ -156,15 +188,16 @@ int reflow_menu_handle()
int32_t rot_delta;
enum button_state button;
static enum lcd_fsm_ret lcd_ret = LCD_FSM_NOP;
static uint64_t lcd_timestamp = 0ULL;
rot_delta = rotary_encoder_get_change_val();
button = button_read_event();
menu_handle(reflow_menu_ptr, (int16_t)rot_delta, button);
if (lcd_ret != LCD_FSM_WAIT_CALL || systick_ticks_have_passed(lcd_timestamp, 2))
if (lcd_ret != LCD_FSM_WAIT_CALL || lcd_tick_ms >= 2) {
lcd_ret = lcd_fsm_write_buffer(display_buffer);
lcd_tick_ms = 0UL;
}
if (lcd_ret == LCD_FSM_CALL_AGAIN)
return 1;

View File

@ -112,13 +112,8 @@ SECTIONS
_siccmram = LOADADDR(.ccmram);
/* CCM-RAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ccmram :
/* CCM-RAM section */
.ccmram (NOLOAD):
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
@ -126,12 +121,12 @@ SECTIONS
*(.ccmram*)
. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCM AT> FLASH
} >CCM
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */

View File

@ -26,8 +26,9 @@
#include <stm32/stm32f4xx.h>
#include <cmsis/core_cm4.h>
volatile uint32_t wait_tick_ms;
volatile uint64_t global_tick_ms;
volatile uint32_t wait_tick_ms = 0UL;
volatile uint64_t global_tick_ms = 0ULL;
volatile uint32_t lcd_tick_ms = 0UL;
void systick_setup(void)
{
@ -84,4 +85,5 @@ void __attribute__((optimize("O3"))) SysTick_Handler()
/* Increase tick counters */
wait_tick_ms++;
global_tick_ms++;
lcd_tick_ms++;
}

View File

@ -393,7 +393,7 @@ enum lcd_fsm_ret lcd_fsm_write_buffer(const char (*display_buffer)[21])
state_cnt++;
break;
case 4:
if (!systick_ticks_have_passed(timestamp, 5)) {
if (!systick_ticks_have_passed(timestamp, 4)) {
ret = LCD_FSM_WAIT_CALL;
} else {
ret = LCD_FSM_WAIT_CALL;

View File

@ -174,6 +174,24 @@ void menu_list_scroll_down(struct menu_list *list)
}
}
void menu_list_enter_selected_entry(struct menu_list *list, struct lcd_menu *menu)
{
menu_func_t entry;
if (!list)
return;
if (!list->submenu_list)
return;
entry = list->submenu_list[list->currently_selected];
if (!entry)
return;
menu_entry_enter(menu, entry, false);
}
void menu_list_scroll_up(struct menu_list *list)
{
if (!list)