wip
This commit is contained in:
11
include/config.h
Normal file
11
include/config.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
inline constexpr uint8_t ledPinR = 16;
|
||||
inline constexpr uint8_t ledPinG = 17;
|
||||
inline constexpr uint8_t ledPinB = 18;
|
||||
inline constexpr uint8_t ledPinCW = 19;
|
||||
inline constexpr uint8_t ledPinWW = 21;
|
||||
|
||||
|
||||
inline constexpr uint32_t maxNumberOfStates = 10;
|
||||
@@ -13,6 +13,10 @@ platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
build_unflags = -std=gnu++11
|
||||
build_flags =
|
||||
-std=c++17
|
||||
-std=gnu++17
|
||||
lib_deps =
|
||||
martinverges/ESP32 Wifi Manager@^1.5.0
|
||||
esp32async/ESPAsyncWebServer@^3.7.10
|
||||
|
||||
24
src/appcontext.hpp
Normal file
24
src/appcontext.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
class Pin;
|
||||
template <uint32_t MAX_NUMBER_OF_STATES, uint32_t MAX_NUMBER_OF_TRANSITIONS>
|
||||
class StateMachine;
|
||||
class OTAHandler;
|
||||
class Mqtt;
|
||||
class Light;
|
||||
class Network;
|
||||
class Scheduler;
|
||||
|
||||
struct AppContext {
|
||||
Pin *pinR = nullptr;
|
||||
Pin *pinG = nullptr;
|
||||
Pin *pinB = nullptr;
|
||||
Pin *pinCW = nullptr;
|
||||
Pin *pinWW = nullptr;
|
||||
|
||||
Network *network = nullptr;
|
||||
Light *light = nullptr;
|
||||
Mqtt *mqtt = nullptr;
|
||||
OTAHandler *ota = nullptr;
|
||||
Scheduler *scheduler = nullptr;
|
||||
};
|
||||
38
src/main.cpp
38
src/main.cpp
@@ -1,10 +1,13 @@
|
||||
#include <Arduino.h>
|
||||
#include "appcontext.hpp"
|
||||
#include "config.h"
|
||||
#include "light.h"
|
||||
#include "mqtt.h"
|
||||
#include "network.h"
|
||||
#include "ota.h"
|
||||
#include "pin.h"
|
||||
#include "statemachine.hpp"
|
||||
#include "states.hpp"
|
||||
#include "TaskScheduler.h"
|
||||
#include "wifimanager.h"
|
||||
|
||||
@@ -13,29 +16,38 @@ OTAHandler* otaHandler = nullptr;
|
||||
Mqtt* mqttClient = nullptr;
|
||||
Light *light = nullptr;
|
||||
|
||||
|
||||
Task *updateTask = nullptr;
|
||||
Task *mqttTickTask = nullptr;
|
||||
Task *mqttCheckConnectionTask = nullptr;
|
||||
|
||||
Pin *pinR = new Pin(16, true, true, 5000, 0); // Example pin numbers, adjust as needed
|
||||
Pin *pinG = new Pin(17, true, true, 5000, 1);
|
||||
Pin *pinB = new Pin(18, true, true, 5000, 2);
|
||||
Pin *pinCW = new Pin(19, true, true, 5000, 3);
|
||||
Pin *pinWW = new Pin(21, true, true, 5000, 4);
|
||||
Pin *pinR = new Pin(ledPinR, true, true, 5000, 0);
|
||||
Pin *pinG = new Pin(ledPinG, true, true, 5000, 1);
|
||||
Pin *pinB = new Pin(ledPinB, true, true, 5000, 2);
|
||||
Pin *pinCW = new Pin(ledPinCW, true, true, 5000, 3);
|
||||
Pin *pinWW = new Pin(ledPinWW, true, true, 5000, 4);
|
||||
|
||||
Scheduler *scheduler;
|
||||
AppContext *appContext = new AppContext();
|
||||
StartState *startState = new StartState(appContext);
|
||||
|
||||
StateMachine<maxNumberOfStates> *stateMachine = nullptr;
|
||||
|
||||
Scheduler *scheduler = nullptr;
|
||||
|
||||
void initializeScheduler();
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting Smart RGB ESP32...");
|
||||
pinR->setLedLevel(0);
|
||||
pinG->setLedLevel(0);
|
||||
pinB->setLedLevel(0);
|
||||
pinCW->setLedLevel(0);
|
||||
pinWW->setLedLevel(0);
|
||||
// Serial.begin(115200);
|
||||
// Serial.println("Starting Smart RGB ESP32...");
|
||||
stateMachine = new StateMachine<maxNumberOfStates>();
|
||||
appContext->pinR = pinR;
|
||||
appContext->pinG = pinG;
|
||||
appContext->pinB = pinB;
|
||||
appContext->pinCW = pinCW;
|
||||
appContext->pinWW = pinWW;
|
||||
stateMachine->addStateRaw(startState);
|
||||
stateMachine->setInitialState(StateId::StartState);
|
||||
network = new Network("smart-rgb");
|
||||
otaHandler = new OTAHandler("smart-rgb-ota");
|
||||
network->registerMDNS();
|
||||
|
||||
49
src/states.hpp
Normal file
49
src/states.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "appcontext.hpp"
|
||||
#include "pin.h"
|
||||
#include "statemachine.hpp"
|
||||
|
||||
enum class StateId
|
||||
{
|
||||
StartState,
|
||||
NetworkInitializeState
|
||||
};
|
||||
|
||||
class StartState : public State
|
||||
{
|
||||
public:
|
||||
StartState(AppContext *appContext) : State("StartState", StateId::StartState), appContext(appContext) {}
|
||||
|
||||
void onEnter(StateMachineBase &stateMachine) override {
|
||||
if (appContext) {
|
||||
appContext->pinR->setLedLevel(0);
|
||||
appContext->pinG->setLedLevel(0);
|
||||
appContext->pinB->setLedLevel(0);
|
||||
appContext->pinCW->setLedLevel(0);
|
||||
appContext->pinWW->setLedLevel(0);
|
||||
}
|
||||
}
|
||||
|
||||
void onExit(StateMachineBase &stateMachine) override {
|
||||
}
|
||||
|
||||
void onUpdate(StateMachineBase &stateMachine) override {
|
||||
}
|
||||
|
||||
private:
|
||||
AppContext *appContext = nullptr;
|
||||
};
|
||||
|
||||
class NetworkInitializeState : public State
|
||||
{
|
||||
public:
|
||||
NetworkInitializeState() : State("NetworkInitializeState", StateId::NetworkInitializeState) {}
|
||||
|
||||
void onEnter(StateMachineBase &stateMachine) override {
|
||||
}
|
||||
|
||||
void onExit(StateMachineBase &stateMachine) override {
|
||||
}
|
||||
|
||||
void onUpdate(StateMachineBase &stateMachine) override {
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user