Getting nosey, I put a bunch of printouts thusly:
size_t FindBestConfig(bool announce = false) {
static_assert(NELEM(blades) > 0, "blades array cannot be empty");
size_t best_config = 0;
if (NELEM(blades) > 1) {
float resistor = id(announce);
float best_err = 100000000.0;
for (size_t i = 0; i < NELEM(blades); i++) {
float err = fabsf(resistor - blades[i].ohm);
PVLOG_NORMAL << "***** Blade " << i << ": ohm = " << blades[i].ohm << ", resistor = " << resistor << ", err = " << err << "\n";
if (err < best_err) {
best_config = i;
best_err = err;
}
}
PVLOG_NORMAL << "**** Selected best_config: " << best_config << " with error: " << best_err << "\n";
} else {
PVLOG_NORMAL << "**** Only one blade configuration available, defaulting to best_config: " << best_config << "\n";
}
return best_config;
}
#ifdef BLADE_ID_SCAN_MILLIS
#ifndef SHARED_POWER_PINS
#warning SHARED_POWER_PINS is recommended when using BLADE_ID_SCAN_MILLIS
#endif
bool find_blade_again_pending_ = false;
uint32_t last_scan_id_ = 0;
bool ScanBladeIdNow() {
uint32_t now = millis();
if (now - last_scan_id_ > BLADE_ID_SCAN_MILLIS) {
last_scan_id_ = now;
// size_t best_config = FindBestConfig();
size_t best_config = FindBestConfig(true);
PVLOG_NORMAL << "******* best_config: " << best_config << "\n";
PVLOG_NORMAL << "******* current_config: " << (current_config - blades) << "\n";
if (current_config != blades + best_config) {
// We can't call FindBladeAgain right away because
// we're called from the blade. Wait until next loop() call.
find_blade_again_pending_ = true;
PVLOG_NORMAL << "******* find_blade_again_pending_ set to true\n";
} else {
PVLOG_NORMAL << "******* No change in blade configuration detected.\n";
}
return true;
}
return false;
}
// Must be called from loop()
void PollScanId() {
if (find_blade_again_pending_) {
find_blade_again_pending_ = false;
int noblade_level_before = current_config->ohm / NO_BLADE;
PVLOG_NORMAL << "******* noblade_level_before : " << noblade_level_before << "\n";
FindBladeAgain();
int noblade_level_after = current_config->ohm / NO_BLADE;
PVLOG_NORMAL << "******* noblade_level_after : " << noblade_level_after << "\n";
if (noblade_level_before < noblade_level_after) {
SaberBase::DoBladeDetect(false);
} else if(noblade_level_before > noblade_level_after) {
SaberBase::DoBladeDetect(true);
} else {
SaberBase::DoNewFont();
}
}
}
#else
void PollScanId() {}
#endif // BLADE_ID_SCAN_MILLIS
this is the result with a blade OUT and OFF: (expected)
BLADE ID: 1000720832.00
***** Blade 0: ohm = 1000000000, resistor = 1000720832.00, err = 720832.00
***** Blade 1: ohm = 650000, resistor = 1000720832.00, err = 1000070848.00
**** Selected best_config: 0 with error: 720832.00
******* best_config: 0
******* current_config: 0
******* No change in blade configuration detected.
BLADE ID: 1000720320.00
***** Blade 0: ohm = 1000000000, resistor = 1000720320.00, err = 720320.00
***** Blade 1: ohm = 650000, resistor = 1000720320.00, err = 1000070336.00
**** Selected best_config: 0 with error: 720320.00
******* best_config: 0
******* current_config: 0
******* No change in blade configuration detected.
BLADE ID: 1000721792.00
***** Blade 0: ohm = 1000000000, resistor = 1000721792.00, err = 721792.00
***** Blade 1: ohm = 650000, resistor = 1000721792.00, err = 1000071808.00
**** Selected best_config: 0 with error: 721792.00
******* best_config: 0
******* current_config: 0
******* No change in blade configuration detected.
Putting the blade IN while OFF, it detects it, plays bladein.wav: (expected)
BLADE ID: 660084.56
***** Blade 0: ohm = 1000000000, resistor = 660084.56, err = 999339904.00
***** Blade 1: ohm = 650000, resistor = 660084.56, err = 10084.56
**** Selected best_config: 1 with error: 10084.56
******* best_config: 1
******* current_config: 0
******* find_blade_again_pending_ set to true
******* noblade_level_before : 1
******* noblade_level_after : 0
BLADE ID: 665646.94
***** Blade 0: ohm = 1000000000, resistor = 665646.94, err = 999334336.00
***** Blade 1: ohm = 650000, resistor = 665646.94, err = 15646.94
**** Selected best_config: 1 with error: 15646.94
blade = 1
BLADE ID: 656285.81
***** Blade 0: ohm = 1000000000, resistor = 656285.81, err = 999343744.00
***** Blade 1: ohm = 650000, resistor = 656285.81, err = 6285.81
**** Selected best_config: 1 with error: 6285.81
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
BLADE ID: 657303.81
***** Blade 0: ohm = 1000000000, resistor = 657303.81, err = 999342720.00
***** Blade 1: ohm = 650000, resistor = 657303.81, err = 7303.81
**** Selected best_config: 1 with error: 7303.81
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
Then turning ON with blade still IN: (expected)
BLADE ID: 616727.50
***** Blade 0: ohm = 1000000000, resistor = 616727.50, err = 999383296.00
***** Blade 1: ohm = 650000, resistor = 616727.50, err = 33272.50
**** Selected best_config: 1 with error: 33272.50
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
BLADE ID: 607278.38
***** Blade 0: ohm = 1000000000, resistor = 607278.38, err = 999392704.00
***** Blade 1: ohm = 650000, resistor = 607278.38, err = 42721.62
**** Selected best_config: 1 with error: 42721.62
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
BLADE ID: 604796.56
***** Blade 0: ohm = 1000000000, resistor = 604796.56, err = 999395200.00
***** Blade 1: ohm = 650000, resistor = 604796.56, err = 45203.44
**** Selected best_config: 1 with error: 45203.44
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
then leaving ON and removing blade: (unexpected)
BLADE ID: 675522.06
***** Blade 0: ohm = 1000000000, resistor = 675522.06, err = 999324480.00
***** Blade 1: ohm = 650000, resistor = 675522.06, err = 25522.06
**** Selected best_config: 1 with error: 25522.06
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
EVENT: ?47 ON millis=190121
BLADE ID: 656884.38
***** Blade 0: ohm = 1000000000, resistor = 656884.38, err = 999343104.00
***** Blade 1: ohm = 650000, resistor = 656884.38, err = 6884.38
**** Selected best_config: 1 with error: 6884.38
******* best_config: 1
******* current_config: 1
******* No change in blade configuration detected.
so it didn’t detect the change.
If I touch the pogo pins with my finger enough to make a disturbance, it detects noblade is present, then loops like this, apparently reading a ghost of a blade value at least once enough to consider it “blade insterted”, then changing its mind that it’s NO_BLADE: (unexpected)
BLADE ID: 659573.69
***** Blade 0: ohm = 1000000000, resistor = 659573.69, err = 999340416.00
***** Blade 1: ohm = 650000, resistor = 659573.69, err = 9573.69
**** Selected best_config: 1 with error: 9573.69
******* best_config: 1
******* current_config: 0
******* find_blade_again_pending_ set to true
******* noblade_level_before : 1
BLADE ID: 1000712704.00
***** Blade 0: ohm = 1000000000, resistor = 1000712704.00, err = 712704.00
***** Blade 1: ohm = 650000, resistor = 1000712704.00, err = 1000062720.00
**** Selected best_config: 0 with error: 712704.00
blade = 0
WS2811 Blade with 5 leds.
WS2811 Blade with 4 leds.
WS2811 Blade with 1 leds.
unit = 1 vol = 0.50, Playing a_EZRA/Nomad/in/in02.wav
channels: 1 rate: 44100 bits: 16
Style RAM = 1812
Style RAM = 712
Style RAM = 688
Scanning sound font: a_EZRA/Nomad
done
Scanning sound font: ProffieOS_Voicepack_Ezra/common
done
Scanning sound font: commonBU
done
Activating polyphonic font.
Activating SmoothSwing V2
Accent Swings Enabled.
Polyphonic swings: 16
Monophonic swings: 0
Accent Slashes NOT Detected:
Ignition.
unit = 0 vol = 0.00, Playing a_EZRA/Nomad/hum.wav
channels: 1 rate: 44100 bits: 16
**** FastOn() called, have fastout.wav, playing fastout.wav
unit = 1 vol = 0.50, Playing commonBU/fastout/fastout1.wav
channels: 1 rate: 44100 bits: 16
HumDelay: 200
unit = 2 vol = 0.00, Playing a_EZRA/Nomad/swingl/swingl01.wav
channels: 1 rate: 44100 bits: 16
unit = 3 vol = 0.00, Playing a_EZRA/Nomad/swingh/swingh01.wav
channels: 1 rate: 44100 bits: 16
******* noblade_level_after : 1
unit = 4 vol = 0.50, Playing a_EZRA/Nomad/font.wav
channels: 1 rate: 44100 bits: 16
and continues doing that every BLADE_SCAN_MILLIS interval.
Not sure what that tells us, but it’s what’s going on.