small change

This commit is contained in:
Alexander Richter 2023-07-23 10:50:52 +02:00
parent 0577013c17
commit dbcbe1ccf7

View File

@ -218,7 +218,7 @@ if Keypad > 0:
#setup JoyStick Pins #setup JoyStick Pins
if JoySticks > 0: if JoySticks > 0:
for port in range(JoySticks): 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() c.ready()
#setup Serial connection #setup Serial connection
@ -287,116 +287,116 @@ def managageOutputs():
while True: while True:
time.wait(0.01) try:
if(arduino.in_waiting()>0): 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: try:
data = arduino.readline().decode('utf-8') #read Data received from Arduino and decode it cmd = data[0][0]
if (Debug):print ("I received:{}".format(data)) if cmd == "":
data = data.split(":",1) if (Debug):print ("No Command!:{}.".format(cmd))
try: else:
cmd = data[0][0] if not data[0][1]:
if cmd == "": io = 0
if (Debug):print ("No Command!:{}.".format(cmd))
else: else:
if not data[0][1]: io = extract_nbr(data[0])
io = 0 value = extract_nbr(data[1])
else: if value<0: value = 0
io = extract_nbr(data[0])
value = extract_nbr(data[1])
if value<0: value = 0
if cmd == "I": if cmd == "I":
firstcom = 1 firstcom = 1
if value == 1: if value == 1:
c["dIn.{}".format(io)] = 1 c["dIn.{}".format(io)] = 1
c["dIn.{}-invert".format(io)] = 0 c["dIn.{}-invert".format(io)] = 0
if(Debug):print("dIn{}:{}".format(io,1)) if(Debug):print("dIn{}:{}".format(io,1))
if value == 0: if value == 0:
c["dIn.{}".format(io)] = 0 c["dIn.{}".format(io)] = 0
c["dIn.{}-invert".format(io)] = 1 c["dIn.{}-invert".format(io)] = 1
if(Debug):print("dIn{}:{}".format(io,0)) if(Debug):print("dIn{}:{}".format(io,0))
else:pass else:pass
elif cmd == "A": elif cmd == "A":
firstcom = 1 firstcom = 1
c["aIn.{}".format(io)] = value c["aIn.{}".format(io)] = value
if (Debug):print("aIn.{}:{}".format(io,value)) if (Debug):print("aIn.{}:{}".format(io,value))
elif cmd == "L": elif cmd == "L":
firstcom = 1 firstcom = 1
for Poti in range(LPoti): for Poti in range(LPoti):
if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 0: if LPotiLatches[Poti][0] == io and SetLPotiValue[Poti] == 0:
for Pin in range(LPotiLatches[Poti][1]): for Pin in range(LPotiLatches[Poti][1]):
if Pin == value: if Pin == value:
c["LPoti.{}.{}" .format(io,Pin)] = 1 c["LPoti.{}.{}" .format(io,Pin)] = 1
if(Debug):print("LPoti.{}.{} =1".format(io,Pin)) 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))
else: else:
c["BinSelKnob.{}".format(port)] = 0 c["LPoti.{}.{}" .format(io,Pin)] = 0
if(Debug):print("BinSelKnob.{}:{}".format(port,0)) if(Debug):print("LPoti.{}.{} =0".format(io,Pin))
else:
c["BinSelKnob.{}.{}" .format(0,"out")] = BinSelKnobvalues[value] 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":
elif cmd == "M": firstcom = 1
firstcom = 1 if SetBinSelKnobValue == 0:
if value == 1: for port in range(BinSelKnobPos):
if Destination[io] == 0 and LinuxKeyboardInput == 1: if port == value:
subprocess.call(["xdotool", "key", Chars[io]]) c["BinSelKnob.{}".format(port)] = 1
if(Debug):print("Emulating Keypress{}".format(Chars[io])) if(Debug):print("BinSelKnob.{}:{}".format(port,1))
else: else:
c["Keypad.{}".format(Chars[io])] = 1 c["BinSelKnob.{}".format(port)] = 0
if(Debug):print("Keypad{}:{}".format(Chars[io],1)) 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": elif cmd == "M":
firstcom = 1 firstcom = 1
c["Jsk.{}".format(io)] = value if value == 1:
if (Debug):print("aIn.{}:{}".format(io,value)) 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': elif cmd == 'E':
arduino.write(b"E0:0\n") arduino.write(b"E0:0\n")
if (Debug):print("Sending E0:0 to establish contact") if (Debug):print("Sending E0:0 to establish contact")
else: pass else: pass
except: pass except: pass
except KeyboardInterrupt: except KeyboardInterrupt:
if (Debug):print ("Keyboard Interrupted.. BYE") if (Debug):print ("Keyboard Interrupted.. BYE")
exit() exit()
except: except:
if (Debug):print ("I received garbage") if (Debug):print ("I received garbage")
arduino.flush() 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. if keepAlive(event): #keep com alive. This is send to help Arduino detect connection loss.
arduino.write(b"E:\n") arduino.write(b"E:\n")
if (Debug):print("keepAlive") if (Debug):print("keepAlive")
event = time.time() event = time.time()
time.wait(0.01)