Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCprop - Make Scroll Presets a mode #705

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ProffieOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
115 changes: 65 additions & 50 deletions props/saber_BC_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class SPEC>
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<class SPEC>
struct BCVolumeMode : public SPEC::SteppedMode {
const int max_volume_ = VOLUME;
Expand Down Expand Up @@ -1339,6 +1385,7 @@ struct BCChangeBladeLengthBlade1 : public mode::ChangeBladeLengthBlade1<SPEC> {
template<class SPEC>
struct BCMenuSpec {
typedef BCVolumeMode<SPEC> BCVolumeMenu;
typedef BCScrollPresetsMode<SPEC> BCScrollPresetsMenu;
#ifdef DYNAMIC_BLADE_LENGTH
typedef BCSelectBladeMode<SPEC> BCSelectBladeMenu;
typedef mode::ShowLengthStyle<SPEC> ShowLengthStyle;
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand All @@ -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<MKSPEC<BCMenuSpec>::BCScrollPresetsMenu>();
}
}

void Loop() override {
PropBase::Loop();
DetectMenuTurn();
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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: " <<battery_monitor.battery_percent() << "\n";
SaberBase::DoEffect(EFFECT_BATTERY_LEVEL, 0);
}

void DoTrackStartOrStop() {
if (scroll_presets_ || spam_blast_) return;
if (spam_blast_) return;
PVLOG_NORMAL << "** Track playback Toggled\n";
StartOrStopTrack();
}
Expand Down Expand Up @@ -1743,7 +1796,7 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase {
}

void DoQuote() {
if (scroll_presets_ || spam_blast_) return;
if (spam_blast_) return;
if (overlap_timer_initialized_ && !overlap_delay_timer_.isTimerExpired()) return; // prevent overlapping.
overlap_timer_initialized_ = true;
if (SFX_quote) {
Expand All @@ -1761,7 +1814,7 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase {
}

void ToggleSequentialQuote() {
if (scroll_presets_ || spam_blast_) return;
if (spam_blast_) return;
sequential_quote_ = !sequential_quote_;
PVLOG_NORMAL << (sequential_quote_ ? "** Quotes play sequentially\n" : "** Quotes play randomly\n");
if (SFX_mnum) {
Expand Down Expand Up @@ -1984,24 +2037,6 @@ class SaberBCButtons : public PROP_INHERIT_PREFIX PropBase {
case EVENTID(BUTTON_AUX2, EVENT_PRESSED, MODE_ON):
return true;

// Volume Up
// Scroll Presets Next
case EVENTID(BUTTON_NONE, EVENT_TWIST_RIGHT, MODE_OFF):
if (scroll_presets_) {
beeper.Beep(0.05, 4000);
next_preset();
}
return true;

// Volume Down
// Scroll Presets Previous
case EVENTID(BUTTON_NONE, EVENT_TWIST_LEFT, MODE_OFF):
if (scroll_presets_) {
beeper.Beep(0.05, 3000);
previous_preset();
}
return true;

/*
Case structure below
1btn
Expand Down Expand Up @@ -2435,7 +2470,6 @@ any # of buttons

#ifdef BC_TWIST_ON
case EVENTID(BUTTON_NONE, EVENT_TWIST, MODE_OFF):
if (scroll_presets_) return false;
NoBladeDisableGestures();
// Delay twist events to prevent false trigger from over twisting
if (millis() - last_twist_millis_ > 300 &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2702,7 +2719,6 @@ any # of buttons
}
return;
case EFFECT_IGNITION:
scroll_presets_ = false;
saber_on_time_ = millis();
return;
case EFFECT_TRANSITION_SOUND:
Expand Down Expand Up @@ -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;
Expand Down