I think I’ve made some progress with this! Although I’m not sure it will be much use to you @olivierflying747-8 , since, as you say, you’re aiming for something rather more complex than me. But I’ll share my results anyway in case they’re useful…
So basically I’ve made it so that with no define in your config file, BladeID works as normal, but if you add two define lines to the config, you get the Sabersense Array Selector which can cycle through any number of blade arrays manually using a button press, with the actual returned BladeID values being ignored.
Before we get into the nuts and bolts of how it works, what are the pracatical applications for this?
Well, one way you could use it would be to split your fonts/presets into batches, like this:
Array 1 - Light Side Fonts
Array 2 - Dark Side Fonts
Array 3 - Blade Plug Charging Font
rray 4 - Diagnostic fonts (blade length finder etc.)
Or perhaps in installs with a rotating motor in the chassis, you might want to duplicate the preset list and just have one array that spins the motor and the other array that doesn’t. This would effectively make the Array Selector button press a motor on/off toggle switch.
Or how about setting your actual arrays up differently, so that with one array you have a main blade of 132 pixels, but on the other array, the main blade (i.e. the blade connector) just has the number of pixels on the connector, allowing for more elaborate animations.
Or what about if you have multiple blades, none of which have resistors in them between neg and data (which means BladeID can’t differentiate between them)? Well now you can set up three arrays, all with the same presets and fonts, but have one for your 36 inch 132 pixel blade, another for your shorter 118 pixel blade, and a third for your indoor shoto blade which only has 80 pixels.
I dare say there are lots of other possibilities too.
So how does it all work?
Well first you need to add this to the top of your prop file, just below the prop files title define lines, like this:
#ifndef PROPS_SABER_SABERSENSE_BUTTONS_H
#define PROPS_SABER_SABERSENSE_BUTTONS_H
#ifdef SABERSENSE_ARRAY_SELECTOR
#ifndef SABERSENSE_NUM_ARRAYS // No default number of arrays - must be defined in config.
#error "SABERSENSE_NUM_ARRAYS must be defined in the config file."
#endif
struct SabersenseArraySelector {
static int return_value; // Tracks the current array index.
static const int sabersense_num_arrays = SABERSENSE_NUM_ARRAYS;
float id() {
return return_value;
} // Return the current array index.
// New method for cycling through the arrays, using the defined num_arrays.
static void cycle() {
return_value = (return_value + 1) % sabersense_num_arrays;
}
};
int SabersenseArraySelector::return_value = 0; // Start with the first array (index 0).
#undef BLADE_ID_CLASS_INTERNAL
#define BLADE_ID_CLASS_INTERNAL SabersenseArraySelector
#undef BLADE_ID_CLASS
#define BLADE_ID_CLASS SabersenseArraySelector
#endif
Then add these two to the list of defines in the prop:
#ifdef SABERSENSE_ARRAY_SELECTOR
#define SABERSENSE_ARRAY_SELECTOR
#endif
#ifdef SABERSENSE_NUM_ARRAYS
#define SABERSENSE_NUM_ARRAYS
#endif
Next add this section somewhere within all the event handlers of the prop:
// BladeID and manual blade array selector.
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
#ifdef SABERSENSE_ARRAY_SELECTOR
// Cycles through blade arrays regardless of BladeID status.
SabersenseArraySelector::cycle();
FindBladeAgain();
SaberBase::DoBladeDetect(true);
return true;
#else
// Runs BladeID manually to actually check BladeID status.
// Won't change arrays unless status tells it to (i.e. Data/Neg resistance changes).
FindBladeAgain();
SaberBase::DoBladeDetect(true);
return true;
#endif
Then add these two defines to the top of your config. The number on the second define needs to be the number of blade arrays in your config:
#define SABERSENSE_ARRAY_SELECTOR
#define SABERSENSE_NUM_ARRAYS 4
And finally lay out your actual blade arrays, each with sequential ident numbers starting at zero, like this:
BladeConfig blades[] = {
// Use sequential numbers starting at 0 if using Sabersense Array Selector.
{ 0,
// Main Blade:
WS281XBladePtr<8, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3>>(),
// Bluetooth Module:
SimpleBladePtr<Bluetooth, NoLED, NoLED, NoLED, bladePowerPin6, -1, -1, -1>(),
CONFIGARRAY(noblade), "Savehilt"}
{ 1,
// Main Blade:
WS281XBladePtr<68, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3>>(),
// Bluetooth Module:
SimpleBladePtr<Bluetooth, NoLED, NoLED, NoLED, bladePowerPin6, -1, -1, -1>(),
CONFIGARRAY(testblde), "Savetest"}
{ 2,
// Main Blade:
WS281XBladePtr<114, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3>>(),
// Bluetooth Module:
SimpleBladePtr<Bluetooth, NoLED, NoLED, NoLED, bladePowerPin6, -1, -1, -1>(),
CONFIGARRAY(lgtblade), "Savelgt"}
{ 3,
// Main Blade:
WS281XBladePtr<10, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3>>(),
// Bluetooth Module:
SimpleBladePtr<Bluetooth, NoLED, NoLED, NoLED, bladePowerPin6, -1, -1, -1>(),
CONFIGARRAY(charging), "SaveChrg"}
};
#endif
All arrays must have the same number of blades, though you can always specify dummy blades if you have to, and each array needs to have its presets added to the blade style array. The names in inverted commas specify the location of save files. This means when you switch array, it will return to the blade preset you left the saber on when you were last on that array.
I’ve tested it and it all seems to work at my end. So my next challenge is to make it play unique array ident sound effects to tell you which array you’ve switched to. But that’s a work in progress - if I crack it, I’ll report back here.