Crazy idea of the day - Constant Blade ID monitoring

This was a PM, but putting it here for public input.

Disclaimer - totally off-the-cuff experimental and likely might take up resources, be a bad idea in general, etc… but is working in testing by adding/removing any blade,
even a NPXL PCB first (detects the change), then add a blade on top of that (2nd change detected)
(They’re wired in parallel)
No BLADE_ID resistors are installed anywhere.

If you have bladein.wav, it will play that when detected.

Used these defines:
#define ENABLE_POWER_FOR_ID PowerPINS<bladePowerPin2, bladePowerPin3>
#define BLADE_ID_CLASS SnapshotBladeID
#define BLADE_ID_MONITORED

Edited the prop’s void Loop() to start like this:

BLADE_ID_CLASS_INTERNAL blade_id;
  void Loop() override {
    PropBase::Loop();
    DetectTwist();
    DetectShake();
#ifdef BLADE_ID_MONITORED
        if (millis() - last_blade_id_ > 2000) {
          STDOUT << "BLADE ID: OLD =  "<< looped_blade_id_ << "\n";
          blade_id.id();
          last_blade_id_ = millis();
          STDOUT << "BLADE ID: checked = "<< blade_id.id() << "\n";
          if (looped_blade_id_ > blade_id.id() + 100 || looped_blade_id_ < blade_id.id() - 100) {
            STDOUT << "BLADE ID: DIFFERENT ***** do something here\n";
            // beeper.Beep(0.5, 1000);
            FindBladeAgain();
            SaberBase::DoBladeDetect(true);
          }
          looped_blade_id_ = blade_id.id();
        }
#endif
    Vec3 mss = fusor.mss();
..................

and initialized these at the bottom

uint32_t last_blade_id_ = millis();
uint32_t looped_blade_id_ = 0;

Might need to be tweaked per setup:
ENABLE_POWER_FOR_ID’s bladePowerPins are your blade’s LED pads.

  • The id() +/- values.
  • The 2000 delay adjust to taste.
  • The detected values set in the BladeConfig.
    Use something reasonable based on what it shows in Serial Monitor for “BLADE ID: checked” for each state.
  • You can kill the beep if you use bladein.wav instead.

Terrible?

The reply:

I see. Yeah, it did work, nothing crapped out. Although I was not doing any effects, just inserting and removing things to make sure the right blade array was being chosen.

There may be caveats, but I think the key might be to do it before this line:

If I remember correctly, once IsReadyForEndFrame() is true, that particular PIN is not transmitting, which means that we can call FindBladeAgain() if we want to.

The tricky part is that this class might have been deleted once we return from FindBladeAgain(), which means there is some hoops to jump through to make sure that it works properly.

There is also a possibility that calling findblade all the time will count as to the neopixels and cause glitches on the blade, but one step at a time I guess…

For anyone reading this, the latest to test would be
#define BLADE_ID_SCAN_MILLIS 1000
where millis is the blade ID scan interval.
If the blade ID comes out the same as before, it will do nothing. If it comes out different, it will do FindBladeAgain(), which will basically initialize the saber from scratch and load the right settings for the new id().
It will only work with neopixel blades, and it probably requires
#define SHARED_POWER_PINS to work.

“The force works in mysterious ways.”

NICE! I know a youngling and three people not running EditMode that could stand to use this option. I can’t jump in w testing r/n but let me know when things are ready, what props (or all props?) it’ll work for.