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) { diff --git a/props/saber_BC_buttons.h b/props/saber_BC_buttons.h index 8a94a1018..967fa9afd 100644 --- a/props/saber_BC_buttons.h +++ b/props/saber_BC_buttons.h @@ -1149,6 +1149,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; @@ -1339,6 +1385,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; @@ -1396,7 +1443,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(); @@ -1411,7 +1458,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(); @@ -1422,6 +1469,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(); @@ -1513,7 +1569,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()) { @@ -1622,7 +1678,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(); @@ -1660,7 +1715,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(); @@ -1685,14 +1739,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 && @@ -2499,18 +2533,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 @@ -2590,49 +2615,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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** 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_DEBUG << "**** EFFECT_USER8 **\n"; SaberBase::DoEffect(EFFECT_USER8, 0); return true; @@ -2702,7 +2719,6 @@ any # of buttons } return; case EFFECT_IGNITION: - scroll_presets_ = false; saber_on_time_ = millis(); return; case EFFECT_TRANSITION_SOUND: @@ -2759,7 +2775,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;