Issue #4: Implement Constant temperature function in GUI. This is useful to verify the oven parameters
This commit is contained in:
		@@ -25,6 +25,7 @@
 | 
			
		||||
#include <reflow-controller/systick.h>
 | 
			
		||||
#include <reflow-controller/adc-meas.h>
 | 
			
		||||
#include <reflow-controller/safety/safety-controller.h>
 | 
			
		||||
#include <reflow-controller/settings/settings.h>
 | 
			
		||||
#include <reflow-controller/temp-converter.h>
 | 
			
		||||
#include <helper-macros/helper-macros.h>
 | 
			
		||||
#include <stm-periph/unique-id.h>
 | 
			
		||||
@@ -33,6 +34,7 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <reflow-controller/oven-driver.h>
 | 
			
		||||
 | 
			
		||||
static char IN_SECTION(.ccm.bss) display_buffer[4][21] = {0};
 | 
			
		||||
static struct lcd_menu IN_SECTION(.ccm.bss) reflow_menu;
 | 
			
		||||
@@ -297,21 +299,113 @@ static void gui_menu_err_flags(struct lcd_menu *menu, enum menu_entry_func_entry
 | 
			
		||||
	timestamp = systick_get_global_tick();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gui_menu_constant_temperature_driver(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
 | 
			
		||||
{
 | 
			
		||||
	static void IN_SECTION(.ccm.bss) *my_parent;
 | 
			
		||||
	static int16_t IN_SECTION(.ccm.bss) temperature;
 | 
			
		||||
	static bool IN_SECTION(.ccm.bss) fine;
 | 
			
		||||
	enum button_state button;
 | 
			
		||||
	int16_t rot;
 | 
			
		||||
	int16_t temp_old;
 | 
			
		||||
 | 
			
		||||
	if (entry_type == MENU_ENTRY_FIRST_ENTER) {
 | 
			
		||||
		my_parent = parent;
 | 
			
		||||
		temperature = 30;
 | 
			
		||||
		menu_display_clear(menu);
 | 
			
		||||
		menu_lcd_outputf(menu, 0, "Temp Controller");
 | 
			
		||||
		temp_old = 0;
 | 
			
		||||
	} else {
 | 
			
		||||
		temp_old = temperature;
 | 
			
		||||
	}
 | 
			
		||||
	if (menu_get_button_ready_state(menu)) {
 | 
			
		||||
		button = menu_get_button_state(menu);
 | 
			
		||||
		rot = menu_get_rotary_delta(menu);
 | 
			
		||||
		if (rot >= 4 || rot <= -4) {
 | 
			
		||||
			menu_ack_rotary_delta(menu);
 | 
			
		||||
			if (rot > 0)
 | 
			
		||||
				temperature += (fine ? 1 : 10);
 | 
			
		||||
			else
 | 
			
		||||
				temperature -= (fine ? 1 : 10);
 | 
			
		||||
			if (temperature > 300)
 | 
			
		||||
				temperature = 300;
 | 
			
		||||
			else if (temperature < 0)
 | 
			
		||||
				temperature = 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		switch (button) {
 | 
			
		||||
		case BUTTON_SHORT_RELEASED:
 | 
			
		||||
			fine = !fine;
 | 
			
		||||
			break;
 | 
			
		||||
		case BUTTON_LONG:
 | 
			
		||||
			oven_pid_stop();
 | 
			
		||||
			menu_entry_dropback(menu, my_parent);
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (oven_pid_get_status() != OVEN_PID_RUNNING) {
 | 
			
		||||
		menu_lcd_output(menu, 1, "PID stopped!");
 | 
			
		||||
		menu_lcd_output(menu, 2, "Check Flags!");
 | 
			
		||||
	} else {
 | 
			
		||||
		if (temperature != temp_old) {
 | 
			
		||||
			oven_pid_set_target_temperature((float)temperature);
 | 
			
		||||
			menu_lcd_outputf(menu, 1, "Temp: %d " LCD_DEGREE_SYMBOL_STRING "C", (int)temperature);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gui_menu_constant_temperature_driver_setup(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
 | 
			
		||||
{
 | 
			
		||||
	static void IN_SECTION(.ccm.bss) *my_parent;
 | 
			
		||||
	struct oven_pid_settings pid_settings;
 | 
			
		||||
	enum button_state button;
 | 
			
		||||
	struct pid_controller pid_controller;
 | 
			
		||||
 | 
			
		||||
	if (entry_type == MENU_ENTRY_FIRST_ENTER) {
 | 
			
		||||
		my_parent = parent;
 | 
			
		||||
 | 
			
		||||
		/* Try loading PID parameters */
 | 
			
		||||
		if (settings_load_pid_oven_parameters(&pid_settings)) {
 | 
			
		||||
			menu_display_clear(menu);
 | 
			
		||||
			menu_lcd_output(menu, 0, "Could not load");
 | 
			
		||||
			menu_lcd_output(menu, 1, "PID parameters");
 | 
			
		||||
		} else {
 | 
			
		||||
			pid_init(&pid_controller, pid_settings.kd, pid_settings.ki, pid_settings.kp, 0, 100,
 | 
			
		||||
				 pid_settings.max_integral, pid_settings.t_sample);
 | 
			
		||||
			oven_pid_init(&pid_controller);
 | 
			
		||||
			menu_entry_enter(menu, gui_menu_constant_temperature_driver, true);
 | 
			
		||||
		}
 | 
			
		||||
	} else if (entry_type == MENU_ENTRY_DROPBACK) {
 | 
			
		||||
		menu_entry_dropback(menu, my_parent);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (menu_get_button_ready_state(menu)) {
 | 
			
		||||
		button = menu_get_button_state(menu);
 | 
			
		||||
		if (button == BUTTON_SHORT_RELEASED || button == BUTTON_LONG) {
 | 
			
		||||
			menu_entry_dropback(menu, my_parent);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gui_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)
 | 
			
		||||
{
 | 
			
		||||
	(void)parent;
 | 
			
		||||
	static struct menu_list list;
 | 
			
		||||
	bool menu_changed = false;
 | 
			
		||||
	static const char * const root_entry_names[] = {
 | 
			
		||||
		"About",
 | 
			
		||||
		"Constant Temp",
 | 
			
		||||
		"Monitoring",
 | 
			
		||||
		"Error Flags",
 | 
			
		||||
		"About",
 | 
			
		||||
		NULL
 | 
			
		||||
	};
 | 
			
		||||
	static const menu_func_t root_entry_funcs[] = {
 | 
			
		||||
		gui_menu_about,
 | 
			
		||||
		gui_menu_constant_temperature_driver_setup,
 | 
			
		||||
		gui_menu_monitor,
 | 
			
		||||
		gui_menu_err_flags,
 | 
			
		||||
		gui_menu_about,
 | 
			
		||||
	};
 | 
			
		||||
	enum button_state push_button;
 | 
			
		||||
	int16_t rot_delta;
 | 
			
		||||
 
 | 
			
		||||
@@ -81,6 +81,8 @@ void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func)
 | 
			
		||||
	else
 | 
			
		||||
		menu->active_entry = menu->root_entry;
 | 
			
		||||
 | 
			
		||||
	menu_ack_rotary_delta(menu);
 | 
			
		||||
 | 
			
		||||
	menu->active_entry_type = MENU_ENTRY_DROPBACK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user