Adapted Python Code to make it work too

This commit is contained in:
Alexander Richter 2023-09-16 21:06:28 +02:00
parent 6e44c697cc
commit 142366491d
2 changed files with 23 additions and 25 deletions

View File

@ -261,7 +261,7 @@ Adafruit_NeoPixel strip(DLEDcount, DLEDPin, NEO_GRB + NEO_KHZ800);//Color sequen
Matrix Keypads are supported. The input is NOT added as HAL Pin to LinuxCNC. Instead it is inserted to Linux as Keyboard direktly. Matrix Keypads are supported. The input is NOT added as HAL Pin to LinuxCNC. Instead it is inserted to Linux as Keyboard direktly.
So you could attach a QWERT* Keyboard to the arduino and you will be able to write in Linux with it (only while LinuxCNC is running!) So you could attach a QWERT* Keyboard to the arduino and you will be able to write in Linux with it (only while LinuxCNC is running!)
*/ */
//#define KEYPAD #define KEYPAD
#ifdef KEYPAD #ifdef KEYPAD
const int numRows = 3; // Define the number of rows in the matrix const int numRows = 3; // Define the number of rows in the matrix
const int numCols = 3; // Define the number of columns in the matrix const int numCols = 3; // Define the number of columns in the matrix
@ -298,7 +298,7 @@ int currentLED = 0;
#define DEBUG //#define DEBUG
//####################################### END OF CONFIG ########################### //####################################### END OF CONFIG ###########################
//###Misc Settings### //###Misc Settings###
@ -490,13 +490,15 @@ void loop() {
#ifdef QUADENC #ifdef QUADENC
readEncoders(); //read Encoders & send data readEncoders(); //read Encoders & send data
#endif #endif
#ifdef JOYSTICK #ifdef JOYSTICK
readJoySticks(); //read Encoders & send data readJoySticks(); //read Encoders & send data
#endif #endif
#ifdef MULTIPLEXLEDS
multiplexLeds(); multiplexLeds();
#endif
} }
#ifdef JOYSTICK #ifdef JOYSTICK
void readJoySticks() { void readJoySticks() {
@ -913,6 +915,7 @@ void readKeypad(){
} }
#endif #endif
#ifdef MULTIPLEXLEDS
void multiplexLeds() { void multiplexLeds() {
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
//init Multiplex //init Multiplex
@ -947,7 +950,7 @@ void multiplexLeds() {
currentLED= 0; currentLED= 0;
} }
} }
#endif
void commandReceived(char cmd, uint16_t io, uint16_t value){ void commandReceived(char cmd, uint16_t io, uint16_t value){
#ifdef OUTPUTS #ifdef OUTPUTS

View File

@ -132,12 +132,12 @@ DLEDcount = 0
# You can specify special Charakters however, which will be handled as Inputs in LinuxCNC. Define those in the LCNC Array below. # You can specify special Charakters however, which will be handled as Inputs in LinuxCNC. Define those in the LCNC Array below.
Keypad = 0 # Set to 1 to Activate Keypad = 1 # Set to 1 to Activate
LinuxKeyboardInput = 1 #Activate direct Keyboard integration to Linux. LinuxKeyboardInput = 1 #Activate direct Keyboard integration to Linux.
Columns = 4 Columns = 3
Rows = 4 Rows = 3
Chars = [ #here you must define as many characters as your Keypad has keys. calculate columns * rows . for example 4 *4 = 16. You can write it down like in the example for ease of readability. Chars = [ #here you must define as many characters as your Keypad has keys. calculate columns * rows . for example 4 *4 = 16. You can write it down like in the example for ease of readability.
"1", "2", "3", "A", "1", "2", "3", "A",
"4", "5", "6", "B", "4", "5", "6", "B",
@ -169,8 +169,8 @@ Destination = [ #define, which Key should be inserted in LinuxCNC as Input or
MultiplexLED = 1 # Set to 1 to Activate MultiplexLED = 1 # Set to 1 to Activate
LedVccPins = 8 LedVccPins = 3
LedGndPins = 7 LedGndPins = 3
@ -339,22 +339,17 @@ def managageOutputs():
if (Debug):print ("Sending:{}".format(command.encode())) if (Debug):print ("Sending:{}".format(command.encode()))
oldDLEDStates[dled] = State oldDLEDStates[dled] = State
time.sleep(0.01) time.sleep(0.01)
if MultiplexLED > 0:
for mled in range(LedVccPins*LedGndPins): for mled in range(LedVccPins*LedGndPins):
State = int(c["mled.{}".format(mled)]) State = int(c["mled.{}".format(mled)])
if oldMledStates[mled] != State: #check if states have changed if oldMledStates[mled] != State: #check if states have changed
Sig = 'M' Sig = 'M'
Pin = mled Pin = mled
command = "{}{}:{}\n".format(Sig,Pin,State) command = "{}{}:{}\n".format(Sig,Pin,State)
arduino.write(command.encode()) arduino.write(command.encode())
if (Debug):print ("Sending:{}".format(command.encode())) if (Debug):print ("Sending:{}".format(command.encode()))
oldMledStates[mled] = State oldMledStates[mled] = State
time.sleep(0.01) time.sleep(0.01)
# setup MultiplexLED halpins
if MultiplexLED > 0:
for port in range(LedVccPins*LedGndPins):
c.newpin("mled.{}".format(port), hal.HAL_BIT, hal.HAL_OUT)
while True: while True: