From ee8eb38182d21be2f4d7dacc1eeef13b4a07938a Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 7 Mar 2017 16:57:07 +0000 Subject: [PATCH 1/4] dc_motor: Add wrapper Signed-off-by: Francois Berder --- letmecreate/click/__init__.py | 9 ++++--- letmecreate/click/dc_motor.py | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 letmecreate/click/dc_motor.py diff --git a/letmecreate/click/__init__.py b/letmecreate/click/__init__.py index 560cfb4..a04815d 100644 --- a/letmecreate/click/__init__.py +++ b/letmecreate/click/__init__.py @@ -11,6 +11,7 @@ - CO - Color - Color2 + - DC motor - Eve - Fan - GYRO @@ -32,7 +33,7 @@ """ __all__ = ['seven_seg', 'led_matrix', 'accel', 'adc', 'air_quality', 'alcohol', - 'bargraph', 'co', 'color', 'color2', 'eve', 'fan', 'gyro', - 'ir_distance', 'ir_eclipse', 'joystick', 'light', 'lin_hall', 'lora', - 'motion', 'oled', 'proximity', 'relay', 'relay2', 'relay4', 'rtc', - 'thermo3', 'uni_hall'] + 'bargraph', 'co', 'color', 'color2', 'dc_motor', 'eve', 'fan', + 'gyro', 'ir_distance', 'ir_eclipse', 'joystick', 'light', + 'lin_hall', 'lora', 'motion', 'oled', 'proximity', 'relay', + 'relay2', 'relay4', 'rtc', 'thermo3', 'uni_hall'] diff --git a/letmecreate/click/dc_motor.py b/letmecreate/click/dc_motor.py new file mode 100644 index 0000000..be80f8b --- /dev/null +++ b/letmecreate/click/dc_motor.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Python binding of DC motor Click wrapper of LetMeCreate library.""" + +import ctypes + +_LIB = ctypes.CDLL('libletmecreate_click.so') + + +def init(mikrobus_index): + ret = _LIB.dc_motor_click_init(mikrobus_index) + if ret < 0: + raise Exception("dc motor click init failed") + + +def set_direction(mikrobus_index, direction): + ret = _LIB.dc_motor_click_set_direction(mikrobus_index, direction) + if ret < 0: + raise Exception("dc motor click set direction failed") + + +def get_direction(mikrobus_index): + direction = ctypes.c_uint8() + ret = _LIB.dc_motor_click_set_direction(mikrobus_index, ctypes.byref(direction)) + if ret < 0: + raise Exception("dc motor click get direction failed") + return direction.value + + +def set_speed(mikrobus_index, speed): + ret = _LIB.dc_motor_click_set_speed(mikrobus_index, speed) + if ret < 0: + raise Exception("dc motor click set speed failed") + + +def get_speed(mikrobus_index): + speed = ctypes.c_float() + ret = _LIB.dc_motor_click_get_speed(mikrobus_index, ctypes.byref(speed)) + if ret < 0: + raise Exception("dc motor click get speed failed") + return speed.value + + +def release(mikrobus_index): + ret = _LIB.dc_motor_click_release(mikrobus_index) + if ret < 0: + raise Exception("dc motor click release failed") From e79b1e7ec8b3792c202df2552b332724f07109df Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 7 Mar 2017 17:01:51 +0000 Subject: [PATCH 2/4] dc_motor: Add documentation of wrapper Signed-off-by: Francois Berder --- letmecreate/click/dc_motor.py | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/letmecreate/click/dc_motor.py b/letmecreate/click/dc_motor.py index be80f8b..10f9456 100644 --- a/letmecreate/click/dc_motor.py +++ b/letmecreate/click/dc_motor.py @@ -7,32 +7,65 @@ def init(mikrobus_index): + """Initialise the DC motor click. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to initialise the board. + """ ret = _LIB.dc_motor_click_init(mikrobus_index) if ret < 0: raise Exception("dc motor click init failed") def set_direction(mikrobus_index, direction): + """Change the direction of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + direction: must be 0 (reverse) or 1 (forward + + Note: An exception is thrown if it fails to change the direction. + """ ret = _LIB.dc_motor_click_set_direction(mikrobus_index, direction) if ret < 0: raise Exception("dc motor click set direction failed") def get_direction(mikrobus_index): + """Returns the direction of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to get the direction. + """ direction = ctypes.c_uint8() - ret = _LIB.dc_motor_click_set_direction(mikrobus_index, ctypes.byref(direction)) + ret = _LIB.dc_motor_click_set_direction(mikrobus_index, + ctypes.byref(direction)) if ret < 0: raise Exception("dc motor click get direction failed") return direction.value def set_speed(mikrobus_index, speed): + """Change the speed of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + speed: floating point value in range 0..100 + + Note: An exception is thrown if it fails to change the speed. + """ ret = _LIB.dc_motor_click_set_speed(mikrobus_index, speed) if ret < 0: raise Exception("dc motor click set speed failed") def get_speed(mikrobus_index): + """Returns the speed of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to get the speed. + """ speed = ctypes.c_float() ret = _LIB.dc_motor_click_get_speed(mikrobus_index, ctypes.byref(speed)) if ret < 0: @@ -41,6 +74,12 @@ def get_speed(mikrobus_index): def release(mikrobus_index): + """Release the DC motor click. + + Stops the motor. + + Note: An exception is thrown if it fails to release + """ ret = _LIB.dc_motor_click_release(mikrobus_index) if ret < 0: raise Exception("dc motor click release failed") From ab5fdd9afb5530b6f45c5784bc238af2507f7848 Mon Sep 17 00:00:00 2001 From: HugoSilvaSantos Date: Wed, 24 Jan 2018 21:39:41 +0000 Subject: [PATCH 3/4] Added README.md to announce this repository is no longer maintained. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index bdcf627..4b5f5db 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,10 @@ thermo3.disable() # Release I2C i2c.release() ``` + +## This repository is no longer maintained. + +Issue reports and pull requests will not be attended. + +--- + From 31b1a9f8195a1fbbde613a5d2980ac6625c0edaa Mon Sep 17 00:00:00 2001 From: HugoSilvaSantos Date: Wed, 24 Jan 2018 21:42:18 +0000 Subject: [PATCH 4/4] Fixed README.md image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b5f5db..78cc6f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](https://static.creatordev.io/logo-md-s.svg) +![logo](https://avatars2.githubusercontent.com/u/18185398?s=200&v=4) # PyLetMeCreate