Merge branch 'ui' into dev

This commit is contained in:
Mario Hüttel 2020-02-21 23:08:38 +01:00
commit 30aa1149a3
4 changed files with 65 additions and 29 deletions

View File

@ -34,4 +34,6 @@
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-1*(a)) : (a))
#endif /* __HELPER_MACROS_H__ */ #endif /* __HELPER_MACROS_H__ */

View File

@ -35,7 +35,7 @@ void rotary_encoder_setup(void);
uint32_t rotary_encoder_get_abs_val(void); uint32_t rotary_encoder_get_abs_val(void);
int32_t rotary_encoder_get_chage_val(void); int32_t rotary_encoder_get_change_val(void);
void rotary_encoder_stop(void); void rotary_encoder_stop(void);

View File

@ -21,6 +21,7 @@
#include <reflow-controller/rotary-encoder.h> #include <reflow-controller/rotary-encoder.h>
#include <stm-periph/clock-enable-manager.h> #include <stm-periph/clock-enable-manager.h>
#include <stm-periph/stm32-gpio-macros.h> #include <stm-periph/stm32-gpio-macros.h>
#include <helper-macros/helper-macros.h>
static inline void rotary_encoder_setup_pins(void) static inline void rotary_encoder_setup_pins(void)
{ {
@ -51,7 +52,7 @@ uint32_t rotary_encoder_get_abs_val(void)
return (uint32_t)ROTARY_ENCODER_TIMER->CNT; return (uint32_t)ROTARY_ENCODER_TIMER->CNT;
} }
int32_t rotary_encoder_get_chage_val(void) int32_t rotary_encoder_get_change_val(void)
{ {
static uint32_t last_val = 0; static uint32_t last_val = 0;
uint32_t val; uint32_t val;
@ -61,10 +62,16 @@ int32_t rotary_encoder_get_chage_val(void)
diff = val - last_val; diff = val - last_val;
if (diff > 0xEFFF) { if (val > last_val) {
diff = 0xFFFF - diff; if (diff > (0xFFFF/2))
diff = -(last_val + 0x10000-val);
} else {
if (ABS(diff) > (0xFFFF/2))
diff = 0x10000 - last_val + val;
} }
last_val = val;
return diff; return diff;
} }

View File

