Skip to content

Commit

Permalink
charts test code
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Sep 5, 2024
1 parent d491a71 commit b206f94
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/driver/drv_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void DGR_SpoofNextDGRPacketSource(const char* ipStrs);
void TuyaMCU_Sensor_RunEverySecond();
void TuyaMCU_Sensor_Init();

void DRV_Test_Charts_AddToHtmlPage(http_request_t *request);

void DRV_Toggler_ProcessChanges(http_request_t* request);
void DRV_Toggler_AddToHtmlPage(http_request_t* request);
Expand Down
12 changes: 11 additions & 1 deletion src/driver/drv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ static driver_t g_drivers[] = {
//drvdetail:"requires":""}
{ "HGS02", HGS02_Init, HGS02_RunEverySecond, NULL, NULL, NULL, NULL, false },
#endif

#if WINDOWS
//drvdetail:{"name":"TestCharts",
//drvdetail:"title":"TODO",
//drvdetail:"descr":".",
//drvdetail:"requires":""}
{ "TestCharts", NULL, NULL, DRV_Test_Charts_AddToHtmlPage, NULL, NULL, NULL, false },
#endif
#if ENABLE_NTP
//drvdetail:{"name":"NTP",
//drvdetail:"title":"TODO",
Expand Down Expand Up @@ -532,7 +540,9 @@ void DRV_StartDriver(const char* name) {

}
else {
g_drivers[i].initFunc();
if (g_drivers[i].initFunc) {
g_drivers[i].initFunc();
}
g_drivers[i].bLoaded = true;
addLogAdv(LOG_INFO, LOG_FEATURE_MAIN, "Started %s.\n", name);
bStarted = 1;
Expand Down
48 changes: 48 additions & 0 deletions src/driver/drv_test_charts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "../new_common.h"
#include "../new_pins.h"
#include "../new_cfg.h"
// Commands register, execution API and cmd tokenizer
#include "../cmnds/cmd_public.h"
#include "../mqtt/new_mqtt.h"
#include "../logging/logging.h"
#include "../hal/hal_pins.h"
#include "../httpserver/new_http.h"

// startDriver TestCharts
void DRV_Test_Charts_AddToHtmlPage(http_request_t *request) {
poststr(request, "<canvas id=\"myChart\" width=\"400\" height=\"200\"></canvas>");
poststr(request, "<script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>");

poststr(request, "<script>");
poststr(request, "function cha() {");
poststr(request, "console.log('qq');");
poststr(request, "if (window.myChartInstance) {");
poststr(request, " window.myChartInstance.destroy();");
poststr(request, "}");
poststr(request, "var ctx = document.getElementById('myChart').getContext('2d');");
poststr(request, "window.myChartInstance = new Chart(ctx, {");
poststr(request, " type: 'line',");
poststr(request, " data: {");
poststr(request, " labels: ['0s', '5s', '10s', '15s', '20s', '25s'],");
poststr(request, " datasets: [{");
poststr(request, " label: 'Temperature',");
poststr(request, " data: [22, 23, 21, 24, 25, 26],");
poststr(request, " borderColor: 'rgba(75, 192, 192, 1)',");
poststr(request, " fill: false");
poststr(request, " }]");
poststr(request, " },");
poststr(request, " options: {");
poststr(request, " scales: {");
poststr(request, " y: {");
poststr(request, " beginAtZero: false");
poststr(request, " }");
poststr(request, " }");
poststr(request, " }");
poststr(request, "});");
poststr(request, "}");
poststr(request, "</script>");
poststr(request, "<style onload='cha();'></style>");
}



0 comments on commit b206f94

Please sign in to comment.