Skip to content

Commit 65c4ba9

Browse files
Merge branch 'dev'
2 parents a6daee1 + 2a69b6c commit 65c4ba9

File tree

15 files changed

+939
-12
lines changed

15 files changed

+939
-12
lines changed

letmecreate/click/__init__.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
"""Python binding of the click part of the LetMeCreate library.
22
33
It defines binding for the following click boards:
4-
- Thermo3
5-
- Proximity
6-
- Accel
7-
- Relay2
8-
- Motion
4+
- 7Seg
95
- 8x8R (LED matrix)
10-
- Joystick
6+
- Accel
7+
- ADC
8+
- Alcohol
9+
- Bargraph
10+
- CO
1111
- Color
12+
- Color2
13+
- Eve
14+
- IR distance
15+
- IR eclipse
16+
- Joystick
17+
- Motion
18+
- Proximity
19+
- Relay (partial support: only relay 1 working)
20+
- Relay2
21+
- Relay4
22+
- Thermo3
1223
"""
1324

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

letmecreate/click/adc.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""Python binding of ADC Click Wrapper of LetMeCreate library.
3+
4+
You must initialise the SPI bus and select the right one before calling
5+
get_raw_value.
6+
"""
7+
8+
import ctypes
9+
10+
_LIB = ctypes.CDLL('libletmecreate_click.so')
11+
12+
ADC_CLICK_CHANNEL_1 = 0
13+
ADC_CLICK_CHANNEL_2 = 1
14+
ADC_CLICK_CHANNEL_3 = 2
15+
ADC_CLICK_CHANNEL_4 = 3
16+
17+
18+
def get_raw_value(channel):
19+
"""Read raw value from ADC Click in range 0..4095
20+
21+
channel: must be in range 0-3. Channel 2 is not available on Ci40.
22+
23+
Note: An exception is thrown if it fails to communicate with the click.
24+
"""
25+
value = ctypes.c_uint16(0)
26+
ret = _LIB.adc_click_get_raw_value(channel, ctypes.byref(value))
27+
if ret < 0:
28+
raise Exception("adc click get raw value failed")
29+
return value.value

letmecreate/click/alcohol.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
"""Python binding of Alcohol Click wrapper of LetMeCreate library."""
3+
import ctypes
4+
5+
_LIB = ctypes.CDLL('libletmecreate_click.so')
6+
7+
8+
def get_measure(mikrobus_index):
9+
"""Returns a 16-bit integer from the Accel Click.
10+
11+
mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2)
12+
13+
Note: An exception is thrown if it fails to get a measure from the click.
14+
"""
15+
measure = ctypes.c_uint16(0)
16+
ret = _LIB.alcohol_click_get_measure(mikrobus_index, ctypes.byref(measure))
17+
if ret < 0:
18+
raise Exception("alcohol click get measure failed")
19+
return measure.value

letmecreate/click/bargraph.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
"""Python binding of Bargraph Click wrapper of LetMeCreate library.
3+
4+
You must configure and select the right SPI bus before using any of these
5+
functions.
6+
"""
7+
8+
import ctypes
9+
10+
_LIB = ctypes.CDLL('libletmecreate_click.so')
11+
12+
13+
def set_value(value):
14+
"""Switch on/off LED's of the Bargraph Click.
15+
16+
value: 8-bit integer used as a bit string. Least significant bit
17+
controls the left-most LED.
18+
19+
Note: An exception is thrown if it fails to switch on/off LED's.
20+
"""
21+
ret = _LIB.bargraph_click_set_value(value)
22+
if ret < 0:
23+
raise Exception("bargrah click set value failed")
24+
25+
26+
def set_intensity(mikrobus_index, intensity):
27+
"""Control the brightness of the LED's of the Bargraph Click.
28+
29+
mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2)
30+
31+
intensity: Percentage of intensity of the LED's, must be in range 0.0-10.0
32+
33+
Note: An exception is thrown if it fails to switch on/off LED's.
34+
"""
35+
ret = _LIB.bargraph_click_set_intensity(mikrobus_index,
36+
ctypes.c_float(intensity))
37+
if ret < 0:
38+
raise Exception("bargrah click set intensity failed")

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

letmecreate/click/color2.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
"""Python binding of Color2 Click wrapper of LetMeCreate library."""
3+
import ctypes
4+
5+
_LIB = ctypes.CDLL('libletmecreate_click.so')
6+
7+
8+
def enable():
9+
"""Enable the Color2 Click.
10+
11+
Note: An exception is thrown if it fails to enable the chip.
12+
"""
13+
ret = _LIB.color2_click_enable()
14+
if ret < 0:
15+
raise Exception("color2 click enable failed")
16+
17+
18+
def get_color():
19+
"""Returns the rgb color measurement as a tuple.
20+
21+
Note: An exception is thrown if it fails to get a measurement from
22+
the click.
23+
"""
24+
red = ctypes.c_uint16(0)
25+
green = ctypes.c_uint16(0)
26+
blue = ctypes.c_uint16(0)
27+
ret = _LIB.color2_click_get_color(ctypes.byref(red),
28+
ctypes.byref(green),
29+
ctypes.byref(blue))
30+
if ret < 0:
31+
raise Exception("color2 click get color failed")
32+
return (red.value, green.value, blue.value)
33+
34+
35+
def disable():
36+
"""Disable the Color2 Click.
37+
38+
Note: An exception is thrown if it fails to disable the chip.
39+
"""
40+
ret = _LIB.color2_click_disable()
41+
if ret < 0:
42+
raise Exception("color2 click disable failed")

0 commit comments

Comments
 (0)