@ -29,7 +29,9 @@
#include <stm-periph/unique-id.h> #include <stm-periph/unique-id.h>
#include <reflow-controller/calibration.h> #include <reflow-controller/calibration.h>
#include <reflow-controller/temp-converter.h> #include <reflow-controller/temp-converter.h>
#include <reflow-controller/stack-check.h> #include <reflow-controller/stack-check.h>
#include <reflow-controller/rotary-encoder.h>
#ifndef GIT_VER #ifndef GIT_VER
#define GIT_VER "VERSION NOT SET" #define GIT_VER "VERSION NOT SET"
@ -46,8 +48,8 @@ static shellmatta_retCode_t write_shell_callback(const char *data, uint32_t len)
} }
static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle, static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
const char *arguments, const char *arguments,
uint32_t length) uint32_t length)
{ {
(void)arguments; (void)arguments;
(void)length; (void)length;
@ -58,22 +60,22 @@ static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
unique_id_get(&high_id, &mid_id, &low_id); unique_id_get(&high_id, &mid_id, &low_id);
shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n" shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n"
"Compiled: " __DATE__ " at " __TIME__ "\r\n" "Compiled: " __DATE__ " at " __TIME__ "\r\n"
"Serial: %08X-%08X-%08X", high_id, mid_id, low_id); "Serial: %08X-%08X-%08X", high_id, mid_id, low_id);
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
static shellmatta_retCode_t shell_cmd_digio_get(const shellmatta_handle_t handle, static shellmatta_retCode_t shell_cmd_digio_get(const shellmatta_handle_t handle,
const char *arguments, const char *arguments,
uint32_t length) uint32_t length)
{ {
(void)arguments; (void)arguments;
(void)length; (void)length;
shellmatta_printf(handle, shellmatta_printf(handle,
"DIGIO0 DIGIO1 DIGIO2 DIGIO3 LED0 LED1 LS\r\n" "DIGIO0 DIGIO1 DIGIO2 DIGIO3 LED0 LED1 LS\r\n"
"%d %d %d %d %d %d %d\r\n", "%d %d %d %d %d %d %d\r\n",
digio_get(0), digio_get(1), digio_get(2), digio_get(3), digio_get(0), digio_get(1), digio_get(2), digio_get(3),
led_get(0), led_get(1), loudspeaker_get()); led_get(0), led_get(1), loudspeaker_get());
@ -81,8 +83,8 @@ static shellmatta_retCode_t shell_cmd_digio_get(const shellmatta_handle_t hand
} }
static shellmatta_retCode_t shell_cmd_digio_set(const shellmatta_handle_t handle, static shellmatta_retCode_t shell_cmd_digio_set(const shellmatta_handle_t handle,
const char *arguments, const char *arguments,
uint32_t length) uint32_t length)
{ {
(void)length; (void)length;
(void)handle; (void)handle;
@ -193,8 +195,8 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
} }
static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle, static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
const char *arguments, const char *arguments,
uint32_t length) uint32_t length)
{ {
(void)arguments; (void)arguments;
(void)length; (void)length;
@ -204,19 +206,36 @@ static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
} }
static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle, static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle,
const char *arguments, const char *arguments,
uint32_t length) uint32_t length)
{ {
(void)arguments; (void)arguments;
(void)length; (void)length;
shellmatta_printf(handle, shellmatta_printf(handle,
"Stack pointer: %p\r\n" "Stack pointer: %p\r\n"
"Stack usage: 0x%x bytes\r\n" "Stack usage: 0x%x bytes\r\n"
"Lim to heap: 0x%x bytes\r\n", "Lim to heap: 0x%x bytes\r\n",
read_stack_pointer(), read_stack_pointer(),
stack_check_get_usage(), stack_check_get_usage(),
stack_check_get_free()); stack_check_get_free());
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_rot(const shellmatta_handle_t handle,
const char *arguments,
uint32_t length)
{
(void)arguments;
(void)length;
uint32_t rot_val;
int32_t delta;
rot_val = rotary_encoder_get_abs_val();
delta = rotary_encoder_get_change_val();
shellmatta_printf(handle, "Rotary encoder value: %u, delta: %d\r\n", rot_val, delta);
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
@ -230,7 +249,7 @@ static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle,
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */ // struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t; //} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[8] = { static shellmatta_cmd_t cmd[9] = {
{ {
.cmd = "version", .cmd = "version",
.cmdAlias = "ver", .cmdAlias = "ver",
@ -293,6 +312,14 @@ static shellmatta_cmd_t cmd[8] = {
.helpText = "Get the stack pointer", .helpText = "Get the stack pointer",
.usageText = "", .usageText = "",
.cmdFct = shell_get_sp, .cmdFct = shell_get_sp,
.next = &cmd[8],
},
{
.cmd = "rotary-encoder",
.cmdAlias = "rot",
.helpText = "Get current rotary encoder value",
.usageText = "",
.cmdFct = shell_cmd_rot,
.next = NULL, .next = NULL,
} }
}; };
@ -303,7 +330,7 @@ shellmatta_handle_t shell_init(void)
shellmatta_retCode_t ret; shellmatta_retCode_t ret;
ret = shellmatta_doInit(&shell, &handle, shell_buffer, sizeof(shell_buffer), history_buffer, sizeof(history_buffer), ret = shellmatta_doInit(&shell, &handle, shell_buffer, sizeof(shell_buffer), history_buffer, sizeof(history_buffer),
"\e[1;32mEnter command:\e[m\r\n", cmd, write_shell_callback); "\e[1;32mEnter command:\e[m\r\n", cmd, write_shell_callback);
if (ret != SHELLMATTA_OK) if (ret != SHELLMATTA_OK)
handle = NULL; handle = NULL;
@ -313,10 +340,10 @@ shellmatta_handle_t shell_init(void)
void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len) void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len)
{ {
if (!shell) if (!shell)
return; return;
shellmatta_processData(shell, (char *)data, (uint32_t)len); shellmatta_processData(shell, (char *)data, (uint32_t)len);
} }
void shell_print_string(shellmatta_handle_t shell, const char *string) void shell_print_string(shellmatta_handle_t shell, const char *string)