I have a hilt with a rotating motor built in, and I’m thinking it would be nice to be able to switch it off when the core is in the hilt and you can’t see it. In the past I’ve done it using Blade Detect on hilts that have a removable core connecting to a fixed inner front core (if you see what I mean) so it works as a kind of chassis detect. And I know you can also do it using blade ID, but that creates a few variables when you use different blades.
The prop I use has a button control to run BladeID manually, but it occurs to me, since all I want is for the saber to be in one of two states, is it possible to tweak the prop so that that button press just switches from whichever preset array you’re on currently to the other array, regardless of what blade is or isn’t fitted?
No biggie if it can’t be done, but I thought it would be worth asking the question as it might be a nice little extra to have in the toolbox.
Thanks in advance.
Could something like this not be done with the Fett263 special abilities? Or some similar setup?
It can absolutely be done, but it will require a little coding.
Basically it’s a matter of taking FindBladeAgain() apart, and replace the part that uses blade ID to figure out what blade array entry to use with something else.
1 Like
Thanks Prof. Good to know it’s possible.
My little prop uses FindBladeAgain currently, but if I’ve understood it right, what that means is the Proffie basically asks the question “Which array should I use?”, then uses BladeID/Detect or whatever to answer it. I was thinking more of a simple, unambiguous toggle - if I’m on A go to B, and if I’m on B go to A.
Astro,
I don’t know too much about Special Abilities, but I was aiming more for a simple mod to be made to my preferred prop that could do it. (When I say “simple”, I mean simple to those who are fluent coders - which I’m not! LOL!).
1 Like
It seems you misunderstand, profezzorn and you are on the same page I believe. He’s saying to dissect that function to see where it does the switch, so you can use that code separately (with necessary modification) within your prop.
1 Like
Yeh, I get that, but unfortunately I run into the brick wall of my very limited coding knowledge. I’m guessing what I need is something like this in my prop:
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
void FindBladeAgain() {
if (!current_config) {
// FindBlade() hasn't been called yet - ignore this.
return;
}
// Reverse everything that FindBlade does.
// First free all styles, then allocate new ones to avoid memory
// fragmentation.
ONCEPERBLADE(UNSET_BLADE_STYLE)
#define DEACTIVATE(N) do { \
if (current_config->blade##N) \
current_config->blade##N->Deactivate(); \
} while(0);
ONCEPERBLADE(DEACTIVATE);
SaveVolumeIfNeeded();
FindBlade(true);
}
…except I can’t make it work.
I’ll keep experimenting over the weekend and report back if I crack it.
Maybe you could just use blade_present()
and have it toggle between a blade and NOBLADE set of preset arrays?
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
blade_present(preset_toggle_);
preset_toggle_ = !preset_toggle_;
return true;
private:
bool preset_toggle_ = true;
Thanks Brian. Yes, that’s the kind of thing I mean - a simple toggle without being based any other factors beyond the button press.
Unfortunately I’ve just tried it in my prop and I’m getting ‘preset_toggle_’ was not declared in this scope and expected primary-expression before ‘private’ errors.
But yes, if that can be made to work, that 's exactly what I need.
blade_present_ only exists if you have blade detect, and if you do, it’s controlled by the blade detect pin.
Although I suppose you could enable blade detect, but use a pin that isn’t used for anything…
Hmmm… just tried that pointing it to Button 3 which isn’t in use, but still got the same errors. Feels like we’re getting very warm though!
Hmm, now that I read that back I realize that I answered the wrong question, probably just adding confusion…
Here is a way that should work though:
// This goes in the prop file, but not in the prop class.
struct FakeBladeID {
static int return_value;
float id() { return return_value; }
void toggle() {
return_value = NO_BLADE - return_value;
}
};
int FakeBladeID::return_value = 0;
#undef BLADE_ID_CLASS_INTERNAL
#define BLADE_ID_CLASS_INTERNAL FakeBladeID
#undef BLADE_ID_CLASS
#define BLADE_ID_CLASS FakeBladeID
// In the prop where you want to toggle you add:
FakeBladeId::toggle();
FindBladeAgain();
1 Like
Hmmm… it still doesn’t quite like it.
This is what I pasted into the prop:
// *****************
// Switch between blade arrays manually.
// This goes in the prop file, but not in the prop class:
struct FakeBladeID {
static int return_value;
float id() { return return_value; }
void toggle() {
return_value = NO_BLADE - return_value;
}
};
int FakeBladeID::return_value = 0;
#undef BLADE_ID_CLASS_INTERNAL
#define BLADE_ID_CLASS_INTERNAL FakeBladeID
#undef BLADE_ID_CLASS
#define BLADE_ID_CLASS FakeBladeID
// In the prop where you want to toggle you add:
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
FakeBladeId::toggle();
FindBladeAgain();
// *****************
And this is the error message I got:
In file included from /Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/config/sabersense_acolyte_v5.h:245,
from /Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/ProffieOS.ino:629:
/Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/props/saber_chris_2_button_v20.h: In member function 'virtual bool SabersenseSA22Cv20::Event2(BUTTON, EVENT, uint32_t)':
/Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/props/saber_chris_2_button_v20.h:739:15: error: local class 'struct SabersenseSA22Cv20::Event2(BUTTON, EVENT, uint32_t)::FakeBladeID' shall not have static data member 'int SabersenseSA22Cv20::Event2(BUTTON, EVENT, uint32_t)::FakeBladeID::return_value' [-fpermissive]
739 | static int return_value;
| ^~~~~~~~~~~~
/Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/props/saber_chris_2_button_v20.h:745:31: error: qualified-id in declaration before '=' token
745 | int FakeBladeID::return_value = 0;
| ^
/Volumes/Sabersense Media/* Customer SD Cards/Lost Acolyte/ProffieOS 7.14f/ProffieOS/props/saber_chris_2_button_v20.h:753:7: error: 'FakeBladeId' has not been declared
753 | FakeBladeId::toggle();
| ^~~~~~~~~~~
exit status 1
Error compiling for board Proffieboard V3.
Is there another file I need to mod, or should it all be done from the prop?
According to the error you’ve placed FakeBladeID
inside of Event2
, which is where those errors stem from.
Chris, put the FakeBladeId code block outside (like right above )
bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
switch (EVENTID(button, event, modifiers)) {
which contains all your cases for button events.
Sorry guys - it still doesn’t seem quite happy.
error: invalid use of qualified-name 'SabersenseSA22Cv20::FakeBladeID::return_value'
339 | int FakeBladeID::return_value = 0;
| ^
error: 'FakeBladeId' has not been declared
757 | FakeBladeId::toggle();
| ^~~~~~~~~~~
Does something need adding to the .ino file?
Oh, put it outside the SabersenseSA22Cv20 class too. So not just above the Event2, but up above where you have class SabersenseSA22Cv20
1 Like
OK, we’re down to one last error.
This is it:
error: cannot call member function 'void FakeBladeID::toggle()' without object
757 | FakeBladeID::toggle();
| ^
exit status 1
And this is the bit around that line:
// ********************
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
FakeBladeID::toggle();
FindBladeAgain();
// ********************
maybe make it static void toggle() {
?
1 Like
Add static
before the toggle function declaration (before void
).
2 Likes
Thanks so much for all your help with this guys - we are now agonisingly close…
It compiles and uploads, but it doesn’t seem to actually perform the blade detect toggle when I hit the button.
My first attempt had this for the button command, as per the instructions above:
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
FakeBladeID::toggle();
FindBladeAgain();
But all that happened when I tried the triple-click was the blade would light mute and it wouldn’t run any kind of detect. At first I though button conflict, but lighting mute in my prop is a single long-held click so that seemed unlikely.
So I modded the above to look like this:
case EVENTID(BUTTON_POWER, EVENT_THIRD_SAVED_CLICK_SHORT, MODE_OFF):
FakeBladeID::toggle();
FindBladeAgain();
SaberBase::DoBladeDetect(true);
return true;
This ran the detect, as evidenced by the bladein beep sound, but it doesn’t actually switch to a different array.
If anyone has any ideas for one last stab at it, that would be amazing, but I realise this has already sucked up lots of your time - for which I’m extremely grateful, But I don’t want to exhaust everyone’s good will, so if it turns out that this one defeats us then c’est la vie.