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 1 commit into
base: master
Choose a base branch
from

Conversation

cshannon2
Copy link

This pull request adds a timeout to the BLADE_ID_SCAN_MILLIS option. Currently if BLADE_ID_SCAN_MILLIS is enabled it will constantly check for a blade configuration even when the lightsaber is not in use. A side effect of BLADE_ID_SCAN_MILLIS is a blinking light. The blinking light can be observed long after the lightsaber has been in use. The timeout allows the lightsaber to stop searching for a blade if it hasn't been turned on in a certain amount of time. The default time is 10 minutes. The value can be changed via a config file.

The logic:
If the blade is off and the blade has been off for longer than the timeout, then the proffie board can stop searching for a blade. BLADE_ID_SCAN_MILLIS can be resumed by turning the lightsaber on and off. Once the lightsaber is turned off the board will restart the countdown.

@profezzorn
Copy link
Owner

Interesting, but maybe we should just be using IDLE_OFF_TIME for this?

@cshannon2
Copy link
Author

cshannon2 commented Sep 29, 2024

Great Observation. I actually started this using IDLE_OFF_TIME. I was using the variable that IDLE_OFF_TIME creates which is called: last_on_time_.

The If statement logic looked like this:
if (IsOn() == false && (now - last_on_time_) < BLADE_ID_SCAN_TIMEOUT)

During testing I noticed that I was running into an issue with the BLADE_ID_SCAN_MILLIS unexpectedly restarting after a timeout had occurred. I found that it was because there is another function that modifies last_on_time_.

if (millis() - last_on_time_ > IDLE_OFF_TIME) { SaberBase::DoOff(OFF_IDLE, 0); last_on_time_ = millis(); }

The above code appeared to be resetting the timeout which resulted in restarting the BLADE_ID_SCAN_MILLIS without the lightsaber being powered on.

I wasn't sure why last_on_time_ was being reset in that function. If we can remove the last_on_time_ = millis(); from that function then I believe that I could change this to use the last_on_time_ variable.

I created BLADE_ID_SCAN_TIMEOUT instead of using IDLE_OFF_TIME to allow users to turn off the blinking light side effect without impacting other leds.

@NoSloppy
Copy link
Contributor

blinking light side effect

By this do you mean like a single "weak" LED such as on an emitter blade PCB?

@cshannon2
Copy link
Author

@NoSloppy the short answer is yes. I have seen this side effect discussed in the forums but now I am having a hard time finding the thread. So I will just talk about my experience until I can find the thread. The emitter on my lightsaber has around 9 small leds. When there isn't a blade in the lightsaber and the lightsaber is powered on these leds provide lighting effects. In my experience when BLADE_ID_SCAN_MILLIS is enabled the 9 small leds in the emitter begin to flash / blink. This flash/blink does not occur everytime a blade_id_scan occurs and the blinking/flashing can vary in its brightness. Based off of what I have read in the forums this can be expected due to how BLADE_ID_SCAN_MILLIS functions. By setting a timeout we can prevent the blinking from occuring after the lightsaber is no longer in use. I am not sure if this change has any impact on battery life but I feel like it could potentially be beneficial for battery life.

return true;
bool ScanBladeIdNow() {
uint32_t now = millis();
if (IsOn() == false && (now - blade_id_scan_start_) < BLADE_ID_SCAN_TIMEOUT) {
Copy link
Owner

Choose a reason for hiding this comment

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

Why is IsOn() == false here?
That will make blade scanning while on not work properly.

Copy link
Author

@cshannon2 cshannon2 Sep 29, 2024

Choose a reason for hiding this comment

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

The assumption was that a blade config file wouldn't change while the blade was ignited, as a result only search for a blade if the lightsaber is off and the timeout hasn't been reached. If you would like I can just remove the IsOn() check. The resulting if statement would be if ((now - blade_id_scan_start_) < BLADE_ID_SCAN_TIMEOUT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants