Merge branch 'dev' of https://github.com/AlexmagToast/LinuxCNC_ArduinoConnector into dev
This commit is contained in:
commit
a67bc21691
31
arduino.py
Normal file → Executable file
31
arduino.py
Normal file → Executable file
@ -96,10 +96,13 @@ BinSelKnobvalues = [[180,190,200,0,0,0,0,0,0,0,0,0,0,0,0,10,20,30,40,50,60,70,80
|
||||
|
||||
#Quadrature Encoders
|
||||
|
||||
#Joystick
|
||||
JoySticks = 1
|
||||
JoyStickPins = [[54,56],
|
||||
[3,1]]
|
||||
#Enable Joystick support.
|
||||
# Intended for use as MPG. useing the Joystick will update a counter, which can be used as Jog Input.
|
||||
# Moving the Joystick will either increase or decrease the counter. Modify Jog-scale in hal to increase or decrease speed.
|
||||
JoySticks = 1 #number of installed Joysticks
|
||||
JoyStickPins = [54,55] #Pins the Joysticks are connected to.
|
||||
#in this example X&Y Pins of the Joystick are connected to Pin A0& A1. Remember, to use the Atmega Pin names here!
|
||||
# for more than one Joystick just add the other pins to the array for example: JoyStickPins = [54,55,56,57]
|
||||
|
||||
|
||||
|
||||
@ -217,8 +220,8 @@ if Keypad > 0:
|
||||
c.newpin("Keypad.{}".format(Chars[port]), hal.HAL_BIT, hal.HAL_IN)
|
||||
#setup JoyStick Pins
|
||||
if JoySticks > 0:
|
||||
for port in range(JoySticks):
|
||||
c.newpin("Jsk.{}".format(JoyStickPins[port]), hal.HAL_FLOAT, hal.HAL_OUT)
|
||||
for port in range(JoySticks*2):
|
||||
c.newpin("Joystick.{}".format(JoyStickPins[port]), hal.HAL_S32, hal.HAL_OUT)
|
||||
c.ready()
|
||||
|
||||
#setup Serial connection
|
||||
@ -249,8 +252,8 @@ def extract_nbr(input_str):
|
||||
return 0
|
||||
|
||||
out_number = ''
|
||||
for ele in input_str:
|
||||
if ele.isdigit():
|
||||
for i, ele in enumerate(input_str):
|
||||
if ele.isdigit() or (ele == '-' and i+1 < len(input_str) and input_str[i+1].isdigit()):
|
||||
out_number += ele
|
||||
return int(out_number)
|
||||
|
||||
@ -295,7 +298,7 @@ while True:
|
||||
try:
|
||||
cmd = data[0][0]
|
||||
if cmd == "":
|
||||
if (Debug):print ("No Command!:{}.".format(cmd))
|
||||
if (Debug):print ("No Command!:{}".format(cmd))
|
||||
|
||||
else:
|
||||
if not data[0][1]:
|
||||
@ -303,8 +306,8 @@ while True:
|
||||
else:
|
||||
io = extract_nbr(data[0])
|
||||
value = extract_nbr(data[1])
|
||||
if value<0: value = 0
|
||||
|
||||
#if value<0: value = 0
|
||||
if (Debug):print ("No Command!:{}.".format(cmd))
|
||||
|
||||
if cmd == "I":
|
||||
firstcom = 1
|
||||
@ -370,8 +373,8 @@ while True:
|
||||
|
||||
elif cmd == "R":
|
||||
firstcom = 1
|
||||
c["Jsk.{}".format(io)] = value
|
||||
if (Debug):print("aIn.{}:{}".format(io,value))
|
||||
c["Joystick.{}".format(io)] = value
|
||||
if (Debug):print("Joystick.{}:{}".format(io,value))
|
||||
|
||||
|
||||
|
||||
@ -398,5 +401,5 @@ while True:
|
||||
if (Debug):print("keepAlive")
|
||||
event = time.time()
|
||||
|
||||
time.wait(0.01)
|
||||
time.sleep(0.01)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user