From 36a8de838b0b8eb0363aa1a2c78c5627ab24cc84 Mon Sep 17 00:00:00 2001 From: Raphael Jacob Date: Wed, 3 Jan 2018 22:46:21 +0100 Subject: [PATCH] Revert "Remove ftduino_direct.py and add as python package" This reverts commit d6e73bd766726f2f59e79781c7402345002301ae. --- .../TXT/rootfs/opt/ftc/ftduino_direct.py | 109 ++++++++++++++++++ configs/fischertechnik_TXT_defconfig | 1 - package/Config.in | 1 - package/python-ftduino-direct/Config.in | 6 - .../python-ftduino-direct.mk | 21 ---- 5 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 board/fischertechnik/TXT/rootfs/opt/ftc/ftduino_direct.py delete mode 100644 package/python-ftduino-direct/Config.in delete mode 100644 package/python-ftduino-direct/python-ftduino-direct.mk diff --git a/board/fischertechnik/TXT/rootfs/opt/ftc/ftduino_direct.py b/board/fischertechnik/TXT/rootfs/opt/ftc/ftduino_direct.py new file mode 100644 index 0000000000..7107b32774 --- /dev/null +++ b/board/fischertechnik/TXT/rootfs/opt/ftc/ftduino_direct.py @@ -0,0 +1,109 @@ +# v1.0.4 (c) 2017 Peter Habermehl +# +# Kommandos fuer ftduino.comm : +# +# void led_set <0|1> +# +# string ftduino_direct_get_version +# char[16] ftduino_id_set +# char[16] ftduino_id_get +# +# +# void input_set_mode +# uint16_t input_get +# +# void output_set mode: 0=open 1=switch to plus (normal operation) 2=switch to gnd +# void motor_set +# +# void ultrasonic_enable +# int16_t ultrasonic_get() +# +# void counter_set_mode +# uint16_t counter_get +# void counter_clear +# uint8_t counter_get_state +# +# Beispiel: +# myftd=ftduino_direct.ftduino() +# myftd.comm("motor M1 right 512") +# + + +import serial +import serial.tools.list_ports +import time + +FTDUINO_VIDPID="1c40:0538" + +__all__ = ["ftduino_scan", "ftduino_find_by_name", "ftduino"] + +def ftduino_scan(): + # scannt nach ftduinos und gibt eine Liste zurueck, die den device-pfad und die vom ftduino zurueckgemeldete ID beinhaltet + # [x][0] enthaelt den device-pfad, [x][1] die ID + # + devices = [] + try: + for dev in serial.tools.list_ports.grep("vid:pid="+FTDUINO_VIDPID): + o = serial.Serial(dev[0], 115200, timeout=.1) + time.sleep(0.25) + o.flushInput() + o.flushOutput() + o.write("ftduino_id_get\n".encode("utf-8")) + n=o.readline().decode("utf-8")[:-2] + o.close() + devices.append([dev[0], n]) + except: + pass + + return devices + +def ftduino_find_by_name(duino): + # sucht nach einem ftduino mit angegebenem Namen und gibt im Erfolgsfall den device-pfad zurueck + # der device-Pfad kann beim Erzeugen eines ftduino-Objekts angegeben werden, um gezielt einen + # bestimmten ftduino anzusprechen. + d=ftduino_scan() + try: + return next(c for c in ftduino_scan() if c[1] == duino)[0] + except: + return None + +class ftduino(object): + + def __init__(self, device=None): + self.ftduino=None + + # bei Angabe eines device-Pfades wird versucht, diesen ftduino zu oeffnen + # ansonsten wird der erste gefundene ftduino angesprochen + + try: + if device==None: + liste=ftduino_scan() + port=liste[0][0] + if liste!=None: + self.ftduino = serial.Serial(port, 115200, timeout=.1) + time.sleep(0.5) #give the connection a second to settle + else: + self.ftduino = serial.Serial(device, 115200, timeout=.1) + except: + pass + + def getDevice(self): + return self.ftduino + + def comm(self, command): + try: + command=command+"\n" + self.ftduino.flushInput() + self.ftduino.flushOutput() + self.ftduino.write(command.encode("utf-8")) + data = self.ftduino.readline() + if data: + return data.decode("utf-8")[:-2] + else: + return False + except: + return False + + def close(self): + self.ftduino.close() + diff --git a/configs/fischertechnik_TXT_defconfig b/configs/fischertechnik_TXT_defconfig index 02ba51d9dd..3421caa6b3 100644 --- a/configs/fischertechnik_TXT_defconfig +++ b/configs/fischertechnik_TXT_defconfig @@ -216,7 +216,6 @@ BR2_PACKAGE_PYTHON_WEDO=y BR2_PACKAGE_PYTHON_ZBARLIGHT=y BR2_PACKAGE_PYTHON_LIBROBOINT=y BR2_PACKAGE_PYTHON_FTTXPY=y -BR2_PACKAGE_PYTHON_FTDUINO_DIRECT=y # # Crypto diff --git a/package/Config.in b/package/Config.in index 5501fec7e5..46889e76ff 100644 --- a/package/Config.in +++ b/package/Config.in @@ -701,7 +701,6 @@ menu "External python modules" source "package/python-flask-jsonrpc/Config.in" source "package/python-flask-login/Config.in" source "package/python-flup/Config.in" - source "package/python-ftduino-direct/Config.in" source "package/python-ftrobopy/Config.in" source "package/python-fttxpy/Config.in" source "package/python-futures/Config.in" diff --git a/package/python-ftduino-direct/Config.in b/package/python-ftduino-direct/Config.in deleted file mode 100644 index b59871538e..0000000000 --- a/package/python-ftduino-direct/Config.in +++ /dev/null @@ -1,6 +0,0 @@ -config BR2_PACKAGE_PYTHON_FTDUINO_DIRECT - bool "python-ftduino-direct" - help - Python interface for the Till Harbaum's ftduino - - https://github.com/PeterDHabermehl/ftduino_direct diff --git a/package/python-ftduino-direct/python-ftduino-direct.mk b/package/python-ftduino-direct/python-ftduino-direct.mk deleted file mode 100644 index 2d8892d35e..0000000000 --- a/package/python-ftduino-direct/python-ftduino-direct.mk +++ /dev/null @@ -1,21 +0,0 @@ -################################################################################ -# -# python-ftrobopy -# -################################################################################ - -PYTHON_FTDUINO_DIRECT_VERSION = fcc31f1c559c4a80174ee7c49805e3052c35f946 -PYTHON_FTDUINO_DIRECT_SITE = $(call github,PeterDHabermehl,ftduino_direct,$(PYTHON_FTDUINO_DIRECT_VERSION)) -PYTHON_FTDUINO_DIRECT_LICENSE = GPL-2.0 -PYTHON_FTDUINO_DIRECT_LICENSE_FILES = LICENSE -PYTHON_FTDUINO_DIRECT_INSTALL_STAGING = NO -PYTHON_FTDUINO_DIRECT_SETUP_TYPE = distutils -PYTHON_FTDUINO_DIRECT_SUBDIR = python - -ifeq ($(BR2_PACKAGE_PYTHON),y) -PYTHON_FTDUINO_DIRECT_DEPENDENCIES += python -else ifeq ($(BR2_PACKAGE_PYTHON3),y) -PYTHON_FTDUINO_DIRECT_DEPENDENCIES += python3 -endif - -$(eval $(python-package))