Skip to content

Commit dedea6f

Browse files
authored
Merge pull request #6 from arduino/docs
Fix API documentation config
2 parents c6d07c8 + 414d0e8 commit dedea6f

File tree

3 files changed

+281
-3
lines changed

3 files changed

+281
-3
lines changed

docs/api.md

+265
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,268 @@
11
# Summary
22

3+
* [buttons](#modulino.buttons)
4+
* [ModulinoButtons](#modulino.buttons.ModulinoButtons)
5+
* [default\_long\_press\_duration](#modulino.buttons.ModulinoButtons.default_long_press_duration)
6+
* [update](#modulino.buttons.ModulinoButtons.update)
7+
* [modulino](#modulino.modulino)
8+
* [I2CHelper](#modulino.modulino.I2CHelper)
9+
* [frequency](#modulino.modulino.I2CHelper.frequency)
10+
* [reset\_bus](#modulino.modulino.I2CHelper.reset_bus)
11+
* [find\_interface](#modulino.modulino.I2CHelper.find_interface)
12+
* [Modulino](#modulino.modulino.Modulino)
13+
* [discover](#modulino.modulino.Modulino.discover)
14+
* [\_\_bool\_\_](#modulino.modulino.Modulino.__bool__)
15+
* [connected](#modulino.modulino.Modulino.connected)
16+
* [pin\_strap\_address](#modulino.modulino.Modulino.pin_strap_address)
17+
* [read](#modulino.modulino.Modulino.read)
18+
* [write](#modulino.modulino.Modulino.write)
19+
* [has\_default\_address](#modulino.modulino.Modulino.has_default_address)
20+
* [reset\_bus](#modulino.modulino.Modulino.reset_bus)
21+
* [pixels](#modulino.pixels)
22+
* [ModulinoColor](#modulino.pixels.ModulinoColor)
23+
* [\_\_int\_\_](#modulino.pixels.ModulinoColor.__int__)
24+
* [thermo](#modulino.thermo)
25+
* [ModulinoThermo](#modulino.thermo.ModulinoThermo)
26+
* [measurements](#modulino.thermo.ModulinoThermo.measurements)
27+
* [relative\_humidity](#modulino.thermo.ModulinoThermo.relative_humidity)
28+
* [temperature](#modulino.thermo.ModulinoThermo.temperature)
29+
30+
<a id="modulino.buttons.ModulinoButtons"></a>
31+
32+
## class `ModulinoButtons`
33+
34+
```python
35+
class ModulinoButtons(Modulino)
36+
```
37+
38+
<a id="modulino.buttons.ModulinoButtons.default_long_press_duration"></a>
39+
40+
### `default_long_press_duration`
41+
42+
1 second
43+
44+
<a id="modulino.buttons.ModulinoButtons.update"></a>
45+
46+
### `update`
47+
48+
```python
49+
def update()
50+
```
51+
52+
Update the button status and call the corresponding callbacks.
53+
Returns True if any of the buttons has changed its state.
54+
55+
<a id="modulino.modulino.I2CHelper"></a>
56+
57+
## class `I2CHelper`
58+
59+
```python
60+
class I2CHelper()
61+
```
62+
63+
A helper class for interacting with I2C devices on supported boards.
64+
65+
<a id="modulino.modulino.I2CHelper.frequency"></a>
66+
67+
### `frequency`
68+
69+
Modulinos operate at 100kHz
70+
71+
<a id="modulino.modulino.I2CHelper.reset_bus"></a>
72+
73+
### `reset_bus`
74+
75+
```python
76+
@staticmethod
77+
def reset_bus(i2c_bus)
78+
```
79+
80+
Resets the I2C bus in case it got stuck. To unblock the bus the SDA line is kept high for 20 clock cycles
81+
Which causes the triggering of a NAK message.
82+
83+
<a id="modulino.modulino.I2CHelper.find_interface"></a>
84+
85+
### `find_interface`
86+
87+
```python
88+
@staticmethod
89+
def find_interface() -> I2C
90+
```
91+
92+
Returns an instance of the I2C interface for the current board.
93+
94+
Raises:
95+
RuntimeError: If the current board is not supported.
96+
97+
Returns:
98+
I2C: An instance of the I2C interface.
99+
100+
<a id="modulino.modulino.Modulino"></a>
101+
102+
## class `Modulino`
103+
104+
```python
105+
class Modulino()
106+
```
107+
108+
<a id="modulino.modulino.Modulino.discover"></a>
109+
110+
### `discover`
111+
112+
```python
113+
def discover(default_addresses)
114+
```
115+
116+
Tries to find the given modulino device in the device chain
117+
based on the pre-defined default addresses.
118+
If the address has been changed to a custom one it won't be found with this function.
119+
120+
<a id="modulino.modulino.Modulino.__bool__"></a>
121+
122+
### `__bool__`
123+
124+
```python
125+
def __bool__()
126+
```
127+
128+
Boolean cast operator to determine if the given i2c device has a correct address
129+
and if the bus is defined.
130+
In case of auto discovery this also means that the device was found on the bus
131+
because otherwise the address would be None.
132+
133+
<a id="modulino.modulino.Modulino.connected"></a>
134+
135+
### `connected`
136+
137+
```python
138+
@property
139+
def connected()
140+
```
141+
142+
Determines if the given modulino is connected to the i2c bus.
143+
144+
<a id="modulino.modulino.Modulino.pin_strap_address"></a>
145+
146+
### `pin_strap_address`
147+
148+
```python
149+
@property
150+
def pin_strap_address()
151+
```
152+
153+
Returns the pin strap i2c address of the modulino.
154+
This address is set via resistors on the modulino board.
155+
Since all modulinos generally use the same firmware, the pinstrap address
156+
is needed to determine the type of the modulino at boot time, so it know what to do.
157+
At boot it checks the internal flash in case its address has been overridden by the user
158+
which would take precedence.
159+
160+
<a id="modulino.modulino.Modulino.read"></a>
161+
162+
### `read`
163+
164+
```python
165+
def read(amount_of_bytes)
166+
```
167+
168+
Reads the given amount of bytes from the i2c device and returns the data.
169+
It skips the first byte which is the pinstrap address.
170+
171+
<a id="modulino.modulino.Modulino.write"></a>
172+
173+
### `write`
174+
175+
```python
176+
def write(data_buffer)
177+
```
178+
179+
Writes the given buffer to the i2c device.
180+
181+
<a id="modulino.modulino.Modulino.has_default_address"></a>
182+
183+
### `has_default_address`
184+
185+
```python
186+
@property
187+
def has_default_address()
188+
```
189+
190+
Determines if the given modulino has a default address
191+
or if a custom one was set.
192+
193+
<a id="modulino.modulino.Modulino.reset_bus"></a>
194+
195+
### `reset_bus`
196+
197+
```python
198+
@staticmethod
199+
def reset_bus(i2c_bus)
200+
```
201+
202+
Resets the i2c bus. This is useful when the bus is in an unknown state.
203+
The modulinos that are equipped with a micro controller use DMA operations.
204+
If the host board does a reset during such operation it can make the bus get stuck.
205+
206+
Returns
207+
----
208+
I2C: A new i2c bus object after resetting the bus.
209+
210+
<a id="modulino.pixels.ModulinoColor"></a>
211+
212+
## class `ModulinoColor`
213+
214+
```python
215+
class ModulinoColor()
216+
```
217+
218+
<a id="modulino.pixels.ModulinoColor.__int__"></a>
219+
220+
### `__int__`
221+
222+
```python
223+
def __int__()
224+
```
225+
226+
Return the 32-bit integer representation of the color.
227+
228+
<a id="modulino.thermo.ModulinoThermo"></a>
229+
230+
## class `ModulinoThermo`
231+
232+
```python
233+
class ModulinoThermo(Modulino)
234+
```
235+
236+
<a id="modulino.thermo.ModulinoThermo.measurements"></a>
237+
238+
### `measurements`
239+
240+
```python
241+
@property
242+
def measurements() -> Measurement
243+
```
244+
245+
Return Temperature and Relative Humidity or None if the data is stalled
246+
247+
<a id="modulino.thermo.ModulinoThermo.relative_humidity"></a>
248+
249+
### `relative_humidity`
250+
251+
```python
252+
@property
253+
def relative_humidity() -> float
254+
```
255+
256+
The current relative humidity in % rH
257+
258+
<a id="modulino.thermo.ModulinoThermo.temperature"></a>
259+
260+
### `temperature`
261+
262+
```python
263+
@property
264+
def temperature() -> float
265+
```
266+
267+
The current temperature in Celsius
3268

pyproject.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
[[tool.pydoc-markdown.loaders]]
22
type = "python"
33
search_path = [ "./src" ]
4-
packages = ["arduino_nicla_sense_env"]
4+
packages = ["modulino"]
5+
6+
[[tool.pydoc-markdown.processors]]
7+
type = "filter"
8+
skip_empty_modules = true
9+
expression = "not \"modulino.lib\" in name and default()"
510

611
[tool.pydoc-markdown.renderer]
712
type = "markdown"

src/modulino/modulino.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,25 @@ def __init__(self, i2c_bus=None, address=None, name=None):
104104
else:
105105
self.i2c_bus = i2c_bus
106106

107-
self.address = address
108107
self.name = name
108+
self.address = address
109109

110-
if self.address == None and len(self.default_addresses) > 0:
110+
if self.address == None:
111+
if len(self.default_addresses) == 0:
112+
raise RuntimeError(f"No default addresses defined for the {self.name} device.")
113+
111114
if self.convert_default_addresses:
112115
# Need to convert the 8-bit address to 7-bit
113116
actual_addresses = list(map(lambda addr: addr >> 1, self.default_addresses))
114117
self.address = self.discover(actual_addresses)
115118
else:
116119
self.address = self.discover(self.default_addresses)
117120

121+
if self.address == None:
122+
raise RuntimeError(f"Couldn't find the {self.name} device on the bus. Try resetting the board.")
123+
elif not self.connected:
124+
raise RuntimeError(f"Couldn't find a {self.name} device with address {hex(self.address)} on the bus. Try resetting the board.")
125+
118126
def discover(self, default_addresses):
119127
"""
120128
Tries to find the given modulino device in the device chain

0 commit comments

Comments
 (0)