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

@ -8,6 +8,7 @@
#include "dummyEEPROM.h"
#endif
#include "main.h"
#include <ComPort.h>
// The array below has 3 stepper objects, for X,Y,Z respectively
const uint8_t n_motors = STAGE_N_MOTORS;
@ -76,10 +77,10 @@ void print_position()
EACH_MOTOR
{
if (i > 0)
SERIAL_PORT.print(" ");
SERIAL_PORT.print(current_pos[i]);
comPort->print(" ");
comPort->print(current_pos[i]);
}
SERIAL_PORT.println();
comPort->println();
}
unsigned long move_start_time = 0;
@ -124,7 +125,7 @@ void start_move(long displ[n_motors])
}
else
{
SERIAL_PORT.println("done.");
comPort->println("done.");
}
}
@ -183,7 +184,7 @@ void stage_loop()
if (!stage_moving && notify_on_stop)
{
SERIAL_PORT.println("stopped");
comPort->println("stopped");
notify_on_stop = false;
}
}
@ -233,7 +234,7 @@ void stage_release(String command)
{
releaseMotor(i);
}
SERIAL_PORT.println("done");
comPort->println("done");
}
void stage_p(String command)
@ -247,14 +248,14 @@ void stage_min_step_delay(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
SERIAL_PORT.print("minimum step delay ");
SERIAL_PORT.println(min_step_delay);
comPort->print("minimum step delay ");
comPort->println(min_step_delay);
}
else
{
min_step_delay = atol(args[0]);
EEPROM.put(min_step_delay_eeprom, min_step_delay);
SERIAL_PORT.println("done.");
comPort->println("done.");
}
free(args[0]);
}
@ -265,14 +266,14 @@ void stage_ramp_time(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
SERIAL_PORT.print("ramp_time ");
SERIAL_PORT.println(ramp_time);
comPort->print("ramp_time ");
comPort->println(ramp_time);
}
else
{
ramp_time = atol(args[0]);
EEPROM.put(ramp_time_eeprom, ramp_time);
SERIAL_PORT.println("done.");
comPort->println("done.");
}
free(args[0]);
}
@ -283,41 +284,41 @@ void update_blocking_moves(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
SERIAL_PORT.print("blocking_moves ");
SERIAL_PORT.println(non_blocking_moves ? "false" : "true");
comPort->print("blocking_moves ");
comPort->println(non_blocking_moves ? "false" : "true");
}
else
{
non_blocking_moves = !(args[0][0] == 't');
EEPROM.put(non_blocking_moves_eeprom, non_blocking_moves);
SERIAL_PORT.println("done.");
comPort->println("done.");
}
}
void stage_zero(String command)
{
EACH_MOTOR current_pos[i] = 0;
SERIAL_PORT.println(F("position reset to 0 0 0"));
comPort->println(F("position reset to 0 0 0"));
EEPROM.put(0, current_pos);
}
void stage_stop(String command)
{
stage_moving = false;
SERIAL_PORT.println("Move aborted");
comPort->println("Move aborted");
}
void is_stage_moving(String command)
{
//TODO: should I bother checking for a ?
SERIAL_PORT.println(stage_moving ? "true" : "false");
comPort->println(stage_moving ? "true" : "false");
}
void activate_notify_on_stop(String command)
{
if (!stage_moving)
{
SERIAL_PORT.println("Error: stage is not moving");
comPort->println("Error: stage is not moving");
}
else
{