Fix #17: Merge branch 'issue/17-rotary-emulation-cmd' into dev

This commit is contained in:
Mario Hüttel 2020-08-30 19:04:01 +02:00
commit 3dfe59482e
6 changed files with 123 additions and 12 deletions

View File

@ -58,3 +58,31 @@ Calibration is most likely not necessary! See the :ref:`usage_calibration` page.
The command will guide you through the calibration process and will ask for two reference resistors with ``1000 Ohm`` and ``2000 Ohm`` values.
Calibration can be aborted using ``CTRL + C``.
.. _shell_command_hang:
hang
~~~~
The ``hang`` command hangs the main-loop in an infinite loop. This function tests, whether the controller is correctly rescued by the watchdog.
.. _shell_command_ui_emulate:
ui-emulate
~~~~~~~~~~
The ``ui-emulate`` command emulates the rotary encoder and button from the shell. The following keys are available:
========== ================================
Key Emulation
========== ================================
``CTRL+C`` Exit the command
``ENTER`` Button press: short released
``s`` Rotary Encoder: anti-clockwise
``w`` Rotary Encoder: clockwise
``l`` Button press: long
``k`` Button press: short
``r`` Button press: long released
========== ================================

View File

@ -29,6 +29,7 @@
static volatile uint64_t IN_SECTION(.ccm.bss) to_active_timestamp;
static volatile enum button_state IN_SECTION(.ccm.bss) int_state;
static volatile enum button_state IN_SECTION(.ccm.bss) override_state;
void button_init()
{
@ -40,6 +41,7 @@ void button_init()
to_active_timestamp = 0ULL;
int_state = BUTTON_IDLE;
override_state = BUTTON_IDLE;
SYSCFG->EXTICR[1] |= 0x3;
EXTI->IMR |= (1U<<4);
@ -53,6 +55,12 @@ enum button_state button_read_event()
uint64_t time_delta;
enum button_state temp_state;
if (override_state != BUTTON_IDLE) {
temp_state = override_state;
override_state = BUTTON_IDLE;
return temp_state;
}
if (BUTTON_PORT->IDR & (1U<<BUTTON_PIN)) {
temp_state = int_state;
int_state = BUTTON_IDLE;
@ -96,3 +104,8 @@ void EXTI4_IRQHandler(void)
to_active_timestamp = systick_get_global_tick();
}
}
void button_override_event(enum button_state state)
{
override_state = state;
}

View File

@ -72,5 +72,10 @@ enum button_state button_read_event();
*/
void button_deinit();
/**
* @brief This function overrides the button event.
* @param state State to set
*/
void button_override_event(enum button_state state);
#endif /* __BUTTON_H__ */

View File

@ -41,4 +41,6 @@ void rotary_encoder_stop(void);
void rotary_encoder_zero(void);
void rotary_encoder_override_delta(int16_t delta);
#endif /* __ROTARY_ENCODER_H__ */

View File

@ -23,6 +23,8 @@
#include <stm-periph/stm32-gpio-macros.h>
#include <helper-macros/helper-macros.h>
static int16_t IN_SECTION(.ccm.bss) override_delta;
static inline void rotary_encoder_setup_pins(void)
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
@ -45,6 +47,8 @@ void rotary_encoder_setup(void)
ROTARY_ENCODER_TIMER->CCER = TIM_CCER_CC1P | TIM_CCER_CC2P;
ROTARY_ENCODER_TIMER->PSC = 0;
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN;
override_delta = 0;
}
uint32_t rotary_encoder_get_abs_val(void)
@ -72,6 +76,9 @@ int32_t rotary_encoder_get_change_val(void)
last_val = val;
diff += override_delta;
override_delta = 0;
return diff;
}
@ -88,3 +95,8 @@ void rotary_encoder_zero(void)
{
ROTARY_ENCODER_TIMER->CNT = 0UL;
}
void rotary_encoder_override_delta(int16_t delta)
{
override_delta = delta;
}

View File

@ -37,6 +37,7 @@
#include <reflow-controller/rotary-encoder.h>
#include <reflow-controller/safety/safety-controller.h>
#include <reflow-controller/settings/settings.h>
#include <reflow-controller/button.h>
#ifndef GIT_VER
#define GIT_VER "VERSION NOT SET"
@ -458,6 +459,48 @@ static shellmatta_retCode_t shell_cmd_hang(const shellmatta_handle_t handle, con
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_ui_emulation(const shellmatta_handle_t handle, const char *arguments,
uint32_t length)
{
(void)length;
(void)arguments;
uint32_t i;
uint32_t len;
char *buff;
shellmatta_read(handle, &buff, &len);
for (i = 0; i < len; i++) {
switch (buff[i]) {
case 'W':
case 'w':
rotary_encoder_override_delta(4);
break;
case 's':
case 'S':
rotary_encoder_override_delta(-4);
break;
case '\r':
button_override_event(BUTTON_SHORT_RELEASED);
break;
case 'l':
case 'L':
button_override_event(BUTTON_LONG);
break;
case 'k':
case 'K':
button_override_event(BUTTON_SHORT);
break;
case 'r':
case 'R':
button_override_event(BUTTON_LONG_RELEASED);
break;
}
}
return SHELLMATTA_CONTINUE;
}
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@ -467,7 +510,7 @@ static shellmatta_retCode_t shell_cmd_hang(const shellmatta_handle_t handle, con
// shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[15] = {
static shellmatta_cmd_t cmd[16] = {
{
.cmd = "version",
.cmdAlias = "ver",
@ -586,8 +629,16 @@ static shellmatta_cmd_t cmd[15] = {
.helpText = "",
.usageText = "",
.cmdFct = shell_cmd_hang,
.next = &cmd[15],
},
{
.cmd = "ui-emulate",
.cmdAlias = NULL,
.helpText = "",
.usageText = "",
.cmdFct = shell_cmd_ui_emulation,
.next = NULL,
}
},
};
shellmatta_handle_t shell_init(shellmatta_write_t write_func)