Skip to content

Commit

Permalink
Register Uart and macro clients before configuration so log_ works
Browse files Browse the repository at this point in the history
Also check SD after other clients so it does not lock out '?'
  • Loading branch information
MitchBradley committed Sep 13, 2021
1 parent b37188c commit af40e77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
13 changes: 9 additions & 4 deletions FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "MotionControl.h"
#include "Platform.h"

#include "WebUI/TelnetServer.h"
#include "WebUI/Serial2Socket.h"
#include "WebUI/InputBuffer.h"

#ifdef ENABLE_WIFI
Expand All @@ -38,6 +40,10 @@ void setup() {
WiFi.mode(WIFI_OFF);
#endif

// Setup input polling loop after loading the configuration,
// because the polling may depend on the config
client_init();

display_init();

// Load settings from non-volatile storage
Expand All @@ -53,10 +59,6 @@ void setup() {
bool configOkay = config->load(config_filename->get());
make_user_commands();

// Setup input polling loop after loading the configuration,
// because the polling may depend on the config
client_init();

if (configOkay) {
log_info("Machine " << config->_name);
log_info("Board " << config->_board);
Expand Down Expand Up @@ -119,10 +121,13 @@ void setup() {

#ifdef ENABLE_WIFI
WebUI::wifi_config.begin();
register_client(&WebUI::Serial2Socket);
register_client(&WebUI::telnet_server);
#endif
#ifdef ENABLE_BLUETOOTH
if (config->_comms->_bluetoothConfig) {
config->_comms->_bluetoothConfig->begin();
register_client(&WebUI::SerialBT);
}
#endif
WebUI::inputBuffer.begin();
Expand Down
35 changes: 13 additions & 22 deletions FluidNC/src/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#include "Uart.h"
#include "Machine/MachineConfig.h"
#include "WebUI/InputBuffer.h"
#include "WebUI/TelnetServer.h"
#include "WebUI/Serial2Socket.h"
#include "WebUI/Commands.h"
#include "WebUI/WifiServices.h"
#include "MotionControl.h"
Expand Down Expand Up @@ -205,29 +203,9 @@ void register_client(Stream* client_stream) {
void client_init() {
register_client(&Uart0); // USB Serial
register_client(&WebUI::inputBuffer); // Macros
#ifdef ENABLE_WIFI
register_client(&WebUI::Serial2Socket);
register_client(&WebUI::telnet_server);
#endif
#ifdef ENABLE_BT
register_client(&WebUI::SerialBT);
#endif
}

InputClient* pollClients() {
auto sdcard = config->_sdCard;
// _readyNext indicates that input is coming from a file and
// the GCode system is ready for another line.
if (sdcard && sdcard->_readyNext) {
Error res = sdcard->readFileLine(sdClient->_line, InputClient::maxLine);
if (res == Error::Ok) {
sdClient->_out = &sdcard->getClient();
sdcard->_readyNext = false;
return sdClient;
}
report_status_message(res, sdcard->getClient());
}

for (auto client : clientq) {
auto source = client->_in;
int c = source->read();
Expand Down Expand Up @@ -284,6 +262,19 @@ InputClient* pollClients() {
WebUI::wifi_services.handle(); // OTA, web_server, telnet_server polling
#endif

auto sdcard = config->_sdCard;
// _readyNext indicates that input is coming from a file and
// the GCode system is ready for another line.
if (sdcard && sdcard->_readyNext) {
Error res = sdcard->readFileLine(sdClient->_line, InputClient::maxLine);
if (res == Error::Ok) {
sdClient->_out = &sdcard->getClient();
sdcard->_readyNext = false;
return sdClient;
}
report_status_message(res, sdcard->getClient());
}

return nullptr;
}

Expand Down
2 changes: 2 additions & 0 deletions FluidNC/src/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ class AllClients : public Print {
size_t write(const uint8_t* buffer, size_t length) override;
};

void register_client(Stream* client_stream);

extern AllClients allClients;

0 comments on commit af40e77

Please sign in to comment.