Working on migrating to using websockets for the UI
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
// Contains configuration constants:
|
||||
|
||||
#define FIRMWARE_VERSION "1.0.2"
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "dashboard_state.h"
|
||||
|
||||
|
||||
void DashboardState::begin() {}
|
||||
|
||||
void DashboardState::update()
|
||||
{
|
||||
unsigned long seconds = millis() / 1000;
|
||||
|
||||
unsigned long days = seconds / 86400;
|
||||
seconds %= 86400;
|
||||
|
||||
unsigned long hours = seconds / 3600;
|
||||
seconds %= 3600;
|
||||
|
||||
unsigned long minutes = seconds / 60;
|
||||
seconds %= 60;
|
||||
|
||||
|
||||
char buffer[64];
|
||||
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%lu days %02lu:%02lu:%02lu",
|
||||
days,
|
||||
hours,
|
||||
minutes,
|
||||
seconds
|
||||
);
|
||||
|
||||
|
||||
uptime = String(buffer);
|
||||
|
||||
firmwareVersion = FIRMWARE_VERSION;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
class DashboardState
|
||||
{
|
||||
public:
|
||||
|
||||
void begin();
|
||||
void update();
|
||||
|
||||
|
||||
String uptime;
|
||||
|
||||
String firmwareVersion;
|
||||
|
||||
};
|
||||
+6
-3
@@ -3,8 +3,9 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "services/service_manager.h"
|
||||
#include "core/dashboard_state.h"
|
||||
|
||||
#include "services/service_manager.h"
|
||||
#include "services/wifi_service.h"
|
||||
#include "services/ota_service.h"
|
||||
#include "services/web_service.h"
|
||||
@@ -12,12 +13,15 @@
|
||||
#include "tasks/system_task.h"
|
||||
|
||||
|
||||
DashboardState dashboardState;
|
||||
|
||||
|
||||
ServiceManager services;
|
||||
|
||||
|
||||
WiFiService wifi;
|
||||
OTAService ota;
|
||||
WebService web;
|
||||
WebService web(dashboardState);
|
||||
|
||||
|
||||
SystemTask systemTask(services);
|
||||
@@ -28,7 +32,6 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
services.add(&wifi);
|
||||
services.add(&ota);
|
||||
services.add(&web);
|
||||
|
||||
@@ -18,7 +18,7 @@ void ServiceManager::begin()
|
||||
}
|
||||
|
||||
|
||||
void ServiceManager::update()
|
||||
void ServiceManager::tick()
|
||||
{
|
||||
for(uint8_t i = 0; i < count; i++)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
|
||||
void begin();
|
||||
|
||||
void update();
|
||||
void tick();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "web_service.h"
|
||||
|
||||
#define FIRMWARE_VERSION "1.0.1"
|
||||
|
||||
WebService::WebService()
|
||||
WebService::WebService(DashboardState& state)
|
||||
:
|
||||
Service("Web", 10),
|
||||
dashboardState(state),
|
||||
server(80)
|
||||
{
|
||||
}
|
||||
@@ -134,7 +133,7 @@ void WebService::begin() {
|
||||
server.send(
|
||||
200,
|
||||
"text/plain",
|
||||
FIRMWARE_VERSION
|
||||
dashboardState.firmwareVersion
|
||||
);
|
||||
});
|
||||
|
||||
@@ -143,7 +142,7 @@ void WebService::begin() {
|
||||
server.send(
|
||||
200,
|
||||
"text/plain",
|
||||
formatUptime()
|
||||
dashboardState.uptime
|
||||
);
|
||||
|
||||
});
|
||||
@@ -157,5 +156,6 @@ void WebService::begin() {
|
||||
|
||||
void WebService::update()
|
||||
{
|
||||
dashboardState.update();
|
||||
server.handleClient();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "service.h"
|
||||
#include "../core/dashboard_state.h"
|
||||
#include <WebServer.h>
|
||||
|
||||
|
||||
@@ -8,7 +9,7 @@ class WebService : public Service {
|
||||
|
||||
public:
|
||||
|
||||
WebService();
|
||||
WebService(DashboardState& state);
|
||||
|
||||
void begin() override;
|
||||
void update() override;
|
||||
@@ -16,4 +17,5 @@ public:
|
||||
private:
|
||||
|
||||
WebServer server;
|
||||
DashboardState dashboardState;
|
||||
};
|
||||
|
||||
@@ -47,14 +47,16 @@ void SystemTask::run()
|
||||
{
|
||||
serviceManager.begin();
|
||||
|
||||
|
||||
TickType_t lastWakeTime =
|
||||
xTaskGetTickCount();
|
||||
|
||||
|
||||
while(true)
|
||||
{
|
||||
serviceManager.update();
|
||||
// Time the length of the task:
|
||||
uint32_t start = micros();
|
||||
serviceManager.tick();
|
||||
uint32_t elapsed = micros() - start;
|
||||
|
||||
|
||||
vTaskDelayUntil(
|
||||
|
||||
Reference in New Issue
Block a user