Skip to content

Commit 73c7d4a

Browse files
Setting for faster Button Repeat delays
1 parent b4112f0 commit 73c7d4a

6 files changed

+113
-11
lines changed

firmware/application/apps/ui_settings.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,36 @@ void SetEncoderDialView::focus() {
721721
button_save.focus();
722722
}
723723

724+
/* SetButtonsView ************************************/
725+
726+
SetButtonsView::SetButtonsView(NavigationView& nav) {
727+
add_children({&labels,
728+
&button_save,
729+
&button_cancel,
730+
&field_repeat_delay,
731+
&field_repeat_speed,
732+
&field_long_press_delay});
733+
734+
field_repeat_delay.set_by_value(pmem::ui_button_repeat_delay());
735+
field_repeat_speed.set_by_value(pmem::ui_button_repeat_speed());
736+
field_long_press_delay.set_by_value(pmem::ui_button_long_press_delay());
737+
738+
button_save.on_select = [&nav, this](Button&) {
739+
pmem::set_ui_button_repeat_delay(field_repeat_delay.selected_index_value());
740+
pmem::set_ui_button_repeat_speed(field_repeat_speed.selected_index_value());
741+
pmem::set_ui_button_long_press_delay(field_long_press_delay.selected_index_value());
742+
nav.pop();
743+
};
744+
745+
button_cancel.on_select = [&nav, this](Button&) {
746+
nav.pop();
747+
};
748+
}
749+
750+
void SetButtonsView::focus() {
751+
button_save.focus();
752+
}
753+
724754
/* AppSettingsView ************************************/
725755

726756
AppSettingsView::AppSettingsView(
@@ -1067,6 +1097,7 @@ void SettingsMenuView::on_populate() {
10671097
{"Converter", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetConverterSettingsView>(); }},
10681098
{"Date/Time", ui::Color::dark_cyan(), &bitmap_icon_options_datetime, [this]() { nav_.push<SetDateTimeView>(); }},
10691099
{"Encoder Dial", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetEncoderDialView>(); }},
1100+
{"Button Speed", ui::Color::dark_cyan(), &bitmap_icon_controls, [this]() { nav_.push<SetButtonsView>(); }},
10701101
{"Freq. Correct", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetFrequencyCorrectionView>(); }},
10711102
{"P.Memory Mgmt", ui::Color::dark_cyan(), &bitmap_icon_memory, [this]() { nav_.push<SetPersistentMemoryView>(); }},
10721103
{"Radio", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetRadioView>(); }},

firmware/application/apps/ui_settings.hpp

+41
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,47 @@ class SetEncoderDialView : public View {
615615
};
616616
};
617617

