diff --git a/props/prop_base.h b/props/prop_base.h index 4be7fac3e..83aa6b24a 100644 --- a/props/prop_base.h +++ b/props/prop_base.h @@ -356,6 +356,9 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac BladeSet BladeOff() { #ifdef IDLE_OFF_TIME last_on_time_ = millis(); +#endif +#ifdef BLADE_ID_SCAN_TIMEOUT + blade_id_scan_start_ = millis(); #endif bool on = IsOn(); BladeSet ret = SaberBase::OnBlades(); @@ -581,22 +584,39 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac #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(PROFFIEOS_LOG_LEVEL >= 500); - 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; - } - return true; + + bool find_blade_again_pending_ = false; + uint32_t last_scan_id_ = 0; + bool ScanBladeIdNow() { + uint32_t now = millis(); + + bool scan = (now - last_scan_id_) > BLADE_ID_SCAN_MILLIS; + +#ifdef BLADE_ID_STOP_SCAN_WHILE_IGNITED + if (IsOn()) { + scan = false; + } +#endif + +#ifdef BLADE_ID_SCAN_TIMEOUT + if ((now - blade_id_scan_start_) < BLADE_ID_SCAN_TIMEOUT) { + scan = false; + } +#endif + + if (scan) { + last_scan_id_ = now; + size_t best_config = FindBestConfig(PROFFIEOS_LOG_LEVEL >= 500); + 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; + } + return true; + } else { + return false; + } } - return false; - } // Must be called from loop() void PollScanId() { @@ -1120,6 +1140,13 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac current_mode->mode_Loop(); +#ifdef BLADE_ID_SCAN_TIMEOUT + if (SaberBase::IsOn() || + (current_style() && current_style()->Charging())) { + blade_id_scan_start_ = millis(); + } +#endif + #ifdef IDLE_OFF_TIME if (SaberBase::IsOn() || (current_style() && current_style()->Charging())) { @@ -1140,6 +1167,10 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac #ifdef IDLE_OFF_TIME uint32_t last_on_time_; #endif + +#ifdef BLADE_ID_SCAN_TIMEOUT + uint32_t blade_id_scan_start_; +#endif #ifdef SOUND_LIBRARY_REQUIRED RefPtr wav_player_;