1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-30 17:49:56 +02:00

Fixed $system/control=reset problem

It was fairly insidious - the client read loop alway thought that
serial data is available, due to a problem with uint8_t vs int.
With uint8_t, there was no way to receive a -1 return value from
the various low level read routines.

I also fixed an ordering problem with config vs client input.
It is necessary to do the config first because client input
depends on the config.
This commit is contained in:
Mitch Bradley
2021-06-23 11:54:54 -10:00
parent 8160d247b5
commit 07499e254b
4 changed files with 24 additions and 13 deletions

View File

@@ -30,6 +30,7 @@
#include "Limits.h"
#include "Protocol.h"
#include "System.h"
#include "Uart.h"
#include "WebUI/WifiConfig.h"
#include "WebUI/InputBuffer.h"
@@ -42,7 +43,7 @@ extern void make_grbl_commands();
void grbl_init() {
try {
client_init(); // Setup serial baud rate and interrupts
uartInit(); // Setup serial port
debug_serial("Initializing WiFi...");
WiFi.persistent(false);
@@ -65,6 +66,10 @@ void grbl_init() {
config->load(config_filename->get());
make_grbl_commands();
// Setup input polling loop after loading the configuration,
// because the polling may depend on the config
client_init();
report_machine_type(CLIENT_SERIAL);
info_serial("Board: %s", config->_board.c_str());

View File

@@ -106,11 +106,7 @@ void client_init() {
xTaskCreatePinnedToCore(heapCheckTask, "heapTask", 2000, NULL, 1, NULL, 1);
#endif
Uart0.setPins(GPIO_NUM_1, GPIO_NUM_3); // Tx 1, Rx 3 - standard hardware pins
Uart0.begin(BAUD_RATE, Uart::Data::Bits8, Uart::Stop::Bits1, Uart::Parity::None);
client_reset_read_buffer(CLIENT_ALL);
Uart0.write("\r\n"); // create some white space after ESP32 boot info
clientCheckTaskHandle = 0;
// create a task to check for incoming data
@@ -126,7 +122,7 @@ void client_init() {
);
}
static uint8_t getClientChar(uint8_t& data) {
static ClientType getClientChar(int& data) {
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (data = Uart0.read()) != -1) {
return CLIENT_SERIAL;
}
@@ -150,22 +146,23 @@ static uint8_t getClientChar(uint8_t& data) {
// this task runs and checks for data on all interfaces
// Realtime stuff is acted upon, then characters are added to the appropriate buffer
void clientCheckTask(void* pvParameters) {
uint8_t data = 0;
uint8_t client; // who sent the data
int data = 0; // Must be int so -1 value is possible
ClientType client; // who sent the data
while (true) { // run continuously
std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); // read fence for settings
while ((client = getClientChar(data)) != CLIENT_ALL) {
uint8_t clientByte = uint8_t(data);
// Pick off realtime command characters directly from the serial stream. These characters are
// not passed into the main buffer, but these set system state flag bits for realtime execution.
if (is_realtime_command(data)) {
execute_realtime_command(static_cast<Cmd>(data), client);
if (is_realtime_command(clientByte)) {
execute_realtime_command(static_cast<Cmd>(clientByte), client);
} else {
if (config->_sdCard->get_state(false) < SDCard::State::Busy) {
vTaskEnterCritical(&myMutex);
client_buffer[client].write(data);
client_buffer[client].write(clientByte);
vTaskExitCritical(&myMutex);
} else {
if (data == '\r' || data == '\n') {
if (clientByte == '\r' || clientByte == '\n') {
grbl_sendf(client, "error %d\r\n", Error::AnotherInterfaceBusy);
info_client(client, "SD card job running");
}

View File

@@ -19,6 +19,7 @@
* UART driver that accesses the ESP32 hardware FIFOs directly.
*/
#include "Logging.h"
#include "Uart.h"
#include <esp_system.h>
@@ -66,7 +67,7 @@ int Uart::read(TickType_t timeout) {
}
uint8_t c;
int res = uart_read_bytes(_uart_num, &c, 1, timeout);
return res != 1 ? -1 : c;
return res == 1 ? c : -1;
}
int Uart::read() {
return read(0);
@@ -110,3 +111,9 @@ bool Uart::flushTxTimed(TickType_t ticks) {
}
Uart Uart0(0);
void uartInit() {
Uart0.setPins(GPIO_NUM_1, GPIO_NUM_3); // Tx 1, Rx 3 - standard hardware pins
Uart0.begin(BAUD_RATE, Uart::Data::Bits8, Uart::Stop::Bits1, Uart::Parity::None);
Uart0.write("\r\n"); // create some white space after ESP32 boot info
}

View File

@@ -71,3 +71,5 @@ public:
};
extern Uart Uart0;
extern void uartInit();