Skip to content

Commit

Permalink
Merge pull request #115 from ski7777/ftduino-pkg
Browse files Browse the repository at this point in the history
Revert "Remove ftduino_direct.py and add as python package"
  • Loading branch information
PeterDHabermehl authored Jan 3, 2018
2 parents af4329b + 36a8de8 commit d2fd2ab
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
109 changes: 109 additions & 0 deletions board/fischertechnik/TXT/rootfs/opt/ftc/ftduino_direct.py
Original file line number Diff line number Diff line change
@@ -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 <string maxlen=16>
# char[16] ftduino_id_get
#
#
# void input_set_mode <I1..I8> <switch|resistance|voltage>
# uint16_t input_get <I1..I8>
#
# void output_set <O1..O8> <mode="0..2"> <pwm=[0..512]> mode: 0=open 1=switch to plus (normal operation) 2=switch to gnd
# void motor_set <M1..M4> <right|left|brake> <pwm=[0..512]>
#
# void ultrasonic_enable <true|false>
# int16_t ultrasonic_get()
#
# void counter_set_mode <none|rising|falling|any>
# uint16_t counter_get <C1..C4>
# void counter_clear <C1..C4>
# uint8_t counter_get_state <C1..C4>
#
# 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()

1 change: 0 additions & 1 deletion configs/fischertechnik_TXT_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,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"
Expand Down

0 comments on commit d2fd2ab

Please sign in to comment.