Add the feature to decide rotate direction of encoder (#2472)

This commit is contained in:
sommermorgentraum 2025-01-09 04:02:05 +08:00 committed by GitHub
parent dfa35b4290
commit 55db0e8c87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 17 deletions

View File

@ -711,10 +711,12 @@ SetEncoderDialView::SetEncoderDialView(NavigationView& nav) {
&button_dial_sensitivity_plus,
&button_dial_sensitivity_minus,
&button_rate_multiplier_plus,
&button_rate_multiplier_minus});
&button_rate_multiplier_minus,
&field_encoder_dial_direction});
field_encoder_dial_sensitivity.set_by_value(pmem::encoder_dial_sensitivity());
field_encoder_rate_multiplier.set_value(pmem::encoder_rate_multiplier());
field_encoder_dial_direction.set_by_value(pmem::encoder_dial_direction());
button_dial_sensitivity_plus.on_select = [this](Button&) {
field_encoder_dial_sensitivity.on_encoder(1);
@ -732,6 +734,7 @@ SetEncoderDialView::SetEncoderDialView(NavigationView& nav) {
button_save.on_select = [&nav, this](Button&) {
pmem::set_encoder_dial_sensitivity(field_encoder_dial_sensitivity.selected_index_value());
pmem::set_encoder_rate_multiplier(field_encoder_rate_multiplier.value());
pmem::set_encoder_dial_direction(field_encoder_dial_direction.selected_index_value());
nav.pop();
};

View File

@ -574,6 +574,7 @@ class SetQRCodeView : public View {
};
};
using portapack::persistent_memory::encoder_dial_direction;
using portapack::persistent_memory::encoder_dial_sensitivity;
using portapack::persistent_memory::encoder_rate_multiplier;
@ -587,44 +588,50 @@ class SetEncoderDialView : public View {
private:
Labels labels{
{{1 * 8, 1 * 16}, "Adjusts sensitivity to dial", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 2 * 16}, "rotation position (number of", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 3 * 16}, "steps per full rotation):", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 5 * 16}, "Dial sensitivity:", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 8 * 16}, "Adjusts sensitivity to dial", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 9 * 16}, "rotation rate (default 1", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 10 * 16}, "means no rate dependency):", Theme::getInstance()->fg_light->foreground},
{{3 * 8, 12 * 16}, "Rate multiplier:", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 0 * 16}, "Sensitivity to dial rotation", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 1 * 16}, "position (x steps per 360):", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 3 * 16}, "Sensitivity:", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 7 * 16}, "Rotation rate (default 1", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 8 * 16}, "means no rate dependency):", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 10 * 16}, "Rate multiplier:", Theme::getInstance()->fg_light->foreground},
{{4 * 8, 14 * 16}, "Direction:", Theme::getInstance()->fg_light->foreground},
};
OptionsField field_encoder_dial_sensitivity{
{20 * 8, 5 * 16},
{20 * 8, 3 * 16},
6,
{{"LOW", encoder_dial_sensitivity::DIAL_SENSITIVITY_LOW},
{"NORMAL", encoder_dial_sensitivity::DIAL_SENSITIVITY_NORMAL},
{"HIGH", encoder_dial_sensitivity::DIAL_SENSITIVITY_HIGH}}};
NumberField field_encoder_rate_multiplier{
{20 * 8, 12 * 16},
{20 * 8, 10 * 16},
2,
{1, 15},
1,
' '};
OptionsField field_encoder_dial_direction{
{18 * 8, 14 * 16},
7,
{{"NORMAL", encoder_dial_direction::DIAL_DIRECTION_NORMAL},
{"REVERSE", encoder_dial_direction::DIAL_DIRECTION_REVERSE}}};
Button button_dial_sensitivity_plus{
{20 * 8, 4 * 16, 16, 16},
{20 * 8, 2 * 16, 16, 16},
"+"};
Button button_dial_sensitivity_minus{
{20 * 8, 6 * 16, 16, 16},
{20 * 8, 4 * 16, 16, 16},
"-"};
Button button_rate_multiplier_plus{
{20 * 8, 11 * 16, 16, 16},
{20 * 8, 9 * 16, 16, 16},
"+"};
Button button_rate_multiplier_minus{
{20 * 8, 13 * 16, 16, 16},
{20 * 8, 11 * 16, 16, 16},
"-"};
Button button_save{

View File

@ -66,6 +66,11 @@ int_fast8_t Encoder::update(const uint_fast8_t phase_bits) {
if (direction == prev_direction) {
if ((sensitivity_map[portapack::persistent_memory::encoder_dial_sensitivity()] & (1 << state)) == 0)
return 0;
// true: normal, false: reverse
if (!portapack::persistent_memory::encoder_dial_direction())
direction = -direction;
return direction;
}

View File

@ -212,7 +212,7 @@ struct data_t {
bool updown_frequency_rx_correction;
bool updown_frequency_tx_correction;
bool lcd_inverted_mode : 1;
bool UNUSED_5 : 1;
bool encoder_dial_direction : 1; // true = normal, false = reverse
bool UNUSED_6 : 1;
bool UNUSED_7 : 1;
@ -290,7 +290,7 @@ struct data_t {
updown_frequency_rx_correction(false),
updown_frequency_tx_correction(false),
lcd_inverted_mode(false),
UNUSED_5(false),
encoder_dial_direction(false),
UNUSED_6(false),
UNUSED_7(false),
@ -417,6 +417,7 @@ void defaults() {
set_config_splash(true);
set_config_disable_external_tcxo(false);
set_encoder_dial_sensitivity(DIAL_SENSITIVITY_NORMAL);
set_encoder_dial_direction(true);
set_config_speaker_disable(true); // Disable AK4951 speaker by default (in case of OpenSourceSDRLab H2)
set_menu_color(Color::grey());
set_ui_hide_numeric_battery(true); // hide the numeric battery by default - no space to display it
@ -1080,6 +1081,13 @@ void set_encoder_rate_multiplier(uint8_t v) {
data->encoder_rate_multiplier = v;
}
bool encoder_dial_direction() {
return data->encoder_dial_direction;
}
void set_encoder_dial_direction(bool v) {
data->encoder_dial_direction = v;
}
// Recovery mode magic value storage
static data_t* data_direct_access = reinterpret_cast<data_t*>(memory::map::backup_ram.base());
@ -1246,6 +1254,7 @@ bool debug_dump() {
pmem_dump_file.write_line("frequency_tx_correction: " + to_string_dec_uint(data->frequency_tx_correction));
pmem_dump_file.write_line("encoder_dial_sensitivity: " + to_string_dec_uint(data->encoder_dial_sensitivity));
pmem_dump_file.write_line("encoder_rate_multiplier: " + to_string_dec_uint(data->encoder_rate_multiplier));
pmem_dump_file.write_line("encoder_dial_direction: " + to_string_dec_uint(data->encoder_dial_direction));
pmem_dump_file.write_line("headphone_volume_cb: " + to_string_dec_int(data->headphone_volume_cb));
pmem_dump_file.write_line("config_mode_storage: 0x" + to_string_hex(data->config_mode_storage, 8));
pmem_dump_file.write_line("dst_config: 0x" + to_string_hex((uint32_t)data->dst_config.v, 8));

View File

@ -120,6 +120,11 @@ enum encoder_dial_sensitivity {
NUM_DIAL_SENSITIVITY
};
enum encoder_dial_direction {
DIAL_DIRECTION_NORMAL = true,
DIAL_DIRECTION_REVERSE = false,
};
typedef union {
uint32_t v;
struct {
@ -252,6 +257,8 @@ uint8_t encoder_dial_sensitivity();
void set_encoder_dial_sensitivity(uint8_t v);
uint8_t encoder_rate_multiplier();
void set_encoder_rate_multiplier(uint8_t v);
bool encoder_dial_direction();
void set_encoder_dial_direction(bool v);
uint32_t config_mode_storage_direct();
void set_config_mode_storage_direct(uint32_t v);

1
firmware/tools/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/