updating to change workplace
This commit is contained in:
parent
163e76906f
commit
edb005e778
76
arduino.py
76
arduino.py
@ -94,7 +94,12 @@ SetBinSelKnobValue = [1]
|
|||||||
BinSelKnobvalues = [[180,190,200,0,0,0,0,0,0,0,0,0,0,0,0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170],
|
BinSelKnobvalues = [[180,190,200,0,0,0,0,0,0,0,0,0,0,0,0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170],
|
||||||
[0.001,0.01,0.1,1]]
|
[0.001,0.01,0.1,1]]
|
||||||
|
|
||||||
#Quadrature Encoders
|
#Enable Quadrature Encoders
|
||||||
|
QuadEncs = 2
|
||||||
|
QuadEncSig = [1,1]
|
||||||
|
#1 = send up or down signal (typical use for selecting modes in hal)
|
||||||
|
#2 = send position signal (typical use for MPG wheel)
|
||||||
|
|
||||||
|
|
||||||
#Enable Joystick support.
|
#Enable Joystick support.
|
||||||
# Intended for use as MPG. useing the Joystick will update a counter, which can be used as Jog Input.
|
# Intended for use as MPG. useing the Joystick will update a counter, which can be used as Jog Input.
|
||||||
@ -169,6 +174,11 @@ if LinuxKeyboardInput:
|
|||||||
|
|
||||||
Inputs = Inputs+ SInputs
|
Inputs = Inputs+ SInputs
|
||||||
InPinmap += sInPinmap
|
InPinmap += sInPinmap
|
||||||
|
|
||||||
|
|
||||||
|
# Storing Variables for counter timing Stuff
|
||||||
|
counter_last_update = {}
|
||||||
|
counter_hold_interval = 100
|
||||||
######## SetUp of HalPins ########
|
######## SetUp of HalPins ########
|
||||||
|
|
||||||
# setup Input halpins
|
# setup Input halpins
|
||||||
@ -221,7 +231,19 @@ if Keypad > 0:
|
|||||||
#setup JoyStick Pins
|
#setup JoyStick Pins
|
||||||
if JoySticks > 0:
|
if JoySticks > 0:
|
||||||
for port in range(JoySticks*2):
|
for port in range(JoySticks*2):
|
||||||
c.newpin("Joystick.{}".format(JoyStickPins[port]), hal.HAL_S32, hal.HAL_OUT)
|
c.newpin("Counter.{}".format(JoyStickPins[port]), hal.HAL_S32, hal.HAL_OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if QuadEncs > 0:
|
||||||
|
for port in range(QuadEncs):
|
||||||
|
if QuadEncSig[port] == 1:
|
||||||
|
c.newpin("CounterUp.{}".format(port), hal.HAL_BIT, hal.HAL_OUT)
|
||||||
|
c.newpin("CounterDown.{}".format(port), hal.HAL_BIT, hal.HAL_OUT)
|
||||||
|
if QuadEncSig[port] == 2:
|
||||||
|
c.newpin("Counter.{}".format(port), hal.HAL_S32, hal.HAL_OUT)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
c.ready()
|
c.ready()
|
||||||
|
|
||||||
#setup Serial connection
|
#setup Serial connection
|
||||||
@ -373,10 +395,56 @@ while True:
|
|||||||
|
|
||||||
elif cmd == "R":
|
elif cmd == "R":
|
||||||
firstcom = 1
|
firstcom = 1
|
||||||
c["Joystick.{}".format(io)] = value
|
if JoySticks > 0:
|
||||||
if (Debug):print("Joystick.{}:{}".format(io,value))
|
for pins in range(JoySticks*2):
|
||||||
|
if (io == JoyStickPins[pins]):
|
||||||
|
c["Counter.{}".format(io)] = value
|
||||||
|
if (Debug):print("Counter.{}:{}".format(io,value))
|
||||||
|
if QuadEncs > 0:
|
||||||
|
if QuadEncSig[io]== 1:
|
||||||
|
if value == 0:
|
||||||
|
c["CounterDown.{}".format(io)] = 1
|
||||||
|
time.sleep(0.1)
|
||||||
|
c["CounterDown.{}".format(io)] = 0
|
||||||
|
if value == 1:
|
||||||
|
c["CounterUp.{}".format(io)] = 1
|
||||||
|
time.sleep(0.1)
|
||||||
|
c["CounterUp.{}".format(io)] = 0
|
||||||
|
if QuadEncSig[io]== 2:
|
||||||
|
c["Counter.{}".format(io)] = value
|
||||||
|
|
||||||
|
|
||||||
|
# Check if the button is not already in the dictionary, and set its last update time to 0
|
||||||
|
if io not in counter_last_update:
|
||||||
|
counter_last_update[io] = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if JoySticks > 0:
|
||||||
|
for pins in range(JoySticks*2):
|
||||||
|
if (io == JoyStickPins[pins]):
|
||||||
|
c["Counter.{}".format(io)] = value
|
||||||
|
if Debug:
|
||||||
|
print("Counter.{}:{}".format(io, value))
|
||||||
|
|
||||||
|
if QuadEncs > 0:
|
||||||
|
if QuadEncSig[io] == 1:
|
||||||
|
# Check if enough time has passed since the last update
|
||||||
|
if millis() - counter_last_update[io] >= counter_hold_interval:
|
||||||
|
counter_last_update[io] = millis() # Update the last update time for the button
|
||||||
|
if value == 0:
|
||||||
|
c["CounterDown.{}".format(io)] = 1
|
||||||
|
counter_last_update[io] = millis() # Update the last update time for the button
|
||||||
|
if value == 1:
|
||||||
|
c["CounterUp.{}".format(io)] = 1
|
||||||
|
counter_last_update[io] = millis() # Update the last update time for the button
|
||||||
|
elif QuadEncSig[io] == 2:
|
||||||
|
c["Counter.{}".format(io)] = value
|
||||||
|
|
||||||
|
|
||||||
|
elif cmd == "R":
|
||||||
|
firstcom = 1
|
||||||
|
handle_button_press(io, value)
|
||||||
|
|
||||||
elif cmd == 'E':
|
elif cmd == 'E':
|
||||||
arduino.write(b"E0:0\n")
|
arduino.write(b"E0:0\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user