Skip to content

Commit 84bbc0b

Browse files
BENB state reset for touch element
1 parent 357647f commit 84bbc0b

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎common/src/c/grid_ui.c‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,26 @@ void grid_ui_bulk_semaphore_release(struct grid_ui_model* ui) { grid_ui_semaphor
110110

111111
bool grid_ui_bulk_semaphore_try(struct grid_ui_model* ui) { return grid_ui_semaphore_try(&ui->bulk_semaphore); }
112112

113+
typedef void (*grid_ui_element_state_reset_t)(void* state);
114+
115+
extern void grid_ui_touch_state_reset(void* state);
116+
113117
void grid_ui_element_reset(struct grid_ui_element* ele) {
114118

115119
ele->timer_event_helper = 0;
116120
ele->timer_source_is_midi = 0;
117121
ele->name[0] = '\0';
122+
123+
static const grid_ui_element_state_reset_t resets[GRID_PARAMETER_ELEMENT_COUNT] = {
124+
[GRID_PARAMETER_ELEMENT_TOUCH] = grid_ui_touch_state_reset,
125+
};
126+
127+
if (ele->type < GRID_PARAMETER_ELEMENT_COUNT) {
128+
129+
if (resets[ele->type] && ele->primary_state) {
130+
resets[ele->type](ele->primary_state);
131+
}
132+
}
118133
}
119134

120135
struct grid_ui_element* grid_ui_element_model_init(struct grid_ui_model* parent, uint8_t index) {
@@ -509,6 +524,8 @@ uint16_t grid_ui_event_count_istriggered(struct grid_ui_model* ui) {
509524
return count;
510525
}
511526

527+
typedef bool (*grid_ui_element_state_any_t)(void* state);
528+
512529
extern bool grid_ui_touch_state_any(void* state);
513530

514531
bool grid_ui_events_any(struct grid_ui_model* ui) {
@@ -517,19 +534,21 @@ bool grid_ui_events_any(struct grid_ui_model* ui) {
517534
return true;
518535
}
519536

537+
static const grid_ui_element_state_any_t anys[GRID_PARAMETER_ELEMENT_COUNT] = {
538+
[GRID_PARAMETER_ELEMENT_TOUCH] = grid_ui_touch_state_any,
539+
};
540+
520541
for (uint8_t i = 0; i < ui->element_list_length; ++i) {
521542

522543
struct grid_ui_element* ele = &ui->element_list[i];
523544

524-
switch (ele->type) {
525-
case GRID_PARAMETER_ELEMENT_TOUCH: {
545+
assert(ele->type < GRID_PARAMETER_ELEMENT_COUNT);
546+
547+
if (anys[ele->type] && ele->primary_state) {
526548

527-
assert(ele->primary_state);
528-
if (grid_ui_touch_state_any(ele->primary_state)) {
549+
if (anys[ele->type](ele->primary_state)) {
529550
return true;
530551
}
531-
532-
} break;
533552
}
534553
}
535554

‎common/src/c/grid_ui_touch.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ const luaL_Reg GRID_LUA_T_INDEX_META[] = {{GRID_LUA_FNC_T_ELEMENT_INDEX_short, X
6969

7070
void grid_ui_touch_state_alloc(struct grid_ui_touch_state* state) { assert(grid_swsr_malloc(&state->swsr, 10 * sizeof(struct touchvalue_t)) == 0); }
7171

72+
void grid_ui_touch_state_reset(struct grid_ui_touch_state* state) {
73+
74+
state->x_min = 0;
75+
state->y_min = 0;
76+
state->x_max = 127;
77+
state->y_max = 127;
78+
}
79+
7280
void grid_ui_touch_state_init(struct grid_ui_touch_state* state, uint8_t adc_bit_depth) { state->adc_bit_depth = adc_bit_depth; }
7381

7482
bool grid_ui_touch_state_any(struct grid_ui_touch_state* state) { return grid_swsr_readable(&state->swsr, sizeof(state->value)); }

‎common/src/c/grid_ui_touch.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extern const luaL_Reg GRID_LUA_T_INDEX_META[];
6868
\
6969
"}}"
7070

71-
#define GRID_ACTIONSTRING_TOUCH_INIT "--[[@cb]] self:txmi(0)self:txma(127)self:tymi(0)self:tyma(127)self.touch_cb=function(self,id,event,x,y)print(id,event,x,y)end"
71+
#define GRID_ACTIONSTRING_TOUCH_INIT "--[[@cb]] self.touch_cb=function(self,id,evt,x,y)print(id,evt,x,y)end"
7272

7373
// clang-format on
7474

0 commit comments

Comments
 (0)