Make ptdump command async: Main loop will continue if comamnd is called

This commit is contained in:
Mario Hüttel 2020-05-09 20:40:31 +02:00
parent 8f2418eb7c
commit 4f05c084d9
2 changed files with 19 additions and 45 deletions

View File

@ -207,6 +207,8 @@ int main()
while (1) { while (1) {
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted); sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
snprintf(&disp[0][0], 17, "SD %smounted", sd_card_mounted ? "" : "un");
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value); pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
if (systick_ticks_have_passed(pid_timestamp, 250)) { if (systick_ticks_have_passed(pid_timestamp, 250)) {
@ -228,20 +230,22 @@ int main()
loudspeaker_set(1); loudspeaker_set(1);
} else if (pid_controller_active) { } else if (pid_controller_active) {
/* In case temperature measuremnt is okay and controlelr is working, write output power */ /* In case temperature measuremnt is okay and controlelr is working, write output power */
oven_driver_set_power(pid_controller_output < 0 ? 0U : pid_controller_output); oven_driver_set_power(pid_controller_output < 0 ? 0U : (uint8_t)pid_controller_output);
} }
button = button_read_event(); button = button_read_event();
rot = rotary_encoder_get_abs_val(); rot = rotary_encoder_get_abs_val();
/* TODO: handle gui */ /* TODO: handle gui */
snprintf(&disp[1][0], 17, "Rotary: %u", (unsigned int)rot);
snprintf(&disp[2][0], 17, "Button: %s", (button == BUTTON_SHORT ? "SHORT" : (button == BUTTON_LONG ? "LONG" : "")));
/* 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); uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
if (uart_receive_status >= 1) if (uart_receive_status >= 0)
shell_handle_input(shell_handle, uart_input, uart_input_len); shell_handle_input(shell_handle, uart_input, uart_input_len);
if (systick_ticks_have_passed(display_timestamp, 1) || lcd_ret == LCD_FSM_CALL_AGAIN) { if (systick_ticks_have_passed(display_timestamp, 2) || lcd_ret == LCD_FSM_CALL_AGAIN) {
lcd_ret = lcd_fsm_write_buffer(disp); lcd_ret = lcd_fsm_write_buffer(disp);
display_timestamp = systick_get_global_tick(); display_timestamp = systick_get_global_tick();
} }

View File

@ -251,46 +251,16 @@ static shellmatta_retCode_t shell_cmd_rot(const shellmatta_handle_t handle,
static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t handle, const char *arguments, static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t handle, const char *arguments,
uint32_t length) uint32_t length)
{ {
char arg[20]; (void)arguments;
size_t arg_len; (void)length;
int led_status = 0; static uint64_t timestamp = 0ULL;
bool run_loop = true;
bool single_line = false;
const char *data;
size_t len;
unsigned int i;
arg_len = (sizeof(arg) < length ? sizeof(arg) : length); if (systick_ticks_have_passed(timestamp, 150)) {
strncpy(arg, arguments, arg_len);
if (strstr(arg, "--single-line"))
single_line = true;
shellmatta_printf(handle, "\r\n");
while (run_loop) {
uart_receive_data_with_dma(&shell_uart, &data , &len);
for (i = 0; i < len; i++) {
if (data[i] == '\x03')
run_loop = false;
}
if (single_line)
shellmatta_printf(handle, "\x1b[1A\x1b[150D\x1b[K");
shell_cmd_pt1000_res(handle, "", 0UL); shell_cmd_pt1000_res(handle, "", 0UL);
timestamp = systick_get_global_tick();
led_set(1, led_status);
if (adc_pt1000_check_error() & ADC_PT1000_WATCHDOG_ERROR) {
led_set(0, 1);
} }
led_status ^= 0x1; return SHELLMATTA_CONTINUE;
systick_wait_ms(150);
}
led_set(0, 0);
led_set(1, 0);
return SHELLMATTA_OK;
} }
static shellmatta_retCode_t shell_cmd_ls(const shellmatta_handle_t handle, const char *arguments, static shellmatta_retCode_t shell_cmd_ls(const shellmatta_handle_t handle, const char *arguments,
@ -404,7 +374,7 @@ static shellmatta_cmd_t cmd[13] = {
.cmd = "pt1000-dump", .cmd = "pt1000-dump",
.cmdAlias = "ptdump", .cmdAlias = "ptdump",
.helpText = "Get current filtered and calibrated PT1000 resistance in a loop", .helpText = "Get current filtered and calibrated PT1000 resistance in a loop",
.usageText = "pt1000-dump [--single-line]", .usageText = "pt1000-dump",
.cmdFct = shell_cmd_pt1000_res_loop, .cmdFct = shell_cmd_pt1000_res_loop,
.next = &cmd[3], .next = &cmd[3],
}, },