Skip to content

Commit 60529a7

Browse files
committed
Slimmed loader, updated examples, fixed wifi, updated README.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent b6e4e63 commit 60529a7

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ This package adds functionalities for
88

99
## Installation
1010

11+
### Using Lab for MicroPython / MicroPython Package Installer
12+
13+
If you are using [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython) to work on your MicroPython projects, you can use the button "Install Package". This will launch [MicroPython Package Installer](https://labs.arduino.cc/en/labs/micropython-package-installer) or take you to the web page to download and install it.
14+
Once installed, running it once will make sure the application file
15+
16+
![Install package](assets/package_installer_button.png)
17+
18+
This tool simplifies installing packages from both the official MicroPython index and Arduino's curated package index on any MicroPython board.
19+
1120
### Using `mpremote`
1221

1322
We must specify the target especially if the framework is already installed and a default app is present, since `mpremote mip` will use the current path to look for or create the `lib` folder.

arduino_tools/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ def __init__(self, app_name):
1212
if not validate_app(app_name):
1313
raise ValueError('Invalid app')
1414
self.properties = get_app_properties(app_name)
15+
self.friendly_name = self.properties['friendly_name']
1516
if os.getcwd() != self.get_path():
1617
enter_app(app_name)
18+
1719

1820
def get_property(self, property):
1921
return self.properties.get(property)

arduino_tools/loader.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@ def enter_default_app():
2323
return None
2424

2525
if fs_item_exists(APPS_ROOT + BOOT_CONFIG_FILE):
26+
boot_entries = []
2627
with open(APPS_ROOT + BOOT_CONFIG_FILE, 'r') as a_cfg:
27-
default_p = a_cfg.readline().strip()
28-
reboot_to = a_cfg.readline().strip()
28+
boot_entries = a_cfg.readlines()
29+
30+
if len(boot_entries) > 1:
31+
default_p = boot_entries.pop(0)
32+
elif len(boot_entries) == 1:
33+
default_p = boot_entries[0]
34+
else:
35+
default_p = ''
36+
default_p = default_p.strip()
2937
if default_p == '':
3038
return None
31-
if reboot_to != '':
39+
if len(boot_entries) > 0:
3240
with open(APPS_ROOT + BOOT_CONFIG_FILE, 'w') as a_cfg:
33-
a_cfg.write(reboot_to)
41+
for entry in boot_entries:
42+
a_cfg.write(entry)
3443
return enter_app(default_p)
3544
return None
3645

arduino_tools/wifi_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ def find_scanned_matches():
124124
# print('encoded name: ', (n['name']).encode())
125125
# print('mac: ', (n['mac']).encode())
126126

127-
filtered = [item for item in _local_networks_cache['networks'] if item[0] == (n['name']).encode() or binascii.hexlify(item[1]) == n['mac'].encode()]
127+
# filtered = [item for item in _local_networks_cache['networks'] if item[0] == (n['name']).encode() or binascii.hexlify(item[1]) == n['mac'].encode()]
128+
filtered = [item for item in _local_networks_cache['networks'] if binascii.hexlify(item[1]) == n['mac'].encode()]
128129
if len(filtered) > 0:
129130
scanned_known_networks.append(n)
130-
131-
132131
return scanned_known_networks
133132

134133
def auto_connect(progress_callback = None):
40.4 KB
Loading

examples/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ In this case the condition to restore `app_launcher` as the default application
1010
This is an example `JSON` file to be reachable at an App's `origin_url` address.
1111
The method `update_app(path = None)`, if `path` is not provided, will query that `URL` and verify that new versions of the App are available.
1212

13-
### Example usage (requires network connection)
13+
### Example usage (requires an active network connection)
1414

1515
```python
1616
from arduino_tools.app import App
1717
my_app = App('valid_app_name')
1818
my_app.update()
1919
```
20+
21+
## app_demo
22+
23+
This is a sample App that displays the structure of an application.
24+
It includes a local `lib` folder, which highlights the fact that libraries local to the application don't need to be installed system-wide, also allowing other versions of packages to be installed on an App basis.
25+
The loader add the local App's `lib` folder at the beginning of `system.path`.

examples/app_demo/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
from sample_lib import sample_lib_function
55
# The following two lines will take care of initializing the app
6+
# as well making sure that once run the current working directory
7+
# is set to the app's folder.
8+
# This comes in handy when testing an App but the board is set to run
9+
# a different default app.
610
from arduino_tools.app import *
711
my_app = App('demo')
812

913
# Write your code below (no #) and have fun :)
1014
print(f'Hello, I am an app and my name is {my_app.friendly_name}')
15+
1116
# Call a function from the sample_lib module
1217
# To demonstrate that the app's lib/ folder is in sys.path
1318
sample_lib_function()

0 commit comments

Comments
 (0)