Add print log functionality and device name handling
- Introduced functions to capture and manage incoming print logs. - Added a download link for the incoming print log in the web interface. - Updated device name prefix for BLE and added device name building logic. - Enhanced SerialCommand class with line handler support. - Implemented WiFi reconnect logic and status tracking.
This commit is contained in:
@@ -30,6 +30,7 @@ SerialCommand::SerialCommand()
|
||||
: commandList(NULL),
|
||||
commandCount(0),
|
||||
defaultHandler(NULL),
|
||||
lineHandler(NULL),
|
||||
term('\r'), // default terminator for commands, newline character
|
||||
last(NULL)
|
||||
{
|
||||
@@ -64,6 +65,10 @@ void SerialCommand::setDefaultHandler(void (*function)(const char *)) {
|
||||
defaultHandler = function;
|
||||
}
|
||||
|
||||
void SerialCommand::setLineHandler(LineHandler function) {
|
||||
lineHandler = function;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This checks the Serial stream for characters, and assembles them into a buffer.
|
||||
@@ -92,6 +97,10 @@ void SerialCommand::readChar(char inChar) {
|
||||
Serial.println(buffer);
|
||||
#endif
|
||||
|
||||
if ((lineHandler != NULL) && (bufPos > 0)) {
|
||||
(*lineHandler)(buffer);
|
||||
}
|
||||
|
||||
char *command = strtok_r(buffer, delim, &last); // Search for command at start of buffer
|
||||
if (command != NULL) {
|
||||
boolean matched = false;
|
||||
|
||||
@@ -44,9 +44,12 @@
|
||||
|
||||
class SerialCommand {
|
||||
public:
|
||||
typedef void (*LineHandler)(const char *);
|
||||
|
||||
SerialCommand(); // Constructor
|
||||
void addCommand(const char *command, void(*function)()); // Add a command to the processing dictionary.
|
||||
void setDefaultHandler(void (*function)(const char *)); // A handler to call when no valid command received.
|
||||
void setLineHandler(LineHandler function); // Optional handler called with each completed input line.
|
||||
|
||||
void readSerial(); // Main entry point.
|
||||
void readSerial(Stream &stream); // Reads commands from any Stream-compatible transport.
|
||||
@@ -65,6 +68,7 @@ class SerialCommand {
|
||||
|
||||
// Pointer to the default handler function
|
||||
void (*defaultHandler)(const char *);
|
||||
LineHandler lineHandler;
|
||||
|
||||
char delim[2]; // null-terminated list of character to be used as delimeters for tokenizing (default " ")
|
||||
char term; // Character that signals end of command (default '\n')
|
||||
|
||||
Reference in New Issue
Block a user