making the code ready to merge with main

This commit is contained in:
Alexander Richter 2023-09-23 17:05:27 +02:00
parent 5a60f79ad4
commit 2fa2cf4265
3 changed files with 45 additions and 21 deletions

View File

@ -16,6 +16,7 @@
- digital Inputs - digital Inputs
- digital Outputs - digital Outputs
- Matrix Keypad - Matrix Keypad
- Multiplexed LEDs
- Quadrature encoders - Quadrature encoders
- Joysticks - Joysticks
@ -32,9 +33,10 @@
binary encoded Selector = 'K' -write only -Pin State: 0-32 binary encoded Selector = 'K' -write only -Pin State: 0-32
rotary encoder = 'R' -write only -Pin State: up/ down / -2147483648 to 2147483647 rotary encoder = 'R' -write only -Pin State: up/ down / -2147483648 to 2147483647
joystick = 'R' -write only -Pin State: up/ down / -2147483648 to 2147483647 joystick = 'R' -write only -Pin State: up/ down / -2147483648 to 2147483647
multiplexed LEDs = 'M' -read only -Pin State: 0,1
Keyboard Input: Keyboard Input:
Matrix Keypad = 'M' -write only -Pin State: Number of Matrix Key. Matrix Keypad = 'M' -write only -Pin State: 0,1
Communication Status = 'E' -read/Write -Pin State: 0:0 Communication Status = 'E' -read/Write -Pin State: 0:0
@ -64,20 +66,20 @@ Communication Status = 'E' -read/Write -Pin State: 0:0
//###################################################IO's################################################### //###################################################IO's###################################################
//#define INPUTS //Use Arduino IO's as Inputs. Define how many Inputs you want in total and then which Pins you want to be Inputs. #define INPUTS //Use Arduino IO's as Inputs. Define how many Inputs you want in total and then which Pins you want to be Inputs.
#ifdef INPUTS #ifdef INPUTS
const int Inputs = 2; //number of inputs using internal Pullup resistor. (short to ground to trigger) const int Inputs = 2; //number of inputs using internal Pullup resistor. (short to ground to trigger)
int InPinmap[] = {8,9}; int InPinmap[] = {8,9};
#endif #endif
//Use Arduino IO's as Toggle Inputs, which means Inputs (Buttons for example) keep HIGH State after Release and Send LOW only after beeing Pressed again. //Use Arduino IO's as Toggle Inputs, which means Inputs (Buttons for example) keep HIGH State after Release and Send LOW only after beeing Pressed again.
//#define SINPUTS //Define how many Toggle Inputs you want in total and then which Pins you want to be Toggle Inputs. #define SINPUTS //Define how many Toggle Inputs you want in total and then which Pins you want to be Toggle Inputs.
#ifdef SINPUTS #ifdef SINPUTS
const int sInputs = 1; //number of inputs using internal Pullup resistor. (short to ground to trigger) const int sInputs = 1; //number of inputs using internal Pullup resistor. (short to ground to trigger)
int sInPinmap[] = {10}; int sInPinmap[] = {10};
#endif #endif
//#define OUTPUTS //Use Arduino IO's as Outputs. Define how many Outputs you want in total and then which Pins you want to be Outputs. #define OUTPUTS //Use Arduino IO's as Outputs. Define how many Outputs you want in total and then which Pins you want to be Outputs.
#ifdef OUTPUTS #ifdef OUTPUTS
const int Outputs = 2; //number of outputs const int Outputs = 2; //number of outputs
int OutPinmap[] = {11,12}; int OutPinmap[] = {11,12};
@ -166,7 +168,7 @@ Encoder Encoder1(31,33); //A,B Pin
const int QuadEncSig[] = {2,2}; //define wich kind of Signal you want to generate. const int QuadEncSig[] = {2,2}; //define wich kind of Signal you want to generate.
//1= send up or down signal (typical use for selecting modes in hal) //1= send up or down signal (typical use for selecting modes in hal)
//2= send position signal (typical use for MPG wheel) //2= send position signal (typical use for MPG wheel)
const int QuadEncMp[] = {1,4}; //some Rotary encoders send multiple Electronical Impulses per mechanical pulse. How many Electrical impulses are send for each mechanical Latch? const int QuadEncMp[] = {4,4}; //some Rotary encoders send multiple Electronical Impulses per mechanical pulse. How many Electrical impulses are send for each mechanical Latch?
#endif #endif
@ -261,23 +263,28 @@ 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 = 8; // Define the number of rows in the matrix const int numRows = 4; // Define the number of rows in the matrix
const int numCols = 8; // Define the number of columns in the matrix const int numCols = 4; // Define the number of columns in the matrix
// Define the pins connected to the rows and columns of the matrix // Define the pins connected to the rows and columns of the matrix
const int rowPins[numRows] = {2,3,4,5,6,7,8,9}; //Iputs const int rowPins[numRows] = {2, 3, 4, 5};
const int colPins[numCols] = {40,41,42,43,44,45,46,47}; //"Output 8-14" const int colPins[numCols] = {6, 7, 8, 9};
int keys[numRows][numCols] = {0}; int keys[numRows][numCols] = {0};
int lastKey= -1; int lastKey= -1;
#endif #endif
#define MULTIPLEXLEDS // Special mode for Multiplexed LEDs. //#define MULTIPLEXLEDS // Special mode for Multiplexed LEDs. This mode is experimental and implemented to support Matrix Keyboards with integrated Key LEDs.
// check out this thread on LinuxCNC Forum for context. https://forum.linuxcnc.org/show-your-stuff/49606-matrix-keyboard-controlling-linuxcnc // check out this thread on LinuxCNC Forum for context. https://forum.linuxcnc.org/show-your-stuff/49606-matrix-keyboard-controlling-linuxcnc
// for Each LED an Output Pin is generated in LinuxCNC. // for Each LED an Output Pin is generated in LinuxCNC.
//If your Keyboard shares pins with the LEDs, you have to check polarity.
//rowPins[numRows] = {} are Pullup Inputs
//colPins[numCols] = {} are GND Pins
//the matrix keyboard described in the thread shares GND Pins between LEDs and KEys, therefore LedGndPins[] and colPins[numCols] = {} use same Pins.
#ifdef MULTIPLEXLEDS #ifdef MULTIPLEXLEDS
const int numVccPins = 8; // Number of rows in the matrix const int numVccPins = 8; // Number of rows in the matrix
@ -494,8 +501,7 @@ void loop() {
readJoySticks(); //read Encoders & send data readJoySticks(); //read Encoders & send data
#endif #endif
#ifdef MULTIPLEXLEDS #ifdef MULTIPLEXLEDS
//for(int i=0;i<20;i++){ multiplexLeds();// cycle through the 2D LED Matrix}
multiplexLeds();//}
#endif #endif
} }

