small change
This commit is contained in:
parent
0577013c17
commit
dbcbe1ccf7
180
arduino.py
180
arduino.py
@ -218,7 +218,7 @@ if Keypad > 0:
|
||||
#setup JoyStick Pins
|
||||
if JoySticks > 0:
|
||||
for port in range(JoySticks):
|
||||
c.newpin("Jsk.{}".format(JoyStickPins[port]), hal.HAL_FLOAT, hal.HAL_OUT)
|
||||
c.newpin("Jsk.{}".format(JoyStickPins[port]), hal.HAL_FLOAT, hal.HAL_OUT)
|
||||
c.ready()
|
||||
|
||||
#setup Serial connection
|
||||
@ -287,116 +287,116 @@ def managageOutputs():
|
||||
|
||||
|
||||
while True:
|
||||
time.wait(0.01)
|
||||
if(arduino.in_waiting()>0):
|
||||
try:
|
||||
data = arduino.readline().decode('utf-8') #read Data received from Arduino and decode it
|
||||
if (Debug):print ("I received:{}".format(data))
|
||||
data = data.split(":",1)
|
||||
|
||||
try:
|
||||
data = arduino.readline().decode('utf-8') #read Data received from Arduino and decode it
|
||||
if (Debug):print ("I received:{}".format(data))
|
||||
data = data.split(":",1)
|
||||
|
||||
try:
|
||||
cmd = data[0][0]
|
||||
if cmd == "":
|
||||
if (Debug):print ("No Command!:{}.".format(cmd))
|
||||
cmd = data[0][0]
|
||||
if cmd == "":
|
||||
if (Debug):print ("No Command!:{}.".format(cmd))
|
||||
|
||||
else:
|
||||
if not data[0][1]:
|
||||
io = 0
|
||||
else:
|
||||
if not data[0][1]:
|
||||
io = 0
|
||||
else:
|
||||
io = extract_nbr(data[0])
|
||||
value = extract_nbr(data[1])
|
||||
if value<0: value = 0
|
||||
io = extract_nbr(data[0])
|
||||
value = extract_nbr(data[1])
|
||||
if value<0: value = 0
|
||||
|
||||
|
||||
if cmd == "I":
|
||||
firstcom = 1
|
||||
if value == 1:
|
||||
c["dIn.{}".format(io)] = 1
|
||||
c["dIn.{}-invert".format(io)] = 0
|
||||
if(Debug):print("dIn{}:{}".format(io,1))
|
||||
if cmd == "I":
|
||||
firstcom = 1
|
||||
if value == 1:
|
||||
c["dIn.{}".format(io)] = 1
|
||||
c["dIn.{}-invert".format(io)] = 0
|
||||
if(Debug):print("dIn{}:{}".format(io,1))
|
||||
|
||||
if value == 0:
|
||||
c["dIn.{}".format(io)] = 0
|
||||
c["dIn.{}-invert".format(io)] = 1
|
||||
if(Debug):print("dIn{}:{}".format(io,0))
|
||||
else:pass
|
||||
if value == 0:
|
||||
c["dIn.{}".format(io)] = 0
|
||||
c["dIn.{}-invert".format(io)] = 1
|
||||
if(Debug):print("dIn{}:{}".format(io,0))
|
||||
else:pass
|
||||
|
||||
elif cmd == "A":
|
||||
firstcom = 1
|
||||
c["aIn.{}".format(io)] = value
|
||||
if (Debug):print("aIn.{}:{}".format(io,value))
|
||||
elif cmd == "A":
|
||||
firstcom = 1
|
||||
c["aIn.{}".format(io)] = value
|
||||
if (Debug):print("aIn.{}:{}".format(io,value))
|
||||
|
||||
elif cmd == "L":
|
||||
firstcom = 1
|
||||
for Poti in range(LPoti):
|
||||
if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 0:
|
||||
for Pin in range(LPotiLatches[Poti][1]):
|
||||
if Pin == value:
|
||||
c["LPoti.{}.{}" .format(io,Pin)] = 1
|
||||
if(Debug):print("LPoti.{}.{} =1".format(io,Pin))
|
||||
else:
|
||||
c["LPoti.{}.{}" .format(io,Pin)] = 0
|
||||
if(Debug):print("LPoti.{}.{} =0".format(io,Pin))
|
||||
|
||||
if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 1:
|
||||
c["LPoti.{}.{}" .format(io,"out")] = LPotiValues[Poti][value]
|
||||
if(Debug):print("LPoti.{}.{} = 0".format("out",LPotiValues[Poti][value]))
|
||||
|
||||
elif cmd == "K":
|
||||
firstcom = 1
|
||||
if SetBinSelKnobValue == 0:
|
||||
for port in range(BinSelKnobPos):
|
||||
if port == value:
|
||||
c["BinSelKnob.{}".format(port)] = 1
|
||||
if(Debug):print("BinSelKnob.{}:{}".format(port,1))
|
||||
elif cmd == "L":
|
||||
firstcom = 1
|
||||
for Poti in range(LPoti):
|
||||
if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 0:
|
||||
for Pin in range(LPotiLatches[Poti][1]):
|
||||
if Pin == value:
|
||||
c["LPoti.{}.{}" .format(io,Pin)] = 1
|
||||
if(Debug):print("LPoti.{}.{} =1".format(io,Pin))
|
||||
else:
|
||||
c["BinSelKnob.{}".format(port)] = 0
|
||||
if(Debug):print("BinSelKnob.{}:{}".format(port,0))
|
||||
else:
|
||||
c["BinSelKnob.{}.{}" .format(0,"out")] = BinSelKnobvalues[value]
|
||||
c["LPoti.{}.{}" .format(io,Pin)] = 0
|
||||
if(Debug):print("LPoti.{}.{} =0".format(io,Pin))
|
||||
|
||||
if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 1:
|
||||
c["LPoti.{}.{}" .format(io,"out")] = LPotiValues[Poti][value]
|
||||
if(Debug):print("LPoti.{}.{} = 0".format("out",LPotiValues[Poti][value]))
|
||||
|
||||
elif cmd == "M":
|
||||
firstcom = 1
|
||||
if value == 1:
|
||||
if Destination[io] == 0 and LinuxKeyboardInput == 1:
|
||||
subprocess.call(["xdotool", "key", Chars[io]])
|
||||
if(Debug):print("Emulating Keypress{}".format(Chars[io]))
|
||||
elif cmd == "K":
|
||||
firstcom = 1
|
||||
if SetBinSelKnobValue == 0:
|
||||
for port in range(BinSelKnobPos):
|
||||
if port == value:
|
||||
c["BinSelKnob.{}".format(port)] = 1
|
||||
if(Debug):print("BinSelKnob.{}:{}".format(port,1))
|
||||
else:
|
||||
c["Keypad.{}".format(Chars[io])] = 1
|
||||
if(Debug):print("Keypad{}:{}".format(Chars[io],1))
|
||||
c["BinSelKnob.{}".format(port)] = 0
|
||||
if(Debug):print("BinSelKnob.{}:{}".format(port,0))
|
||||
else:
|
||||
c["BinSelKnob.{}.{}" .format(0,"out")] = BinSelKnobvalues[value]
|
||||
|
||||
if value == 0 & Destination[io] == 0:
|
||||
c["Keypad.{}".format(Chars[io])] = 0
|
||||
if(Debug):print("Keypad{}:{}".format(Chars[io],0))
|
||||
|
||||
elif cmd == "R":
|
||||
firstcom = 1
|
||||
c["Jsk.{}".format(io)] = value
|
||||
if (Debug):print("aIn.{}:{}".format(io,value))
|
||||
elif cmd == "M":
|
||||
firstcom = 1
|
||||
if value == 1:
|
||||
if Destination[io] == 0 and LinuxKeyboardInput == 1:
|
||||
subprocess.call(["xdotool", "key", Chars[io]])
|
||||
if(Debug):print("Emulating Keypress{}".format(Chars[io]))
|
||||
else:
|
||||
c["Keypad.{}".format(Chars[io])] = 1
|
||||
if(Debug):print("Keypad{}:{}".format(Chars[io],1))
|
||||
|
||||
if value == 0 & Destination[io] == 0:
|
||||
c["Keypad.{}".format(Chars[io])] = 0
|
||||
if(Debug):print("Keypad{}:{}".format(Chars[io],0))
|
||||
|
||||
elif cmd == "R":
|
||||
firstcom = 1
|
||||
c["Jsk.{}".format(io)] = value
|
||||
if (Debug):print("aIn.{}:{}".format(io,value))
|
||||
|
||||
|
||||
|
||||
elif cmd == 'E':
|
||||
arduino.write(b"E0:0\n")
|
||||
if (Debug):print("Sending E0:0 to establish contact")
|
||||
else: pass
|
||||
elif cmd == 'E':
|
||||
arduino.write(b"E0:0\n")
|
||||
if (Debug):print("Sending E0:0 to establish contact")
|
||||
else: pass
|
||||
|
||||
|
||||
except: pass
|
||||
except: pass
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
if (Debug):print ("Keyboard Interrupted.. BYE")
|
||||
exit()
|
||||
except:
|
||||
if (Debug):print ("I received garbage")
|
||||
arduino.flush()
|
||||
except KeyboardInterrupt:
|
||||
if (Debug):print ("Keyboard Interrupted.. BYE")
|
||||
exit()
|
||||
except:
|
||||
if (Debug):print ("I received garbage")
|
||||
arduino.flush()
|
||||
|
||||
if firstcom == 1: managageOutputs() #if ==1: E0:0 has been exchanged, which means Arduino knows that LinuxCNC is running and starts sending and receiving Data
|
||||
if firstcom == 1: managageOutputs() #if ==1: E0:0 has been exchanged, which means Arduino knows that LinuxCNC is running and starts sending and receiving Data
|
||||
|
||||
if keepAlive(event): #keep com alive. This is send to help Arduino detect connection loss.
|
||||
arduino.write(b"E:\n")
|
||||
if (Debug):print("keepAlive")
|
||||
event = time.time()
|
||||
if keepAlive(event): #keep com alive. This is send to help Arduino detect connection loss.
|
||||
arduino.write(b"E:\n")
|
||||
if (Debug):print("keepAlive")
|
||||
event = time.time()
|
||||
|
||||
time.wait(0.01)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user