618+
class SetButtonsView : public View {
619+
public:
620+
SetButtonsView(NavigationView& nav);
621+
void focus() override;
622+
std::string title() const override { return "Button Speed"; };
623+
624+
private:
625+
Labels labels{
626+
{{2 * 8, 4 * 16}, "Repeat delay:", Theme::getInstance()->fg_light->foreground},
627+
{{2 * 8, 6 * 16}, "Repeat speed:", Theme::getInstance()->fg_light->foreground},
628+
{{2 * 8, 8 * 16}, "Long press delay:", Theme::getInstance()->fg_light->foreground},
629+
};
630+
631+
OptionsField field_repeat_delay{
632+
{20 * 8, 4 * 16},
633+
6,
634+
{{"NORMAL", false},
635+
{"FAST", true}}};
636+
637+
OptionsField field_repeat_speed{
638+
{20 * 8, 6 * 16},
639+
6,
640+
{{"NORMAL", false},
641+
{"FAST", true}}};
642+
643+
OptionsField field_long_press_delay{
644+
{20 * 8, 8 * 16},
645+
6,
646+
{{"NORMAL", false},
647+
{"FAST", true}}};
648+
649+
Button button_save{
650+
{2 * 8, 16 * 16, 12 * 8, 32},
651+
"Save"};
652+
653+
Button button_cancel{
654+
{16 * 8, 16 * 16, 12 * 8, 32},
655+
"Cancel",
656+
};
657+
};
658+
618659
class SetPersistentMemoryView : public View {
619660
public:
620661
SetPersistentMemoryView(NavigationView& nav);

firmware/application/hw/debounce.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bool Debounce::feed(const uint8_t bit) {
8484
// (by toggling reported state every 1/2 of the delay time)
8585
if (--repeat_ctr_ == 0) {
8686
state_to_report_ = !state_to_report_;
87-
repeat_ctr_ = REPEAT_SUBSEQUENT_DELAY / 2;
87+
repeat_ctr_ = portapack::persistent_memory::ui_button_repeat_speed() ? REPEAT_SUBSEQUENT_DELAY_FAST / 2 : REPEAT_SUBSEQUENT_DELAY_NORMAL / 2;
8888
return true;
8989
}
9090
}
@@ -96,15 +96,15 @@ bool Debounce::feed(const uint8_t bit) {
9696
// if LONG_PRESS_DELAY is reached then finally report that switch is pressed and set flag
9797
// indicating it was a LONG press
9898
// (note that repeat_support and long_press support are mutually exclusive)
99-
if (held_time_ >= LONG_PRESS_DELAY) {
99+
if (held_time_ >= (portapack::persistent_memory::ui_button_long_press_delay() ? LONG_PRESS_DELAY_FAST : LONG_PRESS_DELAY_NORMAL)) {
100100
pulse_upon_release_ = false;
101101
long_press_occurred_ = true;
102102
state_to_report_ = 1;
103103
return true;
104104
}
105105
} else if (repeat_enabled_ && !long_press_enabled_) {
106106
// Repeat support -- 4 directional buttons only (unless long_press is enabled)
107-
if (held_time_ >= REPEAT_INITIAL_DELAY) {
107+
if (held_time_ >= (portapack::persistent_memory::ui_button_repeat_delay() ? REPEAT_INITIAL_DELAY_FAST : REPEAT_INITIAL_DELAY_NORMAL)) {
108108
// Delay reached; trigger repeat code on NEXT tick
109109
repeat_ctr_ = 1;
110110
held_time_ = 0;

firmware/application/hw/debounce.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
#define DEBOUNCE_MASK ((1 << DEBOUNCE_COUNT) - 1)
3131

3232
// # of timer0 ticks before a held button starts being counted as repeated presses
33-
#define REPEAT_INITIAL_DELAY 250
34-
#define REPEAT_SUBSEQUENT_DELAY 92
35-
#define LONG_PRESS_DELAY 800
33+
#define REPEAT_INITIAL_DELAY_NORMAL 250
34+
#define REPEAT_SUBSEQUENT_DELAY_NORMAL 92
35+
#define LONG_PRESS_DELAY_NORMAL 800
36+
37+
#define REPEAT_INITIAL_DELAY_FAST 180
38+
#define REPEAT_SUBSEQUENT_DELAY_FAST 60
39+
#define LONG_PRESS_DELAY_FAST 550
3640

3741
class Debounce {
3842
public:

firmware/common/portapack_persistent_memory.cpp

+25-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct ui_config_t {
103103
uint8_t show_gui_return_icon : 1;
104104
uint8_t load_app_settings : 1;
105105
uint8_t save_app_settings : 1;
106-
uint8_t UNUSED_1 : 1; // Deprecated, but bit can be set by older firmware
106+
uint8_t UNUSED_7 : 1; // Deprecated, but bit can be set by older firmware
107107

108108
bool disable_touchscreen : 1;
109109
bool hide_clock : 1;
@@ -134,9 +134,9 @@ struct ui_config2_t {
134134
bool hide_numeric_battery : 1;
135135
bool hide_battery_icon : 1;
136136
bool override_batt_calc : 1;
137-
bool UNUSED_4 : 1;
138-
bool UNUSED_5 : 1;
139-
bool UNUSED_6 : 1;
137+
bool button_repeat_delay : 1;
138+
bool button_repeat_speed : 1;
139+
bool button_long_press_delay : 1;
140140

141141
uint8_t theme_id;
142142
uint8_t PLACEHOLDER_3;
@@ -955,6 +955,15 @@ uint8_t ui_theme_id() {
955955
bool ui_override_batt_calc() {
956956
return data->ui_config2.override_batt_calc;
957957
}
958+
bool ui_button_repeat_delay() {
959+
return data->ui_config2.button_repeat_delay;
960+
}
961+
bool ui_button_repeat_speed() {
962+
return data->ui_config2.button_repeat_speed;
963+
}
964+
bool ui_button_long_press_delay() {
965+
return data->ui_config2.button_long_press_delay;
966+
}
958967

959968
void set_ui_hide_speaker(bool v) {
960969
data->ui_config2.hide_speaker = v;
@@ -1000,6 +1009,15 @@ void set_ui_theme_id(uint8_t theme_id) {
10001009
void set_ui_override_batt_calc(bool v) {
10011010
data->ui_config2.override_batt_calc = v;
10021011
}
1012+
void set_ui_button_repeat_delay(bool v) {
1013+
data->ui_config2.button_repeat_delay = v;
1014+
}
1015+
void set_ui_button_repeat_speed(bool v) {
1016+
data->ui_config2.button_repeat_speed = v;
1017+
}
1018+
void set_ui_button_long_press_delay(bool v) {
1019+
data->ui_config2.button_long_press_delay = v;
1020+
}
10031021

10041022
/* Converter */
10051023
bool config_converter() {
@@ -1262,7 +1280,6 @@ bool debug_dump() {
12621280
pmem_dump_file.write_line("ui_config show_gui_return_icon: " + to_string_dec_uint(data->ui_config.show_gui_return_icon));
12631281
pmem_dump_file.write_line("ui_config load_app_settings: " + to_string_dec_uint(data->ui_config.load_app_settings));
12641282
pmem_dump_file.write_line("ui_config save_app_settings: " + to_string_dec_uint(data->ui_config.save_app_settings));
1265-
// pmem_dump_file.write_line("ui_config show_bigger_qr_code: " + to_string_dec_uint(data->ui_config.show_large_qr_code));
12661283
pmem_dump_file.write_line("ui_config disable_touchscreen: " + to_string_dec_uint(data->ui_config.disable_touchscreen));
12671284
pmem_dump_file.write_line("ui_config hide_clock: " + to_string_dec_uint(data->ui_config.hide_clock));
12681285
pmem_dump_file.write_line("ui_config clock_with_date: " + to_string_dec_uint(data->ui_config.clock_show_date));
@@ -1287,6 +1304,9 @@ bool debug_dump() {
12871304
pmem_dump_file.write_line("ui_config2 hide_numeric_battery: " + to_string_dec_uint(data->ui_config2.hide_numeric_battery));
12881305
pmem_dump_file.write_line("ui_config2 theme_id: " + to_string_dec_uint(data->ui_config2.theme_id));
12891306
pmem_dump_file.write_line("ui_config2 override_batt_calc: " + to_string_dec_uint(data->ui_config2.override_batt_calc));
1307+
pmem_dump_file.write_line("ui_config2 button_repeat_delay: " + to_string_dec_uint(data->ui_config2.button_repeat_delay));
1308+
pmem_dump_file.write_line("ui_config2 button_repeat_speed: " + to_string_dec_uint(data->ui_config2.button_repeat_speed));
1309+
pmem_dump_file.write_line("ui_config2 button_long_press_delay: " + to_string_dec_uint(data->ui_config2.button_long_press_delay));
12901310

12911311
// misc_config bits
12921312
pmem_dump_file.write_line("misc_config config_audio_mute: " + to_string_dec_int(config_audio_mute()));

firmware/common/portapack_persistent_memory.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ bool ui_hide_battery_icon();
340340
bool ui_hide_sd_card();
341341
uint8_t ui_theme_id();
342342
bool ui_override_batt_calc();
343+
bool ui_button_repeat_delay();
344+
bool ui_button_repeat_speed();
345+
bool ui_button_long_press_delay();
343346
void set_ui_hide_speaker(bool v);
344347
void set_ui_hide_mute(bool v);
345348
void set_ui_hide_converter(bool v);
@@ -354,6 +357,9 @@ void set_ui_hide_battery_icon(bool v);
354357
void set_ui_hide_sd_card(bool v);
355358
void set_ui_theme_id(uint8_t v);
356359
void set_ui_override_batt_calc(bool v);
360+
void set_ui_button_repeat_delay(bool v);
361+
void set_ui_button_repeat_speed(bool v);
362+
void set_ui_button_long_press_delay(bool v);
357363

358364
// sd persisting settings
359365
bool should_use_sdcard_for_pmem();

0 commit comments

Comments
 (0)