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 MAX(a,b) (((a) > (b)) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-1*(a)) : (a))
#endif /* __HELPER_MACROS_H__ */

View File

@ -35,7 +35,7 @@ void rotary_encoder_setup(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);

View File

@ -21,6 +21,7 @@
#include <reflow-controller/rotary-encoder.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/stm32-gpio-macros.h>
#include <helper-macros/helper-macros.h>
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;
}
int32_t rotary_encoder_get_chage_val(void)
int32_t rotary_encoder_get_change_val(void)
{
static uint32_t last_val = 0;
uint32_t val;
@ -61,10 +62,16 @@ int32_t rotary_encoder_get_chage_val(void)
diff = val - last_val;
if (diff > 0xEFFF) {
diff = 0xFFFF - diff;
if (val > last_val) {
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;
}

View File

@ -29,7 +29,9 @@
#include <stm-periph/unique-id.h>
#include <reflow-controller/calibration.h>
#include <reflow-controller/temp-converter.h>
#include <reflow-controller/stack-check.h>
#include <reflow-controller/rotary-encoder.h>
#ifndef GIT_VER
#define GIT_VER "VERSION NOT SET"
@ -220,6 +222,23 @@ static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle,
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;
}
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@ -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 */
//} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[8] = {
static shellmatta_cmd_t cmd[9] = {
{
.cmd = "version",
.cmdAlias = "ver",
@ -293,6 +312,14 @@ static shellmatta_cmd_t cmd[8] = {
.helpText = "Get the stack pointer",
.usageText = "",
.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,
}
};