-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Feature] System flag to indicate first execution of program #1496
Comments
This could be useful indeed. When we are adding this, we could also add a way to test being connected to the computer or not. This has been requested a few times as well. |
Even simpler, and essentially equivalent, is to set a flag indicating whether the program was started from the IDE, or with the button on the hub.
If there are a few more useful indicators, maybe we can have a single Or just expose the existing status bit flags. (Although "started with button" is not an available status right now.) |
The So the candidates we have are: print(hub.system.info())
{
'name': 'test',
'reset_reason': 0,
'ble_host_connected': True,
'program_started_with_button': True,
'program_id': 2,
# program_size (?)
# mac_address (?)
# free_space (?)
# uptime (?)
# program_run_count (?) (since boot, not persistent)
} |
Looks good to me.
Yes, that sounds like almost the same thing, I guess when one starts the program from the IDE, it is being edited and updated anyway. |
Can be used to indicate various hub states instead of adding a new method for each. See pybricks/support#1496
This gives the user a way to optionally run certain code only when it is first downloaded to the robot. Examples include one-off motor initialization or one-off wiping of user data. Fixes pybricks/support#1496
This gives the user a way to optionally run certain code only when it is first downloaded to the robot. Examples include one-off motor initialization or one-off wiping of user data. Fixes pybricks/support#1496
Output for program started with button:
When started with Pybricks Code:
The numeric codes ( |
Thanks for implementing this! One note, would it be possible to have the possible values as enums/constants? Would make the program more readable. Are there any other values than 2 and 3? |
The numeric codes will be documented in the API docs. Since this is a fairly advanced use case, I think it's OK to ask users to find a number in the documentation. Just like |
I see, in that case I guess my best option is to define constants in the beginning of my program to make it more readable? Aren't there system defined constants? |
Right. You could use |
As discussed in another topic (#1476), a program is not really able to tell if the contents of the persistent storage are valid for the given program or not, because new programs are possible to install without clearing the storage, which makes it hard to use it safely (the only workable solution we came to was using program-specific magic ids written into the beginning of the storage, which is cumbersome to maintain across programs).
I'd propose a system flag to indicate whether the current program being run is the first run of the program. I imagine this flag could always be set when a program is downloaded to the hub, and cleared automatically upon program termination. (I'm not sure if any hub can store more than one programs, then this would have to be a separate flag per program.)
This could be a better alternative to clearing the persistent storage itself, which may not always be desirable, and would require a new UI component. This solution would not effect existing programs as the flag could simply be omitted. However, programs that wish to observe the flag may choose to clear or initialize the storage with valid contents themselves (or even do any other one-time actions, such as showing usage tips on a hub with display).
I imagine it could be accessed like
hub.system.is_first_execution
(if only one program is ever possible on a hub).Is this technically possible (setting and clearing such a flag automatically as proposed)?
The text was updated successfully, but these errors were encountered: