Files
EggDuino/include/EggDuino.h
André Fiedler a1ffcb08ca Refactor SerialCommand to support Stream interface and improve command handling
- Added readSerial(Stream &stream) method to allow reading from any Stream-compatible transport.
- Introduced readChar(char inChar) method for processing individual characters.
- Updated command matching logic to enhance debugging output.
- Improved buffer handling and command execution flow.

Enhance platformio.ini for better compatibility and added libraries

- Added NimBLE-Arduino and WebSockets libraries for BLE and WiFi support.
- Updated upload and monitor ports for better compatibility with macOS.

Integrate WiFi and BLE protocol interfaces

- Implemented startWebInterface() to initialize WiFi protocol alongside existing web server.
- Added BLE support with a new EggBot BLE Serial Protocol for command handling over BLE.
- Created WebSocket server for WiFi communication, maintaining compatibility with existing command protocols.

Refactor command handling in Functions.cpp

- Replaced direct Serial.print calls with protocolWrite for consistent output handling.
- Updated command registration to use a lambda function for better readability and maintainability.

Add documentation for EggBot protocols

- Created separate markdown files for BLE, WiFi, and Serial protocols detailing command structures and usage.
- Provided examples of command transactions for better developer guidance.

Implement BLE and WiFi protocol handling in respective source files

- Developed BLE_Interface.cpp for managing BLE connections and data transmission.
- Created WiFi_Protocol.cpp for handling WebSocket communication and data reception.
2026-02-24 22:00:26 +01:00

153 lines
3.3 KiB
C

#ifndef EGGDUINO_H
#define EGGDUINO_H
#include <Arduino.h>
#ifdef ESP32
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WebServer.h>
#include <SPIFFS.h>
#else
#include <Servo.h>
#endif
#include <FastAccelStepper.h>
#include "SerialCommand.h"
#include "button.h"
// implemented Eggbot-Protocol-Version v13
#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6a"
#ifdef ESP32
// Rotational Stepper
#define dir1 16
#define enableRotMotor 12
#define step1 26
#define rotMicrostep 32
// Pen Stepper
#define step2 25
#define dir2 27
#define enablePenMotor 12
#define penMicrostep 32
#define servoPin 17
#else
// Rotational Stepper
#define step1 2
#define dir1 5
#define enableRotMotor 8
#define rotMicrostep 16
// Pen Stepper
#define step2 3
#define dir2 6
#define enablePenMotor 8
#define penMicrostep 16
#define servoPin 4
#endif
struct ConfigParameter {
const char *key;
int *value;
String description;
int defaultValue;
};
extern FastAccelStepperEngine g_stepEngine;
extern FastAccelStepper *g_pStepperRotate;
extern FastAccelStepper *g_pStepperPen;
extern Servo penServo;
extern SerialCommand SCmd;
#ifdef ESP32
extern SerialCommand g_BLECmd;
extern SerialCommand g_WifiCmd;
#endif
extern int g_iPenUpPos;
extern int g_iPenDownPos;
extern int g_iServoRateUp;
extern int g_iServoRateDown;
extern long g_iRotStepError;
extern long g_iPenStepError;
extern int g_iPenState;
extern uint32_t g_uiNodeCount;
extern unsigned int g_uiLayer;
extern boolean g_bPrgButtonState;
extern float fROT_STEP_CORRECTION;
extern float fPEN_STEP_CORRECTION;
extern boolean g_bMotorsEnabled;
enum ProtocolTransport {
PROTOCOL_TRANSPORT_SERIAL = 0,
PROTOCOL_TRANSPORT_BLE = 1,
PROTOCOL_TRANSPORT_WIFI = 2,
};
extern ConfigParameter configParameters[];
extern const size_t configParameterCount;
void makeComInterface();
void setActiveProtocolContext(SerialCommand *parser, ProtocolTransport transport);
char *nextCommandArg();
void protocolWrite(const char *message);
void protocolWrite(const String &message);
void initHardware();
void moveOneStep();
void moveToDestination();
void sendAck();
void sendError();
void motorsOff();
void motorsOn();
void toggleMotors();
void doTogglePen();
void setprgButtonState();
bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB);
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB);
void storePenUpPosInEE();
void storePenDownPosInEE();
bool initConfigStore();
bool loadConfigFromFile();
bool saveConfigToFile();
String buildConfigJson();
bool applyConfigJson(const String &payload, String &errorMessage);
void startWebInterface();
void handleWebInterface();
#ifdef ESP32
void startBleInterface();
void handleBleInterface();
bool bleProtocolWrite(const char *message);
void startWifiProtocolInterface();
void handleWifiProtocolInterface();
bool wifiProtocolWrite(const char *message);
#else
inline void startBleInterface() {}
inline void handleBleInterface() {}
inline bool bleProtocolWrite(const char *message)
{
(void)message;
return false;
}
inline void startWifiProtocolInterface() {}
inline void handleWifiProtocolInterface() {}
inline bool wifiProtocolWrite(const char *message)
{
(void)message;
return false;
}
#endif
void Log(const String &message);
void Log(const char *message);
String buildLogsJson(uint32_t sinceSeq);
#endif