Skip to content

Commit 8294a64

Browse files
Improved preset skipping in Sabersense Prop. (#810)
1 parent 7da651a commit 8294a64

File tree

1 file changed

+110
-40
lines changed

1 file changed

+110
-40
lines changed

props/saber_sabersense_buttons.h

Lines changed: 110 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/* V7/8-260.
22
============================================================
33
================= SABERSENSE PROP FILE =================
44
================= by =================
@@ -95,9 +95,13 @@ FUNCTIONS WITH BLADE OFF
9595
Skip to first preset Press and hold until it switches, hilt pointing upwards.
9696
Skip to middle preset Press and hold until it switches, hilt horizontal.
9797
Skip to last preset Press and hold until it switches, hilt pointing downwards.
98+
Skip forward 5 presets Fast double-click-and-hold, hilt pointing upwards.
99+
Skip back 5 presets Fast double-click-and-hold, hilt pointing downwards.
100+
Skip forward 10 presets Fast triple-click-and-hold, hilt pointing upwards.
101+
Skip back 10 presets Fast triple-click-and-hold, hilt pointing downwards.
98102
Play Character Quote Fast double-click, hilt pointing up, plays sequentially. **
99103
Play Music Track Fast double-click, hilt pointing down. **
100-
Speak battery voltage Fast double-click-and-hold while OFF.
104+
Speak battery voltage Fast double-click-and-hold, hilt horizontal.
101105
Run BladeID/Array Select Fast triple-click while OFF. (Applicable installs only).
102106
Restore Factory Defaults Fast four-clicks while OFF, hold on last click.
103107
Release once announcement starts.
@@ -260,15 +264,23 @@ COLOUR CHANGE FUNCTIONS WITH BLADE ON
260264
but makes accidental blasts more likely when double-
261265
clicking POWER for Quotes or Force Effect.
262266
263-
#define SABERSENSE_HOT_SKIP_DOWN 23
264-
#define SABERSENSE_HOT_SKIP_LEVEL 9
267+
#define SABERSENSE_FONT_SKIP_A 5
268+
#define SABERSENSE_FONT_SKIP_B 10
269+
As standard, presets can be skipped in batches to aid
270+
font navigation. Two skip levels are provided, A and B,
271+
which default to 5 and 10 fonts respectively. These
272+
defines allow the user to override the default
273+
valuesif required.
274+
275+
#define SABERSENSE_HOT_SKIP_DOWN 0
276+
#define SABERSENSE_HOT_SKIP_LEVEL 0
265277
Hot Skipping is distinct from Font Skipping in that
266278
it skips directly to a given preset, rather than
267279
skipping forwards or backwards x number of presets.
268280
These defines override the Skip-to-Last/Middle
269-
Preset feature, so system skips to user-defined
270-
preset. Note that Skip-to-First preset is fixed
271-
and not user-definable.
281+
Preset feature, so that the system skips to a
282+
user-defined preset. Note that Skip-to-First
283+
preset is fixed and not user-definable.
272284
273285
#define SABERSENSE_DISABLE_FONT_SKIPPING
274286
Completely disables all preset skipping, meaning
@@ -384,6 +396,14 @@ class SaveArrayStateFile : public ConfigFile {
384396
#define BUTTON_HELD_MEDIUM_TIMEOUT 1000
385397
#endif
386398

399+
#ifndef SABERSENSE_FONT_SKIP_A
400+
#define SABERSENSE_FONT_SKIP_A 5
401+
#endif
402+
403+
#ifndef SABERSENSE_FONT_SKIP_B
404+
#define SABERSENSE_FONT_SKIP_B 10
405+
#endif
406+
387407
// Hot Skip values are placeholders only.
388408
#ifndef SABERSENSE_HOT_SKIP_DOWN
389409
#define SABERSENSE_HOT_SKIP_DOWN 0
@@ -497,6 +517,45 @@ class SabersenseButtons : public PROP_INHERIT_PREFIX PropBase {
497517
#endif
498518
}
499519

520+
// PRESET SKIPPING
521+
// Skip Value definable.
522+
int GetNumberOfPresets() {
523+
CurrentPreset tmp;
524+
tmp.SetPreset(-1);
525+
return tmp.preset_num + 1;
526+
}
527+
528+
// Two Button system: Up/Down only - loose angle settings for ease of use.
529+
bool MultiFontSkip(int skip_value) {
530+
float angle = fusor.angle1();
531+
int delta = 0;
532+
533+
#if NUM_BUTTONS == 2
534+
delta = (angle < -M_PI / 4) ? -skip_value : skip_value;
535+
#elif NUM_BUTTONS == 1
536+
if (angle < -M_PI / 6) { // Pointing down
537+
delta = -skip_value;
538+
} else if (angle > M_PI / 6) { // Pointing up
539+
delta = skip_value;
540+
} else {
541+
SpeakBatteryLevel();
542+
return true;
543+
}
544+
#endif
545+
int count = GetNumberOfPresets();
546+
int new_index = current_preset_.preset_num + delta;
547+
// Capping/Clamping, not wrapping - less disorienting for user.
548+
if (new_index < 0) new_index = 0;
549+
if (new_index >= count) new_index = count - 1;
550+
551+
#ifdef SAVE_PRESET
552+
SaveState(new_index);
553+
#endif
554+
555+
SetPreset(new_index, true);
556+
return true;
557+
}
558+
500559
// VOLUME MENU
501560
void VolumeUp() {
502561
STDOUT.println("Volume up");
@@ -541,6 +600,16 @@ class SabersenseButtons : public PROP_INHERIT_PREFIX PropBase {
541600
STDOUT.print("Minimum Volume: ");
542601
}
543602
}
603+
604+
// BATTERY LEVEL INDICATOR
605+
void SpeakBatteryLevel() {
606+
talkie.SayDigit((int)floorf(battery_monitor.battery()));
607+
talkie.Say(spPOINT);
608+
talkie.SayDigit(((int)floorf(battery_monitor.battery() * 10)) % 10);
609+
talkie.SayDigit(((int)floorf(battery_monitor.battery() * 100)) % 10);
610+
talkie.Say(spVOLTS);
611+
SaberBase::DoEffect(EFFECT_BATTERY_LEVEL, 0);
612+
}
544613

545614
// BLADE ID OPTIONS AND ARRAY MANAGEMENT
546615
// True BladeID, runs scan on-demand with unique 'bladeid' ident sound.
@@ -756,21 +825,21 @@ bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
756825
#if NUM_BUTTONS == 1
757826
case EVENTID(BUTTON_POWER, EVENT_FIRST_CLICK_LONG, MODE_OFF):
758827
IgnoreClash(100); // Hopefully prevents false clashes due to 'clicky' button.
759-
// Low threshold so as not to conflict with 1-button volume menu access.
760-
#define DEGREES_TO_RADIANS (M_PI / 180)
761-
if (fusor.angle1() > 45 * DEGREES_TO_RADIANS) {
762-
// If pointing up
828+
// Low threshold so as not to conflict with 1-button volume menu access.
829+
if (fusor.angle1() > M_PI / 6) {
830+
// Pointing up
763831
next_preset();
764-
} else if (fusor.angle1() < -45 * DEGREES_TO_RADIANS) {
765-
// If pointing down
832+
} else if (fusor.angle1() < -M_PI / 6) {
833+
// Pointing down
766834
previous_preset();
767835
} else {
768-
// If horizontal
836+
// Horizontal
769837
if (SetMute(true)) {
770838
unmute_on_deactivation_ = true;
771839
On();
772840
}
773841
}
842+
774843
#ifdef SAVE_PRESET
775844
SaveState(current_preset_.preset_num);
776845
#endif
@@ -829,25 +898,28 @@ bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
829898
return true;
830899
#endif
831900

832-
// Multiple preset skips - 2 button sabers only.
833-
#if NUM_BUTTONS == 2
834-
// Skips forward five presets pointing up, back five pointing down.
835-
case EVENTID(BUTTON_AUX, EVENT_SECOND_SAVED_CLICK_SHORT, MODE_OFF):
836-
// Backwards if pointing down
837-
SetPreset(current_preset_.preset_num + (fusor.angle1() < -M_PI / 4 ? -5 : 5), true);
838-
#ifdef SAVE_PRESET
839-
SaveState(current_preset_.preset_num);
840-
#endif
841-
return true;
842-
843-
// Skips forward ten presets pointing up, back ten pointing down.
844-
case EVENTID(BUTTON_AUX, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
845-
// Backwards if pointing down
846-
SetPreset(current_preset_.preset_num + (fusor.angle1() < -M_PI / 4 ? -10 : 10), true);
847-
#ifdef SAVE_PRESET
848-
SaveState(current_preset_.preset_num);
849-
#endif
850-
return true;
901+
// PRESET SKIPPING
902+
// Skips forward when pointing up, backward when pointing down.
903+
// Uses SABERSENSE_FONT_SKIP_A/B for skip values.
904+
#ifndef SABERSENSE_DISABLE_FONT_SKIPPING
905+
#if NUM_BUTTONS == 1
906+
// First skip value (define A - default 5)
907+
case EVENTID(BUTTON_POWER, EVENT_SECOND_HELD_MEDIUM, MODE_OFF): {
908+
return MultiFontSkip(SABERSENSE_FONT_SKIP_A);
909+
}
910+
// Second skip value (define B - default 10)
911+
case EVENTID(BUTTON_POWER, EVENT_THIRD_HELD_MEDIUM, MODE_OFF): {
912+
return MultiFontSkip(SABERSENSE_FONT_SKIP_B);
913+
}
914+
#else
915+
// First skip value (define A - default 5)
916+
case EVENTID(BUTTON_AUX, EVENT_SECOND_SAVED_CLICK_SHORT, MODE_OFF): {
917+
return MultiFontSkip(SABERSENSE_FONT_SKIP_A);
918+
}
919+
// Second skip value (define B - default 10)
920+
case EVENTID(BUTTON_AUX, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF): {
921+
return MultiFontSkip(SABERSENSE_FONT_SKIP_B);
922+
}
851923
#endif
852924

853925
// Skips to first preset (up), last or user-defined preset (down),
@@ -888,6 +960,7 @@ bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
888960
SetPreset(target_preset, true);
889961
break;
890962
}
963+
#endif
891964

892965
// BLADE ID OPTIONS AND ARRAY NAVIGATION
893966
// Blade ID on-demand scanning with BladeID audio idents.
@@ -1156,15 +1229,12 @@ bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
11561229
break;
11571230
#endif
11581231

1159-
// BATTERY LEVEL
1232+
// 1 Button feature handled in Preset Skipping unless skipping disabled.
1233+
#if (NUM_BUTTONS == 2) || (NUM_BUTTONS == 1 && defined(SABERSENSE_DISABLE_FONT_SKIPPING))
11601234
case EVENTID(BUTTON_POWER, EVENT_SECOND_HELD_MEDIUM, MODE_OFF):
1161-
talkie.SayDigit((int)floorf(battery_monitor.battery()));
1162-
talkie.Say(spPOINT);
1163-
talkie.SayDigit(((int)floorf(battery_monitor.battery() * 10)) % 10);
1164-
talkie.SayDigit(((int)floorf(battery_monitor.battery() * 100)) % 10);
1165-
talkie.Say(spVOLTS);
1166-
SaberBase::DoEffect(EFFECT_BATTERY_LEVEL, 0);
1235+
SpeakBatteryLevel();
11671236
return true;
1237+
#endif
11681238

11691239
#ifdef BLADE_DETECT_PIN
11701240
case EVENTID(BUTTON_BLADE_DETECT, EVENT_LATCH_ON, MODE_ANY_BUTTON | MODE_ON):

0 commit comments

Comments
 (0)