Skip to content

Commit ecbe6d6

Browse files
co: add wrapper
Signed-off-by: Francois Berder <[email protected]> Signed-off-by: Francois Berder <[email protected]>
1 parent b83a09f commit ecbe6d6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

letmecreate/click/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- ADC
88
- Alcohol
99
- Bargraph
10+
- CO
1011
- Color
1112
- Color2
1213
- Eve
@@ -23,4 +24,5 @@
2324

2425
__all__ = ['seven_seg', 'led_matrix', 'accel', 'adc', 'alcohol', 'bargraph',
2526
'color', 'color2', 'eve', 'ir_distance', 'ir_eclipse', 'joystick',
26-
'motion', 'proximity', 'relay', 'relay2', 'relay4', 'thermo3']
27+
'motion', 'proximity', 'relay', 'relay2', 'relay4', 'thermo3',
28+
'CO']

letmecreate/click/co.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
"""Python binding of CO Click wrapper of LetMeCreate library."""
3+
4+
import ctypes
5+
6+
_LIB = ctypes.CDLL('libletmecreate_click.so')
7+
8+
9+
def get_measure(mikrobus_index):
10+
"""Measure the CO concentration in the air using the CO click.
11+
12+
mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2)
13+
14+
Note: An exception is thrown if it fails to communicate with the CO click.
15+
"""
16+
value = ctypes.c_uint16_t(0)
17+
ret = _LIB.co_click_get_measure(mikrobus_index, ctypes.byref(value))
18+
if ret < 0:
19+
raise Exception("co click read ppm failed")
20+
return value.value

0 commit comments

Comments
 (0)