2022-11-25 00:38:01 +01:00
|
|
|
/*
|
2022-11-25 02:43:59 +01:00
|
|
|
LinuxCNC_ArduinoConnector
|
|
|
|
By Alexander Richter, info@theartoftinkering.com 2022
|
|
|
|
|
|
|
|
This Software is used as IO Expansion for LinuxCNC. Here i am using a Mega 2560.
|
|
|
|
|
|
|
|
It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches!
|
|
|
|
|
|
|
|
You can create as many digital & analog Inputs, Outputs and PWM Outputs as your Arduino can handle.
|
|
|
|
You can also generate "virtual Pins" by using latching Potentiometers, which are connected to one analog Pin, but are read in Hal as individual Pins.
|
|
|
|
|
|
|
|
Currently the Software provides:
|
|
|
|
- analog Inputs
|
|
|
|
- latching Potentiometers
|
|
|
|
- 1 absolute encoder input
|
|
|
|
- digital Inputs
|
|
|
|
- digital Outputs
|
|
|
|
|
|
|
|
The Send and receive Protocol is <Signal><PinNumber>:<Pin State>
|
|
|
|
To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged.
|
|
|
|
Data is only send everythime it changes once.
|
|
|
|
|
|
|
|
Inputs = 'I' -write only -Pin State: 0,1
|
|
|
|
Outputs = 'O' -read only -Pin State: 0,1
|
|
|
|
PWM Outputs = 'P' -read only -Pin State: 0-255
|
|
|
|
Analog Inputs = 'A' -write only -Pin State: 0-1024
|
|
|
|
Latching Potentiometers = 'L' -write only -Pin State: 0-max Position
|
|
|
|
Absolute Encoder input = 'K' -write only -Pin State: 0-32
|
|
|
|
|
|
|
|
Command 'E0:0' is used for connectivity checks and is send every 5 seconds as keep alive signal
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2022-11-25 00:38:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
//###IO's###
|
2022-11-25 03:04:17 +01:00
|
|
|
#define INPUTS
|
|
|
|
#ifdef INPUTS
|
2022-11-25 00:38:01 +01:00
|
|
|
const int Inputs = 16; //number of inputs using internal Pullup resistor. (short to ground to trigger)
|
|
|
|
int InPinmap[] = {32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48};
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define OUTPUTS
|
|
|
|
#ifdef OUTPUTS
|
|
|
|
const int Outputs = 9; //number of outputs
|
|
|
|
int OutPinmap[] = {10,9,8,7,6,5,4,3,2,21};
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define PWMOUTPUTS
|
|
|
|
#ifdef PWMOUTPUTS
|
2022-11-25 02:43:59 +01:00
|
|
|
const int PwmOutputs = 2; //number of outputs
|
2022-11-26 01:16:53 +01:00
|
|
|
int PwmOutPinmap[] = {12,11};
|
2022-11-25 00:38:01 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define AINPUTS
|
|
|
|
#ifdef AINPUTS
|
|
|
|
const int AInputs = 1;
|
2022-11-25 22:12:38 +01:00
|
|
|
int AInPinmap[] = {1}; //Potentiometer for SpindleSpeed override
|
2022-11-25 02:43:59 +01:00
|
|
|
int smooth = 200; //number of samples to denoise ADC, try lower numbers on your setup
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define LPOTIS
|
|
|
|
#ifdef LPOTIS
|
|
|
|
const int LPotis = 2;
|
|
|
|
int LPotiPins[LPotis][2] = {
|
2022-11-25 22:12:38 +01:00
|
|
|
{2,9}, //Latching Knob Spindle Overdrive on A1, has 9 Positions
|
|
|
|
{3,4} //Latching Knob Feed Resolution on A2, has 4 Positions
|
2022-11-25 00:38:01 +01:00
|
|
|
};
|
2022-11-25 02:43:59 +01:00
|
|
|
int margin = 20; //giving it some margin so Numbers dont jitter, make this number smaller if your knob has more than 50 Positions
|
2022-11-25 00:38:01 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define ABSENCODER
|
|
|
|
#ifdef ABSENCODER
|
|
|
|
const int AbsEncPins[] = {27,28,31,29,30}; //1,2,4,8,16
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
|
|
|
|
#define STATUSLED
|
2022-11-21 12:56:51 +01:00
|
|
|
#ifdef STATUSLED
|
|
|
|
const int StatLedPin = 13; //Pin for Status LED
|
|
|
|
const int StatLedErrDel[] = {1000,10}; //Blink Timing for Status LED Error (no connection)
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
//###Misc Settings###
|
|
|
|
const int timeout = 10000; // timeout after 10 sec not receiving Stuff
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 03:04:17 +01:00
|
|
|
//#define DEBUG
|
2022-11-21 12:53:33 +01:00
|
|
|
|
|
|
|
//Variables for Saving States
|
2022-11-25 03:04:17 +01:00
|
|
|
#ifdef INPUTS
|
2022-11-25 00:38:01 +01:00
|
|
|
int InState[Inputs];
|
|
|
|
int oldInState[Inputs];
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
#ifdef OUTPUTS
|
|
|
|
int OutState[Outputs];
|
|
|
|
int oldOutState[Outputs];
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 02:43:59 +01:00
|
|
|
#ifdef PWMOUTPUTS
|
|
|
|
int OutPWMState[PwmOutputs];
|
|
|
|
int oldOutPWMState[PwmOutputs];
|
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
#ifdef AINPUTS
|
|
|
|
int oldAinput[AInputs];
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
#ifdef LPOTIS
|
2022-11-25 02:43:59 +01:00
|
|
|
int Lpoti[LPotis];
|
2022-11-25 00:38:01 +01:00
|
|
|
int oldLpoti[LPotis];
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
#ifdef ABSENCODER
|
|
|
|
int oldAbsEncState;
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
//### global Variables setup###
|
2022-11-25 02:43:59 +01:00
|
|
|
//Please don't touch them
|
2022-11-21 12:56:51 +01:00
|
|
|
unsigned long oldmillis = 0;
|
2022-11-25 00:38:01 +01:00
|
|
|
unsigned long newcom = 0;
|
|
|
|
unsigned long lastcom = 0;
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
#define STATE_CMD 0
|
|
|
|
#define STATE_IO 1
|
|
|
|
#define STATE_VALUE 2
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
byte state = STATE_CMD;
|
|
|
|
char inputbuffer[5];
|
|
|
|
byte bufferIndex = 0;
|
|
|
|
char cmd = 0;
|
|
|
|
uint16_t io = 0;
|
|
|
|
uint16_t value = 0;
|
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
void setup() {
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 03:04:17 +01:00
|
|
|
#ifdef INPUTS
|
2022-11-21 12:56:51 +01:00
|
|
|
//setting Inputs with internal Pullup Resistors
|
2022-11-25 00:38:01 +01:00
|
|
|
for(int i= 0; i<Inputs;i++){
|
|
|
|
pinMode(InPinmap[i], INPUT_PULLUP);
|
2022-11-21 12:56:51 +01:00
|
|
|
oldInState[i] = -1;
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 02:43:59 +01:00
|
|
|
#ifdef AINPUTS
|
2022-11-25 00:38:01 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
for(int i= 0; i<AInputs;i++){
|
|
|
|
pinMode(AInPinmap[i], INPUT);
|
|
|
|
oldAinput[i] = -1;
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
#ifdef OUTPUTS
|
|
|
|
for(int o= 0; o<Outputs;o++){
|
|
|
|
pinMode(OutPinmap[o], OUTPUT);
|
2022-11-21 12:56:51 +01:00
|
|
|
oldOutState[o] = 0;
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
#ifdef PWMOUTPUTS
|
|
|
|
for(int o= 0; o<PwmOutputs;o++){
|
|
|
|
pinMode(PwmOutPinmap[o], OUTPUT);
|
|
|
|
oldOutPWMState[o] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-21 12:56:51 +01:00
|
|
|
#ifdef STATUSLED
|
|
|
|
pinMode(StatLedPin, OUTPUT);
|
|
|
|
#endif
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
#ifdef ABSENCODER
|
|
|
|
pinMode(AbsEncPins[0], INPUT_PULLUP);
|
|
|
|
pinMode(AbsEncPins[1], INPUT_PULLUP);
|
|
|
|
pinMode(AbsEncPins[2], INPUT_PULLUP);
|
|
|
|
pinMode(AbsEncPins[3], INPUT_PULLUP);
|
|
|
|
pinMode(AbsEncPins[4], INPUT_PULLUP);
|
|
|
|
#endif
|
|
|
|
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
//Setup Serial
|
2022-11-21 12:56:51 +01:00
|
|
|
Serial.begin(115200);
|
2022-11-25 02:43:59 +01:00
|
|
|
while (!Serial){}
|
|
|
|
while (lastcom == 0){
|
|
|
|
readCommands();
|
|
|
|
flushSerial();
|
2022-11-25 22:12:38 +01:00
|
|
|
Serial.println("E0:0");
|
2022-11-21 12:56:51 +01:00
|
|
|
#ifdef STATUSLED
|
2022-11-25 02:43:59 +01:00
|
|
|
StatLedErr(1000,1000);
|
2022-11-21 12:56:51 +01:00
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
readCommands(); //receive and execute Commands
|
|
|
|
comalive(); //if nothing is received for 10 sec. blink warning LED
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 03:04:17 +01:00
|
|
|
#ifdef INPUTS
|
|
|
|
readInputs(); //read Inputs & send data
|
2022-11-25 02:43:59 +01:00
|
|
|
#endif
|
|
|
|
#ifdef AINPUTS
|
2022-11-25 03:04:17 +01:00
|
|
|
readAInputs(); //read Analog Inputs & send data
|
2022-11-25 02:43:59 +01:00
|
|
|
#endif
|
|
|
|
#ifdef LPOTIS
|
2022-11-25 03:04:17 +01:00
|
|
|
readLPoti(); //read LPotis & send data
|
2022-11-25 02:43:59 +01:00
|
|
|
#endif
|
|
|
|
#ifdef ABSENCODER
|
2022-11-25 03:04:17 +01:00
|
|
|
readAbsKnob(); //read ABS Encoder & send data
|
2022-11-25 02:43:59 +01:00
|
|
|
#endif
|
2022-11-21 12:53:33 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
void comalive(){
|
|
|
|
if(millis() - lastcom > timeout){
|
2022-11-25 02:43:59 +01:00
|
|
|
StatLedErr(1000,10);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
digitalWrite(StatLedPin, HIGH);
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-21 12:56:51 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
void StatLedErr(int offtime, int ontime){
|
2022-11-21 12:56:51 +01:00
|
|
|
unsigned long newMillis = millis();
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
if (newMillis - oldmillis >= offtime){
|
2022-11-21 12:56:51 +01:00
|
|
|
|
|
|
|
digitalWrite(StatLedPin, HIGH);
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if (newMillis - oldmillis >= offtime+ontime){{
|
2022-11-21 12:56:51 +01:00
|
|
|
digitalWrite(StatLedPin, LOW);
|
|
|
|
oldmillis = newMillis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
void sendData(char sig, int pin, int state){
|
|
|
|
Serial.print(sig);
|
|
|
|
Serial.print(pin);
|
|
|
|
Serial.print(":");
|
|
|
|
Serial.println(state);
|
2022-11-21 12:56:51 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
void flushSerial(){
|
|
|
|
while (Serial.available() > 0) {
|
|
|
|
Serial.read();
|
2022-11-21 12:56:51 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
|
|
|
|
void writeOutputs(int Pin, int Stat){
|
2022-11-26 01:16:53 +01:00
|
|
|
digitalWrite(Pin, Stat);
|
2022-11-25 02:43:59 +01:00
|
|
|
}
|
2022-11-25 03:04:17 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
void writePwmOutputs(int Pin, int Stat){
|
2022-11-26 01:16:53 +01:00
|
|
|
analogWrite(Pin, Stat);
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
2022-11-21 12:53:33 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
int readLPoti(){
|
|
|
|
for(int i= 0;i<LPotis; i++){
|
2022-11-26 01:16:53 +01:00
|
|
|
int var = analogRead(LPotiPins[i][0])+margin;
|
|
|
|
int pos = 1024/(LPotiPins[i][1]-1);
|
|
|
|
var = var/pos;
|
|
|
|
if(oldLpoti[i]!= var){
|
|
|
|
oldLpoti[i] = var;
|
2022-11-25 02:43:59 +01:00
|
|
|
sendData('L', LPotiPins[i][0],oldLpoti[i]);
|
|
|
|
}
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-21 12:53:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
|
|
|
|
int readAInputs(){
|
2022-11-25 00:38:01 +01:00
|
|
|
unsigned long var = 0;
|
2022-11-25 02:43:59 +01:00
|
|
|
for(int i= 0;i<AInputs; i++){
|
|
|
|
int State = analogRead(AInPinmap[i]);
|
|
|
|
for(int i= 0;i<smooth; i++){// take couple samples to denoise signal
|
|
|
|
var = var+ analogRead(AInPinmap[i]);
|
|
|
|
}
|
|
|
|
var = var / smooth;
|
|
|
|
if(oldAinput[i]!= var){
|
|
|
|
oldAinput[i] = var;
|
|
|
|
sendData('A',AInPinmap[i],oldAinput[i]);
|
|
|
|
}
|
2022-11-25 22:12:38 +01:00
|
|
|
}
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
void readInputs(){
|
|
|
|
for(int i= 0;i<Inputs; i++){
|
|
|
|
int State = digitalRead(InPinmap[i]);
|
|
|
|
if(InState[i]!= State){
|
|
|
|
InState[i] = State;
|
|
|
|
sendData('I',InPinmap[i],InState[i]);
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
}
|
2022-11-21 12:53:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int readAbsKnob(){
|
|
|
|
int var = 0;
|
2022-11-25 02:43:59 +01:00
|
|
|
if(digitalRead(AbsEncPins[0])==1){
|
2022-11-21 12:53:33 +01:00
|
|
|
var += 1;
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if(digitalRead(AbsEncPins[1])==1){
|
2022-11-21 12:53:33 +01:00
|
|
|
var += 2;
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if(digitalRead(AbsEncPins[2])==1){
|
2022-11-21 12:53:33 +01:00
|
|
|
var += 4;
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if(digitalRead(AbsEncPins[3])==1){
|
2022-11-21 12:53:33 +01:00
|
|
|
var += 8;
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if(digitalRead(AbsEncPins[4])==1){
|
2022-11-21 12:53:33 +01:00
|
|
|
var += 16;
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
if(var != oldAbsEncState){
|
2022-11-25 22:12:38 +01:00
|
|
|
Serial.print("K0:");
|
2022-11-21 12:53:33 +01:00
|
|
|
Serial.println(var);
|
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
oldAbsEncState = var;
|
2022-11-21 12:53:33 +01:00
|
|
|
return (var);
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
2022-11-25 02:43:59 +01:00
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
|
|
|
|
void commandReceived(char cmd, uint16_t io, uint16_t value){
|
2022-11-25 02:43:59 +01:00
|
|
|
if(cmd == 'O'){
|
|
|
|
writeOutputs(io,value);
|
|
|
|
}
|
|
|
|
if(cmd == 'P'){
|
|
|
|
writePwmOutputs(io,value);
|
|
|
|
}
|
|
|
|
if(cmd == 'E'){
|
|
|
|
lastcom=millis();
|
|
|
|
}
|
2022-11-25 00:38:01 +01:00
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.print("I Received= ");
|
|
|
|
Serial.print(cmd);
|
|
|
|
Serial.print(io);
|
|
|
|
Serial.print(":");
|
|
|
|
Serial.println(value);
|
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int isCmdChar(char cmd){
|
|
|
|
if(cmd == 'O'||cmd == 'P'||cmd == 'E') {return true;}
|
|
|
|
else{return false;}
|
|
|
|
}
|
|
|
|
|
|
|
|
void readCommands(){
|
|
|
|
byte current;
|
|
|
|
while(Serial.available() > 0){
|
|
|
|
current = Serial.read();
|
|
|
|
switch(state){
|
|
|
|
case STATE_CMD:
|
|
|
|
if(isCmdChar(current)){
|
|
|
|
cmd = current;
|
|
|
|
state = STATE_IO;
|
|
|
|
bufferIndex = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_IO:
|
|
|
|
if(isDigit(current)){
|
|
|
|
inputbuffer[bufferIndex++] = current;
|
|
|
|
}else if(current == ':'){
|
|
|
|
inputbuffer[bufferIndex] = 0;
|
|
|
|
io = atoi(inputbuffer);
|
|
|
|
state = STATE_VALUE;
|
|
|
|
bufferIndex = 0;
|
|
|
|
|
2022-11-25 02:43:59 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
#ifdef DEBUG
|
2022-11-25 00:38:01 +01:00
|
|
|
Serial.print("Ungültiges zeichen: ");
|
|
|
|
Serial.println(current);
|
2022-11-25 02:43:59 +01:00
|
|
|
#endif
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_VALUE:
|
|
|
|
if(isDigit(current)){
|
|
|
|
inputbuffer[bufferIndex++] = current;
|
2022-11-25 02:43:59 +01:00
|
|
|
}
|
|
|
|
else if(current == '\n'){
|
2022-11-25 00:38:01 +01:00
|
|
|
inputbuffer[bufferIndex] = 0;
|
|
|
|
value = atoi(inputbuffer);
|
|
|
|
commandReceived(cmd, io, value);
|
|
|
|
state = STATE_CMD;
|
2022-11-25 02:43:59 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.print("Ungültiges zeichen: ");
|
|
|
|
Serial.println(current);
|
|
|
|
#endif
|
|
|
|
|
2022-11-25 00:38:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|