Merge in com port switching from sangaboard v4

I've refactored the use of the serial port, to store the
current serial port in a global variable in a module.
This is set to the most recent port to receive data,
and so we should always be replying to the port
that was used to initiate a command.

If SECONDARY_SERIAL_PORT is not defined, this
should result in no change - if it is, we should be
able to communicate on either port.
This commit is contained in:
Richard Bowman 2023-02-22 12:05:48 +00:00
parent e65c290ae6
commit 3997d66cde
12 changed files with 180 additions and 145 deletions

View file

@ -1,6 +1,7 @@
#include "config.h"
#ifdef ILLUMINATION
#include "illumination.h"
#include <ComPort.h>
#ifdef SUPPORT_EEPROM
#include <EEPROM.h>
#else
@ -16,11 +17,11 @@ void illumination_pwm_freq(String command)
analogWriteFreq(atol(args[0]));//32khz seems sensible
analogWriteRange(65535);
SERIAL_PORT.print("Frequency set: ");
SERIAL_PORT.print(atol(args[0]));
SERIAL_PORT.println("Hz");
comPort->print("Frequency set: ");
comPort->print(atol(args[0]));
comPort->println("Hz");
#else
SERIAL_PORT.println("Feature not supported");
comPort->println("Feature not supported");
#endif
free(args[0]);
@ -35,7 +36,7 @@ void illumination_pwm(String command)
uint8_t index = atoi(args[0]);
if (index >= PWM_NUM)
{
Serial.println("Invalid index");
comPort->println("Invalid index");
}
float val = atof(args[1]);
@ -50,8 +51,8 @@ void illumination_pwm(String command)
#endif
analogWrite(pwm_led_pins[index], pwm_val);
SERIAL_PORT.print("Illumination set");
SERIAL_PORT.println(pwm_val);
comPort->print("Illumination set");
comPort->println(pwm_val);
free(args[0]);
free(args[1]);
@ -117,10 +118,10 @@ void cc_set(String command)
delayMicroseconds(stepd);
digitalWrite(WIRING_CC_LED, HIGH);
delayMicroseconds(td);
Serial.println("Stepping CC"); //TODO remove debug print
comPort->println("Stepping CC"); //TODO remove debug print
}
#else
SERIAL_PORT.println("CC LED not supported");
comPort->println("CC LED not supported");
#endif
}