Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Blade ID Scan Millis Timeout #697

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
63 changes: 48 additions & 15 deletions props/prop_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_MILLIS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be #ifdef BLADE_ID_SCAN_TIMEOUT ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

blade_id_scan_start_ = millis();
#endif
bool on = IsOn();
BladeSet ret = SaberBase::OnBlades();
Expand Down Expand Up @@ -581,22 +584,41 @@ 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
#define BLADE_ID_SCAN_TIMEOUT 60 * 10 * 1000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub highlighted 4 different lines. Which one are you saying should be removed? Also I am not sure why any of the 4 lines highlighted would be removed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line:
#define BLADE_ID_SCAN_TIMEOUT 60 * 10 * 1000

It will produce a warning message that BLADE_ID_SCAN_TIMEOUT is already defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been completed. Now with the re-write / refactoring of the feature the user should be able to define a timeout if they want blade id to timeout but it won't effect users who don't specify a timeout.


if ((now - blade_id_scan_start_) < BLADE_ID_SCAN_TIMEOUT) {
profezzorn marked this conversation as resolved.
Show resolved Hide resolved
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() {
Expand Down Expand Up @@ -1120,6 +1142,13 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac

current_mode->mode_Loop();

#ifdef BLADE_ID_SCAN_MILLIS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (#ifdef BLADE_ID_SCAN_TIMEOUT)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (SaberBase::IsOn() ||
(current_style() && current_style()->Charging())) {
blade_id_scan_start_ = millis();
profezzorn marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

#ifdef IDLE_OFF_TIME
if (SaberBase::IsOn() ||
(current_style() && current_style()->Charging())) {
Expand All @@ -1140,6 +1169,10 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac
#ifdef IDLE_OFF_TIME
uint32_t last_on_time_;
#endif

#ifdef BLADE_ID_SCAN_MILLIS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here (#ifdef BLADE_ID_SCAN_TIMEOUT)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

uint32_t blade_id_scan_start_;
#endif

#ifdef SOUND_LIBRARY_REQUIRED
RefPtr<BufferedWavPlayer> wav_player_;
Expand Down