diff --git a/grid_common/grid_lua_api.c b/grid_common/grid_lua_api.c index e8136396..fdfec291 100644 --- a/grid_common/grid_lua_api.c +++ b/grid_common/grid_lua_api.c @@ -68,6 +68,7 @@ // If there is any content to encode if (msg_len > 0) { + grid_platform_printf("LUA: %s\r\n", message); grid_port_debug_print_text(message); } diff --git a/grid_common/grid_protocol.h b/grid_common/grid_protocol.h index b0c7e8c4..249f0e6f 100644 --- a/grid_common/grid_protocol.h +++ b/grid_common/grid_protocol.h @@ -677,6 +677,9 @@ #define GRID_LUA_FNC_EP_BUTTON_MODE_short "bmo" #define GRID_LUA_FNC_EP_BUTTON_MODE_human "button_mode" +#define GRID_LUA_FNC_EP_BUTTON_STEP_short "bstp" +#define GRID_LUA_FNC_EP_BUTTON_STEP_human "button_step" + #define GRID_LUA_FNC_EP_BUTTON_ELAPSED_index 6 #define GRID_LUA_FNC_EP_BUTTON_ELAPSED_short "bel" #define GRID_LUA_FNC_EP_BUTTON_ELAPSED_human "button_elapsed_time" diff --git a/grid_common/grid_ui.c b/grid_common/grid_ui.c index 612654e8..7289e45e 100644 --- a/grid_common/grid_ui.c +++ b/grid_common/grid_ui.c @@ -840,10 +840,7 @@ static bool grid_ui_bulk_queue_with_state(struct grid_ui_model* ui, fn_prthread_ bool grid_ui_bulk_start_with_state(struct grid_ui_model* ui, fn_prthread_bulk_t next, uint8_t page, uint8_t lastheader_id, void (*success_cb)(uint8_t)) { - if (grid_ui_bulk_in_progress(ui)) { - return false; - } - + assert(!grid_ui_bulk_in_progress(ui)); assert(grid_ui_bulk_queue_with_state(ui, next, page, lastheader_id, success_cb)); return true; @@ -899,14 +896,15 @@ void grid_ui_bulk_process(struct grid_ui_model* ui) { // Protothread requires no further execution if (status >= PT_EXITED) { + // Unset currently executing protothread before calling success callback, + // so that the callback can queue a new bulk operation via bulk_start_with_state + ui->bulk_curr = NULL; + // Protothread reached its end (instead of exiting early) if (status == PT_ENDED) { grid_ui_bulk_handle_success_cb(ui); } - // Unset currently executing protothread - ui->bulk_curr = NULL; - // There are no more protohreads waiting to be executed if (!grid_ui_bulk_in_waiting(ui)) { diff --git a/grid_common/grid_ui_button.c b/grid_common/grid_ui_button.c index 6825f07a..82b2a5f0 100644 --- a/grid_common/grid_ui_button.c +++ b/grid_common/grid_ui_button.c @@ -348,14 +348,18 @@ void grid_ui_button_store_input(struct grid_ui_button_state* state, uint16_t val last = clampi32(last, min, max); - int32_t new_value = last + (tmax - tmin) / steps; - - if (new_value > max) { - new_value = min; + int32_t step_size = (tmax - tmin) / steps; + int32_t new_value; + + if (step_size != 0) { + int32_t k = (last - tmin) / step_size; + new_value = tmin + (k + 1) * step_size; + } else { + new_value = last; } - if (new_value < min) { - new_value = max; + if (new_value > max || new_value < min) { + new_value = tmin; } int32_t value_range = tmax - tmin; diff --git a/grid_common/grid_ui_encoder.h b/grid_common/grid_ui_encoder.h index 194c5570..b6a4884d 100644 --- a/grid_common/grid_ui_encoder.h +++ b/grid_common/grid_ui_encoder.h @@ -75,8 +75,8 @@ extern const luaL_Reg GRID_LUA_E_INDEX_META[]; GRID_LUA_FNC_ASSIGN_META_PAR1_RET("gen", GRID_LUA_FNC_G_ELEMENTNAME_short) "," \ \ GRID_LUA_FNC_E_BUTTON_STEP_short " =function (self) " \ - "local steps, min, max, value = self:" GRID_LUA_FNC_B_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_B_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_B_BUTTON_MAX_short \ - "(), self:" GRID_LUA_FNC_B_BUTTON_VALUE_short "() " \ + "local steps, min, max, value = self:" GRID_LUA_FNC_E_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_E_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_E_BUTTON_MAX_short \ + "(), self:" GRID_LUA_FNC_E_BUTTON_VALUE_short "() " \ "if steps == 0 then return false end " \ "return value // ((max - min) // steps) " \ "end," \ diff --git a/grid_common/grid_ui_endless.h b/grid_common/grid_ui_endless.h index f2cdd111..ded0e23f 100644 --- a/grid_common/grid_ui_endless.h +++ b/grid_common/grid_ui_endless.h @@ -58,6 +58,13 @@ extern const luaL_Reg GRID_LUA_EP_INDEX_META[]; \ GRID_LUA_FNC_ASSIGN_META_PAR1_RET("gen", GRID_LUA_FNC_G_ELEMENTNAME_short) "," \ \ + GRID_LUA_FNC_EP_BUTTON_STEP_short " =function (self) " \ + "local steps, min, max, value = self:" GRID_LUA_FNC_EP_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_EP_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_EP_BUTTON_MAX_short \ + "(), self:" GRID_LUA_FNC_EP_BUTTON_VALUE_short "() " \ + "if steps == 0 then return false end " \ + "return value // ((max - min) // steps) " \ + "end," \ + \ "}}" #define GRID_ACTIONSTRING_ENDLESS_INIT ""