Skip to content

Commit 447cc28

Browse files
committed
Added cycling through apps on boot. Updated version number.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent c4c678c commit 447cc28

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ The framework exploits the standard behaviour of MicroPython at start/reset/soft
5454
The framework's boot.py only requires two lines for the following operations:
5555

5656
* import the minimum required parts of arduino_tools (common) from the board's File System (installed as a package in [flash]/lib/arduino_tools)
57-
* invoke the method `load_app()` to enter the default app's path and apply some temporary settings to configure the running environment (search paths and launch configuration changes) which will be reset at the next start.
57+
* invoke the method `load_app(app_name = None, cycle_mode = False)` to enter the default app's path and apply some temporary settings to configure the running environment (search paths and launch configuration changes) which will be reset at the next start.
5858

5959
If no default app is set, it will fall back to the `main.py` in the board's root if present.
6060
No error condition will be generated, as MicroPython is capable of handling the absence of `boot.py` and/or `main.py` at C level.
6161

62-
If a default app is set, the `load_app()` will issue an `os.chdir()` command and enter the app's folder.
62+
If a default app is set, the `load_app(app_name = None, cycle_mode = False)` will issue an `os.chdir()` command and enter the app's folder.
6363
MicroPython will automatically run the main.py it finds in its Current Working Directory.
6464

65+
`cycle_mode`: when this parameter is `True`, the loader will pop first item from the `boot.cfg` file and append it to the end.
66+
This could be useful if you have a board in demo mode (needing to display multiple applications) or need to run applications in a sequence for RAM or features constraints.
67+
You could think of a board that needs to connect to Internet to download data, but would not be able to process the data with the RAM available.
68+
6569
**NOTES:**
6670

6771
* each app can contain a `.hidden` file that will hide the app from AMP, effectively preventing listing or deletion.

arduino_tools/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
APP_FRIENDLY_NAME_FILE = '.friendly_name'
77
APP_HIDDEN_FILE = '.hidden'
88
APPS_FRAMEWORK_NAME = 'Arduino Apps'
9-
TOOLS_VERSION = '0.7.0'
9+
TOOLS_VERSION = '0.9.0'

arduino_tools/loader.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,37 @@
1212

1313
default_path = sys.path.copy()
1414

15-
def load_app(app_name = None):
16-
if app_name == None:
17-
return enter_default_app()
15+
def load_app(app_name = None, cycle_mode = False):
16+
if app_name == None or cycle_mode:
17+
return enter_default_app(cycle_mode = cycle_mode)
1818
return enter_app(app_name)
1919

20-
def enter_default_app():
20+
def enter_default_app(cycle_mode = False):
2121
if restore_available and restore_target():
2222
enter_app(restore_target())
2323
return None
2424

2525
if fs_item_exists(APPS_ROOT + BOOT_CONFIG_FILE):
2626
boot_entries = []
2727
with open(APPS_ROOT + BOOT_CONFIG_FILE, 'r') as a_cfg:
28-
boot_entries = a_cfg.readlines()
28+
boot_entries = [entry.strip() for entry in a_cfg]
2929

3030
if len(boot_entries) > 1:
3131
default_p = boot_entries.pop(0)
3232
elif len(boot_entries) == 1:
3333
default_p = boot_entries[0]
3434
else:
3535
default_p = ''
36-
default_p = default_p.strip()
36+
# default_p = default_p.strip()
3737
if default_p == '':
3838
return None
3939
if len(boot_entries) > 0:
40+
if cycle_mode:
41+
boot_entries.append(default_p)
4042
with open(APPS_ROOT + BOOT_CONFIG_FILE, 'w') as a_cfg:
41-
for entry in boot_entries:
42-
a_cfg.write(entry)
43+
for i, entry in enumerate(boot_entries):
44+
new_line = '\n' if i < len(boot_entries) - 1 else ''
45+
a_cfg.write(entry + new_line)
4346
return enter_app(default_p)
4447
return None
4548

arduino_tools/templates/main.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ from arduino_tools.app import *
66
my_app = App('{app_name}')
77

88
# Write your code below (no #) and have fun :)
9-
print("Hello, I am an app and my name is {app_friendly_name}")
9+
print("Hello, I am an App and my name is {app_friendly_name}")

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,67 @@
22
"urls": [
33
[
44
"arduino_tools/__init__.py",
5-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/__init__.py"
5+
"github:arduino/arduino-tools-mpy/arduino_tools/__init__.py"
66
],
77
[
88
"arduino_tools/app.py",
9-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/app.py"
9+
"github:arduino/arduino-tools-mpy/arduino_tools/app.py"
1010
],
1111
[
1212
"arduino_tools/apps_manager.py",
13-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/apps_manager.py"
13+
"github:arduino/arduino-tools-mpy/arduino_tools/apps_manager.py"
1414
],
1515
[
1616
"arduino_tools/common.py",
17-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/common.py"
17+
"github:arduino/arduino-tools-mpy/arduino_tools/common.py"
1818
],
1919
[
2020
"arduino_tools/constants.py",
21-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/constants.py"
21+
"github:arduino/arduino-tools-mpy/arduino_tools/constants.py"
2222
],
2323
[
2424
"arduino_tools/files.py",
25-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/files.py"
25+
"github:arduino/arduino-tools-mpy/arduino_tools/files.py"
2626
],
2727
[
2828
"arduino_tools/help.txt",
29-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/help.txt"
29+
"github:arduino/arduino-tools-mpy/arduino_tools/help.txt"
3030
],
3131
[
3232
"arduino_tools/helpers.py",
33-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/helpers.py"
33+
"github:arduino/arduino-tools-mpy/arduino_tools/helpers.py"
3434
],
3535
[
3636
"arduino_tools/loader.py",
37-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/loader.py"
37+
"github:arduino/arduino-tools-mpy/arduino_tools/loader.py"
3838
],
3939
[
4040
"arduino_tools/properties.py",
41-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/properties.py"
41+
"github:arduino/arduino-tools-mpy/arduino_tools/properties.py"
4242
],
4343
[
4444
"arduino_tools/updater.py",
45-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/updater.py"
45+
"github:arduino/arduino-tools-mpy/arduino_tools/updater.py"
4646
],
4747
[
4848
"arduino_tools/wifi_utils.py",
49-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/wifi_utils.py"
49+
"github:arduino/arduino-tools-mpy/arduino_tools/wifi_utils.py"
5050
],
5151
[
5252
"arduino_tools/utils/semver.py",
53-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/utils/semver.py"
53+
"github:arduino/arduino-tools-mpy/arduino_tools/utils/semver.py"
5454
],
5555
[
5656
"arduino_tools/templates/main.tpl",
57-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/templates/main.tpl"
57+
"github:arduino/arduino-tools-mpy/arduino_tools/templates/main.tpl"
5858
],
5959
[
6060
"arduino_tools/templates/boot_apps.tpl",
61-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/templates/boot_apps.tpl"
61+
"github:arduino/arduino-tools-mpy/arduino_tools/templates/boot_apps.tpl"
6262
],
6363
[
6464
"arduino_tools/templates/boot_plain.tpl",
65-
"github:arduino/arduino/arduino-tools-mpy/arduino_tools/templates/boot_plain.tpl"
65+
"github:arduino/arduino-tools-mpy/arduino_tools/templates/boot_plain.tpl"
6666
],
6767
],
6868
"deps": [
@@ -75,5 +75,5 @@
7575
"latest"
7676
]
7777
],
78-
"version": "0.8.0"
78+
"version": "0.9.0"
7979
}

0 commit comments

Comments
 (0)