diff --git a/data/js/controls.js b/data/js/controls.js index 84b001b..da9303c 100644 --- a/data/js/controls.js +++ b/data/js/controls.js @@ -60,7 +60,10 @@ const UPDATE_SEPARATOR = 119; const UI_TIME = 20; const UPDATE_TIME = 120; -const UI_FRAGMENT = 21; +const UI_FILEDISPLAY = 21; +const UPDATE_FILEDISPLAY = 121; + +const UI_FRAGMENT = 98; const UP = 0; const DOWN = 1; @@ -80,7 +83,7 @@ const C_DARK = 7; const C_NONE = 255; var controlAssemblyArray = new Object(); -var FragmentAssemblyTimer = new Object(); +var FragmentAssemblyTimer = new Array(); var graphData = new Array(); var hasAccel = false; var sliderContinuous = false; @@ -197,8 +200,8 @@ function conStatusError() { FragmentAssemblyTimer.forEach(element => { clearInterval(element); }); - FragmentAssemblyTimer = new Object(); - controlAssemblyArray = new Object(); + FragmentAssemblyTimer = new Array(); + controlAssemblyArray = new Array(); if (true === websockConnected) { websockConnected = false; @@ -220,10 +223,10 @@ function handleVisibilityChange() { } function start() { - let location = window.location.hostname; - let port = window.location.port; -// let location = "192.168.10.229"; -// let port = ""; +// let location = window.location.hostname; +// let port = window.location.port; + let location = "192.168.10.219"; + let port = ""; document.addEventListener("visibilitychange", handleVisibilityChange, false); if ( @@ -257,8 +260,8 @@ function start() { FragmentAssemblyTimer.forEach(element => { clearInterval(element); }); - FragmentAssemblyTimer = new Object(); - controlAssemblyArray = new Object(); + FragmentAssemblyTimer = new Array(); + controlAssemblyArray = new Array(); }; websock.onclose = function (evt) { @@ -270,8 +273,8 @@ function start() { FragmentAssemblyTimer.forEach(element => { clearInterval(element); }); - FragmentAssemblyTimer = new Object(); - controlAssemblyArray = new Object(); + FragmentAssemblyTimer = new Array(); + controlAssemblyArray = new Array(); }; websock.onerror = function (evt) { @@ -283,8 +286,8 @@ function start() { FragmentAssemblyTimer.forEach(element => { clearInterval(element); }); - FragmentAssemblyTimer = new Object(); - controlAssemblyArray = new Object(); + FragmentAssemblyTimer = new Array(); + controlAssemblyArray = new Array(); }; var handleEvent = function (evt) { @@ -367,7 +370,7 @@ function start() { if (data.visible) addToHTML(data); break; - /* + /* These elements must call additional functions after being added to the DOM */ case UI_BUTTON: @@ -565,6 +568,14 @@ function start() { } break; + case UI_FILEDISPLAY: + if (data.visible) + { + addToHTML(data); + FileDisplayUploadFile(data); + } + break; + /* * Update messages change the value/style of a component without adding new HTML */ @@ -639,6 +650,10 @@ function start() { websock.send("time:" + rv + ":" + data.id); break; + case UPDATE_FILEDISPLAY: + FileDisplayUploadFile(data); + break; + case UI_FRAGMENT: let FragmentLen = data.length; let FragementOffset = data.offset; @@ -770,6 +785,25 @@ function start() { websock.onmessage = handleEvent; } +function FileDisplayUploadFile(data) +{ + let text = downloadFile(data.value); + // populate the text object +} // FileDisplayUploadFile + +async function downloadFile(filename) { + let response = await fetch(filename); + + if(response.status != 200) { + throw new Error("File Read Server Error: '" + response.status + "'"); + } + + // read response stream as text + let text_data = await response.text(); + + return text_data; +} // downloadFile + function StartFragmentAssemblyTimer(Id) { StopFragmentAssemblyTimer(Id); @@ -930,6 +964,7 @@ var addToHTML = function (data) { case UI_GRAPH: case UI_GAUGE: case UI_ACCEL: + case UI_FILEDISPLAY: html = "
If site does not re-direct click here this link
"); + responseText += (""); + response->write(responseText.c_str(), responseText.length()); + request->send(response); request->redirect("/"); } else diff --git a/src/ESPUI.h b/src/ESPUI.h index 23d65ad..ceb4748 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -143,6 +143,7 @@ public: uint16_t gauge(const char* label, ControlColor color, int value, int min = 0, int max = 100); // Create Gauge display uint16_t separator(const char* label); //Create separator + uint16_t fileDisplay(const char* label, ControlColor color, String filename); // Input only uint16_t accelerometer(const char* label, std::function