a couple of Bugfixes

This commit is contained in:
Alexander Richter 2023-05-07 11:20:04 +02:00
parent 97d3c375cc
commit 422f12ce24
2 changed files with 42 additions and 26 deletions

View File

@ -134,6 +134,7 @@ Note that Analog Pin numbering is different to the Print on the PCB.
// if connection is lost, something happened. (Linuxcnc was closed for example or USB Connection failed.) It will recover when Linuxcnc is restartet. (you could also run "unloadusr arduino", "loadusr arduino" in Hal) // if connection is lost, something happened. (Linuxcnc was closed for example or USB Connection failed.) It will recover when Linuxcnc is restartet. (you could also run "unloadusr arduino", "loadusr arduino" in Hal)
// Define an Pin you want to connect the LED to. it will be set as Output indipendand of the OUTPUTS function, so don't use Pins twice. // Define an Pin you want to connect the LED to. it will be set as Output indipendand of the OUTPUTS function, so don't use Pins twice.
// If you use Digital LED's such as WS2812 or PL9823 (only works if you set up the DLED settings below) you can also define a position of the LED. In this case StatLedPin will set the number of the Digital LED Chain. // If you use Digital LED's such as WS2812 or PL9823 (only works if you set up the DLED settings below) you can also define a position of the LED. In this case StatLedPin will set the number of the Digital LED Chain.
//#define STATUSLED //#define STATUSLED
#ifdef STATUSLED #ifdef STATUSLED
const int StatLedPin = 5; //Pin for Status LED const int StatLedPin = 5; //Pin for Status LED
@ -202,7 +203,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 = 4; // Define the number of rows in the matrix const int numRows = 4; // Define the number of rows in the matrix
const int numCols = 4; // Define the number of columns in the matrix const int numCols = 4; // Define the number of columns in the matrix
@ -225,6 +226,12 @@ int lastKey= 0;
//#define DEBUG //#define DEBUG
//###Misc Settings###
const int timeout = 10000; // timeout after 10 sec not receiving Stuff
const int debounceDelay = 50;
//####################################### END OF CONFIG ########################### //####################################### END OF CONFIG ###########################
//###Misc Settings### //###Misc Settings###
@ -397,7 +404,7 @@ void loop() {
void comalive(){ void comalive(){
#ifdef STATUSLED #ifdef STATUSLED
if(millis() - lastcom > timeout){ if(millis() - lastcom > timeout){
StatLedErr(1000,10); StatLedErr(500,200);
} }
else{ else{
if(DLEDSTATUSLED){controlDLED(StatLedPin, 1);} if(DLEDSTATUSLED){controlDLED(StatLedPin, 1);}
@ -475,24 +482,24 @@ void controlDLED(int Pin, int Stat){
Serial.print(Pin); Serial.print(Pin);
Serial.print(" set to:"); Serial.print(" set to:");
Serial.println(Stat); Serial.println(Stat);
#endif
}
else{strip.setPixelColor(Pin, strip.Color(DledOffColors[Pin][0],DledOffColors[Pin][1],DledOffColors[Pin][2]));
#ifdef DEBUG
Serial.print("DLED No.");
Serial.print(Pin);
Serial.print(" set to:");
Serial.println(Stat);
#endif
}
strip.show();
} #endif
}
else{
strip.setPixelColor(Pin, strip.Color(DledOffColors[Pin][0],DledOffColors[Pin][1],DledOffColors[Pin][2]));
#ifdef DEBUG
Serial.print("DLED No.");
Serial.print(Pin);
Serial.print(" set to:");
Serial.println(Stat);
#endif
}
strip.show();
}
#endif #endif
#ifdef LPOTI #ifdef LPOTIS
int readLPoti(){ int readLPoti(){
for(int i= 0;i<LPotis; i++){ for(int i= 0;i<LPotis; i++){
int var = analogRead(LPotiPins[i][0])+margin; int var = analogRead(LPotiPins[i][0])+margin;
@ -504,8 +511,6 @@ int readLPoti(){
} }
} }
} }
#endif #endif
@ -590,6 +595,7 @@ int readAbsKnob(){
} }
#endif #endif
#ifdef KEYPAD
void readKeypad(){ void readKeypad(){
//detect if Button is Pressed //detect if Button is Pressed
for (int col = 0; col < numCols; col++) { for (int col = 0; col < numCols; col++) {
@ -623,21 +629,28 @@ void readKeypad(){
pinMode(colPins[col], INPUT); pinMode(colPins[col], INPUT);
} }
} }
#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
if(cmd == 'O'){ if(cmd == 'O'){
writeOutputs(io,value); writeOutputs(io,value);
lastcom=millis();
} }
#endif #endif
#ifdef PWMOUTPUTS #ifdef PWMOUTPUTS
if(cmd == 'P'){ if(cmd == 'P'){
writePwmOutputs(io,value); writePwmOutputs(io,value);
lastcom=millis();
} }
#endif #endif
#ifdef DLED #ifdef DLED
if(cmd == 'D'){ if(cmd == 'D'){
controlDLED(io,value); controlDLED(io,value);
lastcom=millis();
} }
#endif #endif
if(cmd == 'E'){ if(cmd == 'E'){

View File

@ -132,6 +132,7 @@ Debug = 0 #only works when this script is run from halrun in Terminal. "halrun"
######## End of Config! ######## ######## End of Config! ########
olddOutStates= [0]*Outputs olddOutStates= [0]*Outputs
oldPwmOutStates=[0]*PwmOutputs oldPwmOutStates=[0]*PwmOutputs
oldDLEDStates=[0]*DLEDcount
if LinuxKeyboardInput: if LinuxKeyboardInput:
@ -177,7 +178,7 @@ if BinSelKnob:
if DLEDcount > 0: if DLEDcount > 0:
for port in range(DLEDcount): for port in range(DLEDcount):
c.newpin("DLED.{}".format(port), hal.HAL_BIT, hal.HAL_IN) c.newpin("DLED.{}".format(port), hal.HAL_BIT, hal.HAL_IN)
oldDLEDStates[port] = 0
# setup MatrixKeyboard halpins # setup MatrixKeyboard halpins
if Keypad > 0: if Keypad > 0:
for port in range(Columns*Rows): for port in range(Columns*Rows):
@ -243,11 +244,13 @@ def managageOutputs():
for port in range(DLEDcount): for port in range(DLEDcount):
State = int(c["DLED.{}".format(port)]) State = int(c["DLED.{}".format(port)])
Sig = 'D' if oldDLEDStates[port] != State: #check if states have changed
Pin = int(port) Sig = 'D'
command = "{}{}:{}\n".format(Sig,Pin,State) Pin = int(port)
arduino.write(command.encode()) command = "{}{}:{}\n".format(Sig,Pin,State)
if (Debug):print ("Sending:{}".format(command.encode())) arduino.write(command.encode())
oldDLEDStates[port] = State
if (Debug):print ("Sending:{}".format(command.encode()))
while True: while True:
@ -350,4 +353,4 @@ while True:
arduino.write(b"E:\n") arduino.write(b"E:\n")
if (Debug):print("keepAlive") if (Debug):print("keepAlive")
event = time.time() event = time.time()