Skip to content

Commit 3d318fe

Browse files
authored
Support to mip package manager (#16)
* Changes module's files structure. The module import does not change with this commit. * Adds package.json for the package to be available via mip and mpremote. * Adds support to mip. * Bumps to v0.4.1.
1 parent e51cc4e commit 3d318fe

File tree

6 files changed

+737
-712
lines changed

6 files changed

+737
-712
lines changed

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,31 @@ A full example is provided in `/example` directory.
4646

4747
#### 1a - **network-enabled MicroPython ports**
4848

49-
> Warning: in latest MicroPython releases `upip` has been deprecated in favor of [`mip`](https://docs.micropython.org/en/latest/reference/packages.html#package-management). Please use the manual installation until I set up the driver to work with `mip`.
49+
> Warning: in latest MicroPython releases `upip` has been deprecated in favor of [`mip`](https://docs.micropython.org/en/latest/reference/packages.html#package-management). This module is compatible with both of them. Please use the package manager included into your MicroPython version.
5050
51-
To include the library into a network-enabled MicroPython project, it's sufficient to install the package using `upip`:
51+
If your MicroPython version supports `mip` package manager, put these lines **after** the setup of an Internet connection:
52+
53+
```python
54+
import mip
55+
56+
mip.install("github:n-elia/MAX30102-MicroPython-driver")
57+
```
58+
59+
If your MicroPython version supports `upip` package manager, put these lines **after** the setup of an Internet connection:
5260

5361
```python
5462
import upip
5563

5664
upip.install("micropython-max30102")
5765
```
5866

59-
Make sure that your firmware runs these lines **after** an Internet connection has been established.
60-
6167
To run the example in `./example` folder, please set your WiFi credentials in `boot.py` and then upload `./example`
6268
content into your microcontroller. If you prefer, you can perform a manual install as explained below.
6369

6470
#### 1b - **manual way** (no Internet access required)
6571

6672
To directly include the library into a MicroPython project, it's sufficient to copy `max30102/circular_buffer.py`
67-
and `max30102/max30102.py` next to your `main.py` file, into a `lib` directory.
73+
and `max30102/__init__.py` next to your `main.py` file, into a `lib` directory.
6874

6975
The folder tree should look as follows:
7076

@@ -73,7 +79,7 @@ The folder tree should look as follows:
7379
┣ 📜 boot.py
7480
┣ 📜 main.py
7581
┗ 📂 lib
76-
┣ 📜 max30102.py
82+
┣ 📜 __init__.py
7783
┗ 📜 circular_buffer.py
7884
```
7985

@@ -83,7 +89,7 @@ Then, import the constructor as follows:
8389
from max30102 import MAX30102
8490
```
8591

86-
To run the example in `./example` folder, copy `max30102/circular_buffer.py` and `max30102/max30102.py` into
92+
To run the example in `./example` folder, copy `max30102/circular_buffer.py` and `max30102/__init__.py` into
8793
the `./example/lib` directory. Then, upload the `./example` directory content into your microcontroller. After the
8894
upload, press the reset button of your board are you're good to go.
8995

@@ -273,6 +279,9 @@ resolution of 0.0625°C, but be aware that the accuracy is ±1°C.
273279

274280
## Changelog
275281

282+
- v0.4.1
283+
- Changed the module files organization.
284+
- Added support to `mip` package manager.
276285
- v0.4.0
277286
- According to some best practices discussed [here](https://forum.micropython.org/viewtopic.php?f=2&t=12508), some
278287
changes have been made.

example/boot.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ def do_connect(ssid: str, password: str):
1717
my_ssid = "my_ssid"
1818
my_pass = "my_password"
1919

20+
# Check if the module is available in memory
2021
try:
2122
from max30102 import MAX30102
22-
except:
23-
print("'max30102' not found!")
23+
except ImportError as e:
24+
# Module not available. Try to connect to Internet to download it.
25+
print(f"Import error: {e}")
26+
print("Trying to connect to the Internet to download the module.")
27+
do_connect(my_ssid, my_pass)
2428
try:
29+
# Try to leverage upip package manager to download the module.
2530
import upip
26-
do_connect(my_ssid, my_pass)
2731
upip.install("micropython-max30102")
28-
except:
29-
print("Unable to get 'micropython-max30102' package!")
32+
except ImportError:
33+
# upip not available. Try to leverage mip package manager to download the module.
34+
print("upip not available in this port. Trying with mip.")
35+
import mip
36+
mip.install("github:n-elia/MAX30102-MicroPython-driver")

0 commit comments

Comments
 (0)