Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/Display_Graphic_Diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class DisplayGraphicDiagramClass {

void updatePeriod();

const std::array<float, MAX_DATAPOINTS>& getGraphValues() const;
uint8_t getGraphValuesCount() const;
uint32_t getSecondsPerDot() const;

private:
void averageLoop();
void dataPointLoop();

uint32_t getSecondsPerDot();

Task _averageTask;
Task _dataPointTask;

Expand Down
2 changes: 2 additions & 0 deletions include/WebApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "WebApi_device.h"
#include "WebApi_devinfo.h"
#include "WebApi_display.h"
#include "WebApi_dtu.h"
#include "WebApi_errors.h"
#include "WebApi_eventlog.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ class WebApiClass {

WebApiDeviceClass _webApiDevice;
WebApiDevInfoClass _webApiDevInfo;
WebApiDisplayClass _webApiDisplay;
WebApiDtuClass _webApiDtu;
WebApiEventlogClass _webApiEventlog;
WebApiFileClass _webApiFile;
Expand Down
13 changes: 13 additions & 0 deletions include/WebApi_display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <ESPAsyncWebServer.h>
#include <TaskSchedulerDeclarations.h>

class WebApiDisplayClass {
public:
void init(AsyncWebServer& server, Scheduler& scheduler);

private:
void onDisplayHistory(AsyncWebServerRequest* request);
};
12 changes: 11 additions & 1 deletion src/Display_Graphic_Diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ void DisplayGraphicDiagramClass::dataPointLoop()
}
}

uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
const std::array<float, MAX_DATAPOINTS>& DisplayGraphicDiagramClass::getGraphValues() const
{
return _graphValues;
}

uint8_t DisplayGraphicDiagramClass::getGraphValuesCount() const
{
return _graphValuesCount;
}

uint32_t DisplayGraphicDiagramClass::getSecondsPerDot() const
{
return Configuration.get().Display.Diagram.Duration / _chartWidth;
}
Expand Down
1 change: 1 addition & 0 deletions src/WebApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void WebApiClass::init(Scheduler& scheduler)
{
_webApiDevice.init(_server, scheduler);
_webApiDevInfo.init(_server, scheduler);
_webApiDisplay.init(_server, scheduler);
_webApiDtu.init(_server, scheduler);
_webApiEventlog.init(_server, scheduler);
_webApiFile.init(_server, scheduler);
Expand Down
37 changes: 37 additions & 0 deletions src/WebApi_display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022-2026 Thomas Basler and others
*/
#include "WebApi_display.h"
#include "Display_Graphic.h"
#include "WebApi.h"
#include <AsyncJson.h>

void WebApiDisplayClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
using std::placeholders::_1;

server.on("/api/display/history", HTTP_GET, static_cast<ArRequestHandlerFunction>(std::bind(&WebApiDisplayClass::onDisplayHistory, this, _1)));
}

void WebApiDisplayClass::onDisplayHistory(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
auto& root = response->getRoot();

JsonArray values = root["values"].to<JsonArray>();
const auto& graphValues = Display.Diagram().getGraphValues();
const uint8_t graphValuesCount = Display.Diagram().getGraphValuesCount();
for (uint8_t i = 0; i < graphValuesCount; i++) {
values.add(graphValues[i]);
}

root["values_count"] = graphValuesCount;
root["seconds_per_dot"] = Display.Diagram().getSecondsPerDot();

WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}