Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chart scroll and 4x performance #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
77 changes: 43 additions & 34 deletions FSBrowser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -198,43 +198,33 @@ void handleFileList() {

static void sendCommand(String cmd)
{
Serial.print("\n");
delay(1);
while(Serial.available())
Serial.read(); //flush all previous output
Serial.print(cmd);
Serial.print("\n");
Serial.readStringUntil('\n'); //consume echo

char c;
uint32_t timeout = millis();
do {
if(Serial.available() > 0)
c = Serial.read();
} while (millis() - timeout < 256 && c != '\n');
}

static void handleCommand() {
const int cmdBufSize = 128;
if(!server.hasArg("cmd")) {server.send(500, "text/plain", "BAD ARGS"); return;}

String cmd = server.arg("cmd").substring(0, cmdBufSize);
//const int cmdBufSize = 128;
//String cmd = server.arg("cmd").substring(0, cmdBufSize);

sendCommand(server.arg("cmd"));

int repeat = 0;
char buffer[255];
size_t len = 0;
String output;

if (server.hasArg("repeat"))
repeat = server.arg("repeat").toInt();

if (!fastUart && fastUartAvailable)
{
sendCommand("fastuart");
if (Serial.readString().startsWith("OK"))
{
Serial.begin(921600);
fastUart = true;
}
else
{
fastUartAvailable = false;
}
}

sendCommand(cmd);

do {
memset(buffer,0,sizeof(buffer));
len = Serial.readBytes(buffer, sizeof(buffer) - 1);
Expand All @@ -247,8 +237,8 @@ static void handleCommand() {
Serial.readBytes(buffer, 1); //consume "!"
}
} while (len > 0);
server.sendHeader("Access-Control-Allow-Origin","*");
server.send(200, "text/json", output);
//server.sendHeader("Access-Control-Allow-Origin","*");
server.send(200, "text/plain", output);
}

static uint32_t crc32_word(uint32_t Crc, uint32_t Data)
Expand Down Expand Up @@ -291,14 +281,19 @@ static void handleUpdate()
if (step == -1)
{
int c;
sendCommand("reset");
char b[128];

Serial.print("reset\n");
Serial.readBytesUntil('t', b, sizeof(b) - 1); //echo -> reset

if (fastUart)
{
Serial.begin(115200);
fastUart = false;
fastUartAvailable = true; //retry after reboot
}
Serial.setTimeout(1000); //default

do {
c = Serial.read();
} while (c != 'S' && c != '2');
Expand Down Expand Up @@ -394,6 +389,10 @@ static void handleWifi()

static void handleBaud()
{
if (server.hasArg("timeout")) {
Serial.setTimeout(server.arg("timeout").toInt());
}

if (fastUart)
server.send(200, "text/html", "fastUart on");
else
Expand All @@ -412,6 +411,24 @@ void setup(void){
Serial.setTimeout(100);
SPIFFS.begin();

Serial.print("\n");
while(Serial.available())
Serial.read(); //flush all previous output

if (!fastUart && fastUartAvailable)
{
sendCommand("fastuart");
if (Serial.readString().startsWith("OK"))
{
Serial.begin(921600);
fastUart = true;
}
else
{
fastUartAvailable = false;
}
}

//WIFI INIT
#ifdef WIFI_IS_OFF_AT_BOOT
enableWiFiAtBootTime();
Expand Down Expand Up @@ -587,8 +604,6 @@ void setup(void){
swd.debugHaltOnReset(0);
swd.debugReset();

server.sendContent(""); //end stream

} else {
server.send(200, "text/plain", "SWD Error");
}
Expand All @@ -603,7 +618,6 @@ void setup(void){
} else if (server.hasArg("flash")) {
addr = 0x08001000;
addrEnd = 0x0801ffff;
//addrEnd = 0x080011ff; //Quick Debug
} else if (server.hasArg("ram")) {
addr = 0x20000000;
addrEnd = 0x200003ff; //Note: Read is limited to 0x200003ff but you can write to higher portion of RAM
Expand All @@ -624,8 +638,6 @@ void setup(void){
addrNext += (addrCount * 4); //step = count * 4 bytes in int32 word
} while (addrNext <= addrEnd);

server.sendContent(""); //end stream

} else {
server.send(200, "text/plain", "SWD Error");
}
Expand Down Expand Up @@ -665,8 +677,6 @@ void setup(void){
addrNext++;
} while (addrNext <= addrEnd);

server.sendContent(""); //end stream

} else {
server.send(200, "text/plain", "SWD Error");
}
Expand Down Expand Up @@ -755,7 +765,6 @@ void setup(void){
fs.close();
SPIFFS.remove("/" + filename);

server.sendContent(""); //end stream
digitalWrite(LED_BUILTIN, HIGH); //OFF
} else {
server.send(200, "text/plain", "File Error");
Expand Down
Binary file modified gauge.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion gauges.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<title>Huebner Inverter Management Console</title>
<title>Open Inverter Management Console</title>
<script type="text/javascript">
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
Expand Down
19 changes: 15 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Huebner Inverter Management Console</title>
<title>Open Inverter Management Console</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="chart.min.js" type="text/javascript"></script>
<script src="inverter.js" type="text/javascript"></script>
Expand Down Expand Up @@ -53,7 +53,7 @@ <h2 id="commands">Commands</h2>
<h2 id="update">UART Update</h2>
<p>Use binary files (stm32_sine/foc.bin) for updating inverter firmware. Upload any other file for updating this web interface.</p>
<form id="uploadform" enctype="multipart/form-data" action="edit" method="POST">
<input id="updatefile" name="updatefile" type="file" onchange="fileSelected();" />
<input id="updatefile" name="updatefile" type="file" />
<input type="button" onclick="uploadFile();" value="Upload" />
</form>
<div id="progress" class="graph">
Expand All @@ -63,7 +63,7 @@ <h2 id="update">UART Update</h2>
<h2 id="swdupdate">SWD Update</h2>
<p>Use binary files (stm32_loader.bin, stm32_sine/foc.bin) for updating inverter bootloader/firmware.</p>
<form id="swdform" enctype="multipart/form-data" action="edit" method="POST">
<input id="swdfile" name="swdfile" type="file" onchange="fileSelected();" accept=".bin" />
<input id="swdfile" name="swdfile" type="file" accept=".bin" />
<input type="button" onclick="uploadSWDFile();" value="Upload" />
</form>
<div id="progress" class="graph">
Expand Down Expand Up @@ -133,13 +133,24 @@ <h2 id="spot">Spot Values</h2>
</tbody>
</table>
<h2 id="plot">Plot</h2>
<canvas id="canvas" width=100 height=40></canvas>
<div class="chartWrapper">
<div class="chartAreaWrapper" id="chartAreaWrapper">
<div class="chartArea" id="chartArea">
<canvas id="canvas"></canvas>
</div>
</div>
<canvas id="chartAxis" height="640" width="0"></canvas>
</div>
<p>
<button onclick="startPlot()">Start Plot</button>
<button onclick="stopPlot()">Stop Plot</button>
<button onclick="pauseResumePlot()" disabled id="pauseButton">Pause Plot</button>
<button onclick="exportChartImage()" id="exportButton">Export Image</button>
Scroll pages: <input type="number" id="maxPages" step="1" min="1" max="10" value="2" />
Limit data points to: <input type="number" id="maxValues" step="1" min="10" max="10000" value="1000" />
Burst length: <input type="number" id="burstLength" step="1" min="1" max="1000" value="10" />
Chart delay (ms): <input type="number" id="chartDelay" step="1" min="0" max="1000" value="100" onchange="serialTimeout(this.value)" />
Auto scroll: <input type="checkbox" id="autoScroll" checked />
<p>Copyright 2018 Johannes Huebner dev@johanneshuebner.com</p>
<p>Charting by <a href="http://chartjs.org/" target="_blank">chart.js</a></p>
<p>Gauges by <a href="https://github.com/Mikhus/canvas-gauges" target="_blank">Mykhailo Stadnyk</a></p>
Expand Down
Loading