feat(color): More tuning of rotary encoder acc, enable for color picker (#2366)

* Smoother encoder acceleration

* Enable encoder accel on color picker
This commit is contained in:
Raphael Coeffic
2022-09-27 11:52:28 +10:00
committed by GitHub
parent 4d85f67a00
commit af7679a486
2 changed files with 6 additions and 3 deletions
+4 -3
View File
@@ -261,10 +261,11 @@ static void rotaryDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
else if (diff > 0) dir = 1;
if (use_accel && (dir == prevDir)) {
if (g_tmr10ms - lastEvent <= ROTENC_DELAY_HIGHSPEED) { // 160 ms
auto speed = (g_tmr10ms - lastEvent) / abs(diff);
if (speed <= ROTENC_DELAY_HIGHSPEED/2) { // 80 ms
// below ROTENC_DELAY_HIGHSPEED btw. events: accelerate
accel += abs(diff);
} else if (g_tmr10ms - lastEvent >= ROTENC_DELAY_MIDSPEED) { // 320 ms
accel = min((int8_t)(accel + 1), (int8_t)25);
} else if (speed >= ROTENC_DELAY_MIDSPEED/2) { // 160 ms
// above ROTENC_DELAY_MIDSPEED btw. events: normal speed
accel = 0;
}
+2
View File
@@ -140,6 +140,8 @@ ColorBar::ColorBar(Window* parent, const rect_t& r, uint32_t value,
uint32_t maxValue, bool invert) :
FormField(parent, r)
{
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
lv_group_add_obj((lv_group_t*)lv_group_get_default(), lvobj);
lv_obj_add_event_cb(lvobj, ColorBar::pressing, LV_EVENT_PRESSING, nullptr);
lv_obj_add_event_cb(lvobj, ColorBar::on_key, LV_EVENT_KEY, nullptr);