View File

@ -32,6 +32,9 @@ It also supports Digital LEDs such as WS2812 or PL9823. This way you can have as
| binary encoded Selector Switch | 1 | 1 | 1 | | binary encoded Selector Switch | 1 | 1 | 1 |
| Quadrature Encoder Input | 3 or more | 1 or more | 1 or more | | Quadrature Encoder Input | 3 or more | 1 or more | 1 or more |
| Joystick Support (2Axis) | 8 | 6 | 3 | | Joystick Support (2Axis) | 8 | 6 | 3 |
| Matrix Keyboard | 1 | 1 | 1 |
| Multiplexed LEDs | ~ 1000 | ~ 1000 | ~ 1000 |
# Compatiblity # Compatiblity
@ -168,6 +171,19 @@ If it doesn't, something is not working and this program will not work either. P
In the Settings a cheap 4x4 Keyboard is used such as https://theartoftinkering.com/recommends/matrix-keyboard/ (referral link) In the Settings a cheap 4x4 Keyboard is used such as https://theartoftinkering.com/recommends/matrix-keyboard/ (referral link)
# Multiplexed LEDs
Special mode for Multiplexed LEDs. This mode is experimental and implemented to support Matrix Keyboards with integrated Key LEDs. Please provide feedback if u use this feature.
check out this thread on LinuxCNC Forum for context. https://forum.linuxcnc.org/show-your-stuff/49606-matrix-keyboard-controlling-linuxcnc
for Each LED an Output Pin is generated in LinuxCNC.
If your Keyboard shares pins with the LEDs, you have to check polarity. The Matrix Keyboard uses Pins as such:
rowPins[numRows] = {} are Pullup Inputs
colPins[numCols] = {} are GND Pins
the matrix keyboard described in the thread shares GND Pins between LEDs and KEYs, therefore LedGndPins[] and colPins[numCols] = {} use same Pins, LedVccPins[] are Outputs and drive the LEDs.
# Quadrature Encoders # Quadrature Encoders
Quadrature Encoders require a Library to be installed. Quadrature Encoders require a Library to be installed.
More Info about the used Library can be found here: https://www.pjrc.com/teensy/td_libs_Encoder.html More Info about the used Library can be found here: https://www.pjrc.com/teensy/td_libs_Encoder.html

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 = 1 # Set to 1 to Activate Keypad = 0 # Set to 1 to Activate
LinuxKeyboardInput = 1 #Activate direct Keyboard integration to Linux. LinuxKeyboardInput = 0 # set to 1 to Activate direct Keyboard integration to Linux.
Columns = 3 Columns = 4
Rows = 3 Rows = 4
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",
@ -167,14 +167,16 @@ Destination = [ #define, which Key should be inserted in LinuxCNC as Input or
# 12, 13, 14, 15 # 12, 13, 14, 15
# #
# this is an experimental feature, meant to support MatrixKeyboards with integrated LEDs in each Key but should work with any other LED Matrix too.
MultiplexLED = 1 # Set to 1 to Activate # It creates Output Halpins that can be connected to signals in LinuxCNC
LedVccPins = 3 MultiplexLED = 0 # Set to 1 to Activate
LedVccPins = 3
LedGndPins = 3 LedGndPins = 3
Debug = 0 #only works when this script is run from halrun in Terminal. "halrun","loadusr arduino" now Debug info will be displayed. Debug = 0 #only works when this script is run from halrun in Terminal. "halrun","loadusr arduino" now Debug info will be displayed.
######## End of Config! ######## ######## End of Config! ########