From 2f405dfae74f77d2857243602a19e0f8919f6149 Mon Sep 17 00:00:00 2001 From: NoSloppy <53964195+NoSloppy@users.noreply.github.com> Date: Wed, 27 Nov 2024 06:21:38 -0500 Subject: [PATCH 1/3] add next/prev_preset() trampolines. --- ProffieOS.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ProffieOS.ino b/ProffieOS.ino index bbb1b6129..88fe9ac24 100644 --- a/ProffieOS.ino +++ b/ProffieOS.ino @@ -710,6 +710,8 @@ void prop_SetClashThreshold(int clash_threshold) { void prop_SaveState() { prop.SaveState(); } void prop_UpdateStyle() { prop.UpdateStyle(); } +void prop_next_preset() { prop.next_preset(); } +void prop_previous_preset() { prop.previous_preset(); } #ifdef DYNAMIC_BLADE_LENGTH int prop_GetBladeLength(int blade) { From 3ab838360c86bfb53d98a600de75a2b8a0151b62 Mon Sep 17 00:00:00 2001 From: NoSloppy <53964195+NoSloppy@users.noreply.github.com> Date: Wed, 27 Nov 2024 06:33:16 -0500 Subject: [PATCH 2/3] make Scroll Presets a mode. --- props/saber_BC_buttons.h | 106 +++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/props/saber_BC_buttons.h b/props/saber_BC_buttons.h index 15017db21..4f86ee15b 100644 --- a/props/saber_BC_buttons.h +++ b/props/saber_BC_buttons.h @@ -1153,6 +1153,52 @@ EFFECT(tr); // for EFFECT_TRANSITION_SOUND, use with User Effects. EFFECT(mute); // Notification before muted ignition to avoid confusion. EFFECT(mzoom); // for Spam Blast enter/exit +template +struct BCScrollPresetsMode : public SPEC::SteppedMode { + int steps_per_revolution() override { + return 12; // adjust for sensitivity + } + + void next() override { + beeper.Beep(0.05, 4000); + prop_next_preset(); + } + + void prev() override { + beeper.Beep(0.05, 3000); + prop_previous_preset(); + } + + void update() override { // Overridden to substitute the tick sound + } + + void exit() override { + PVLOG_NORMAL << "** Exit Scroll Presets\n"; + beeper.Beep(0.05, 3000); + beeper.Silence(0.05); + beeper.Beep(0.05, 3000); + beeper.Silence(0.05); + beeper.Beep(0.10, 2000); + SPEC::SteppedMode::exit(); + } + + bool mode_Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override { + switch (EVENTID(button, event, 0)) { + + case EVENTID(BUTTON_POWER, EVENT_FIRST_SAVED_CLICK_SHORT, 0): + SaberBase::TurnOn(); + exit(); + return true; + + // case EVENTID(BUTTON_POWER, EVENT_SECOND_SAVED_CLICK_SHORT, 0): + case EVENTID(BUTTON_POWER, EVENT_FIRST_HELD_MEDIUM, 0): + exit(); + return true; + } + return false; + } +}; + template struct BCVolumeMode : public SPEC::SteppedMode { const int max_volume_ = VOLUME; @@ -1343,6 +1389,7 @@ struct BCChangeBladeLengthBlade1 : public mode::ChangeBladeLengthBlade1 { template struct BCMenuSpec { typedef BCVolumeMode BCVolumeMenu; + typedef BCScrollPresetsMode BCScrollPresetsMenu; #ifdef DYNAMIC_BLADE_LENGTH typedef BCSelectBladeMode BCSelectBladeMenu; typedef mode::ShowLengthStyle ShowLengthStyle; @@ -1400,7 +1447,7 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { #if defined(DYNAMIC_BLADE_LENGTH) && !defined(MENU_SPEC_TEMPLATE) void EnterBladeLengthMode() { - if (scroll_presets_ || !current_style()) return; + if (!current_style()) return; if (current_mode == this) { sound_library_.SayEditBladeLength(); @@ -1415,7 +1462,7 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { #endif // DYNAMIC_BLADE_LENGTH void EnterVolumeMenu() { - if (!current_style() || scroll_presets_) return; + if (!current_style()) return; if (current_mode == this) { #ifdef MENU_SPEC_TEMPLATE sound_library_.SayEditVolume(); @@ -1517,7 +1564,7 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { } #endif // Delaying playing font.wav so that beep can be heard first. - if (scroll_presets_beep_delay_timer_.isTimerExpired() && scroll_presets_) { + if (scroll_presets_beep_delay_timer_.isTimerExpired()) { SaberBase::DoEffect(EFFECT_NEWFONT, 0); } if (twist_delay_timer_.isTimerExpired()) { @@ -1626,7 +1673,6 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { // Previous, next, or first preset, depending on blade angle void DoChangePreset() { - if (scroll_presets_) return; if (fusor.angle1() > M_PI / 3) { // Main Blade pointing UP first_preset(); @@ -1664,7 +1710,6 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { } void DoSpokenBatteryLevel() { - if (scroll_presets_) return; // Avoid weird battery readings when using USB if (battery_monitor.battery() < 0.5) { sound_library_.SayTheBatteryLevelIs(); @@ -1689,14 +1734,13 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { } void OnDemandBatteryLevel() { - if (scroll_presets_) return; PVLOG_NORMAL << "Battery Voltage: " << battery_monitor.battery() << "\n"; PVLOG_NORMAL << "Battery Percentage: " < 300 && @@ -2512,18 +2537,9 @@ any # of buttons #endif return true; -// Toggle Scroll Presets - case EVENTID(BUTTON_POWER, EVENT_FIRST_HELD_MEDIUM, MODE_OFF): - scroll_presets_ = !scroll_presets_; - if (scroll_presets_) { - PVLOG_NORMAL << "** Enter Scroll Presets\n"; - BeepEnterFeature(); - scroll_presets_beep_delay_timer_.trigger(350); - } else { - PVLOG_NORMAL << "** Exit Scroll Presets\n"; - BeepExitFeature(); - // No need to play font.wav again when exiting - } +// Enter Scroll Presets + case EVENTID(BUTTON_POWER, EVENT_FIRST_HELD_LONG, MODE_OFF): + EnterScrollPresets(); return true; // Auto Swing Blast @@ -2603,49 +2619,41 @@ any # of buttons // User Effects a.k.a. "Special Abilities" ©Fett263 case EVENTID(BUTTON_NONE, EVENT_TWIST_LEFT, MODE_ON | BUTTON_POWER): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER1 **\n"; SaberBase::DoEffect(EFFECT_USER1, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_RIGHT, MODE_ON | BUTTON_POWER): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER2 **\n"; SaberBase::DoEffect(EFFECT_USER2, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_LEFT, MODE_ON | BUTTON_AUX): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER3 **\n"; SaberBase::DoEffect(EFFECT_USER3, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_RIGHT, MODE_ON | BUTTON_AUX): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER4 **\n"; SaberBase::DoEffect(EFFECT_USER4, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_LEFT, MODE_OFF | BUTTON_POWER): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER5 **\n"; SaberBase::DoEffect(EFFECT_USER5, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_RIGHT, MODE_OFF | BUTTON_POWER): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER6 **\n"; SaberBase::DoEffect(EFFECT_USER6, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_LEFT, MODE_OFF | BUTTON_AUX): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER7 **\n"; SaberBase::DoEffect(EFFECT_USER7, 0); return true; case EVENTID(BUTTON_NONE, EVENT_TWIST_RIGHT, MODE_OFF | BUTTON_AUX): - if (scroll_presets_) return false; PVLOG_NORMAL << "** EFFECT_USER8 **\n"; SaberBase::DoEffect(EFFECT_USER8, 0); return true; @@ -2715,7 +2723,6 @@ any # of buttons } return; case EFFECT_IGNITION: - scroll_presets_ = false; saber_on_time_ = millis(); return; case EFFECT_TRANSITION_SOUND: @@ -2772,7 +2779,6 @@ any # of buttons bool sequential_quote_ = false; bool spam_blast_ = false; bool speaking_ = false; // Don't play battery.wav when doing Spoken Battery Level - bool scroll_presets_ = false; bool muted_ = false; bool forward_stab_ = false; bool overlap_timer_initialized_ = false; From af459c234103a12ce4ca6e87bf043b5803103516 Mon Sep 17 00:00:00 2001 From: NoSloppy <53964195+NoSloppy@users.noreply.github.com> Date: Wed, 27 Nov 2024 06:35:56 -0500 Subject: [PATCH 3/3] add EnterScrollPresets() helper function --- props/saber_BC_buttons.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/props/saber_BC_buttons.h b/props/saber_BC_buttons.h index 4f86ee15b..bf390a0db 100644 --- a/props/saber_BC_buttons.h +++ b/props/saber_BC_buttons.h @@ -1473,6 +1473,15 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase { } } + void EnterScrollPresets() { + if (current_mode == this) { + PVLOG_NORMAL << "** Enter Scroll Presets\n"; + BeepEnterFeature(); + scroll_presets_beep_delay_timer_.trigger(350); + pushMode::BCScrollPresetsMenu>(); + } + } + void Loop() override { PropBase::Loop(); DetectMenuTurn();