Web server now using SPIFFS - must use Partition: Minimal SPIFFS
This commit is contained in:
parent
f48ec8d314
commit
4b1d941b7f
10 changed files with 797 additions and 4 deletions
|
@ -103,6 +103,9 @@
|
|||
#include "src/OLED/keypad.h"
|
||||
#include <DallasTemperature.h>
|
||||
#include "src/RTC/Clock.h"
|
||||
#if USE_SPIFFS == 1
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#define FAILEDSSID "BTCESP32"
|
||||
#define FAILEDPASSWORD "thereisnospoon"
|
||||
|
@ -266,6 +269,16 @@ void setup() {
|
|||
sprintf(msg, " Temperature for device#1 (idx 0) is: %.1f", TempSensor.getTempCByIndex(0));
|
||||
DebugPort.println(msg);
|
||||
|
||||
#if USE_SPIFFS == 1
|
||||
// Initialize SPIFFS
|
||||
if(!SPIFFS.begin(true)){
|
||||
DebugPort.println("An Error has occurred while mounting SPIFFS");
|
||||
}
|
||||
else {
|
||||
DebugPort.println("Mounted SPIFFS OK");
|
||||
}
|
||||
#endif
|
||||
|
||||
// locate devices on the bus
|
||||
DebugPort.print(" Locating DS18B20 devices...");
|
||||
|
||||
|
@ -316,7 +329,7 @@ void setup() {
|
|||
|
||||
initWifi(WiFi_TriggerPin, FAILEDSSID, FAILEDPASSWORD);
|
||||
#if USE_OTA == 1
|
||||
// initOTA();
|
||||
initOTA();
|
||||
#endif // USE_OTA
|
||||
#if USE_WEBSERVER == 1
|
||||
initWebServer();
|
||||
|
|
BIN
Arduino/BTCDieselHeater/data/favicon.ico
Normal file
BIN
Arduino/BTCDieselHeater/data/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
502
Arduino/BTCDieselHeater/data/index.html
Normal file
502
Arduino/BTCDieselHeater/data/index.html
Normal file
|
@ -0,0 +1,502 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon" />
|
||||
<title>Chinese Diesel Heater Web Controller Interface</title>
|
||||
|
||||
<script>
|
||||
|
||||
var Socket;
|
||||
function init() {
|
||||
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
|
||||
Socket.onmessage = function(event){
|
||||
var heater = JSON.parse(event.data);
|
||||
var key;
|
||||
for(key in heater) {
|
||||
console.log("JSON decode:", key, heater[key]);
|
||||
switch(key) {
|
||||
case "RunState":
|
||||
if (heater[key] == 0) {
|
||||
document.getElementById("myonoffswitch").checked = false;
|
||||
document.getElementById("myonoffswitch").style = "block";
|
||||
document.getElementById("onoffswitch").style.visibility = "visible";
|
||||
} else if(heater[key] >= 7) {
|
||||
document.getElementById("myonoffswitch").checked = false;
|
||||
document.getElementById("myonoffswitch").style = "none";
|
||||
document.getElementById("onoffswitch").style.visibility = "hidden";
|
||||
} else {
|
||||
document.getElementById("myonoffswitch").checked = true;
|
||||
document.getElementById("myonoffswitch").style = "block";
|
||||
document.getElementById("onoffswitch").style.visibility = "visible";
|
||||
}
|
||||
document.getElementById("RunString").style.visibility = (heater[key] == 5 || heater[key] == 0) ? "hidden" : "visible";
|
||||
break;
|
||||
case "ErrorString":
|
||||
case "PumpFixed":
|
||||
case "RunString":
|
||||
case "TempCurrent":
|
||||
document.getElementById(key).innerHTML = heater[key];
|
||||
break;
|
||||
case "TempDesired":
|
||||
document.getElementById("slide").value = heater[key];
|
||||
document.getElementById(key).innerHTML = heater[key];
|
||||
break;
|
||||
case "ErrorState":
|
||||
document.getElementById("ErrorDiv").hidden = heater[key] <= 1;
|
||||
break;
|
||||
case "TempBody":
|
||||
//The threshold levels for each bar to come on are: 21°C, 41°C, 61°C, 81°C, 101°C, 121°C
|
||||
if(heater[key] > 120){
|
||||
document.getElementById("TopBar").className = "active121";
|
||||
}
|
||||
else if(heater[key] > 100){
|
||||
document.getElementById("TopBar").className = "active101";
|
||||
}
|
||||
else if(heater[key] > 80){
|
||||
document.getElementById("TopBar").className = "active81";
|
||||
}
|
||||
else if(heater[key] > 60){
|
||||
document.getElementById("TopBar").className = "active61";
|
||||
}
|
||||
else if(heater[key] > 40){
|
||||
document.getElementById("TopBar").className = "active41";
|
||||
}
|
||||
else if(heater[key] > 20){
|
||||
document.getElementById("TopBar").className = "active21";
|
||||
}
|
||||
else {
|
||||
document.getElementById("TopBar").className = "active0";
|
||||
}
|
||||
break;
|
||||
case "Thermostat":
|
||||
if(heater[key] != 0) {
|
||||
document.getElementById("FixedDiv").hidden = true;
|
||||
document.getElementById("ThermoDiv").hidden = false;
|
||||
}
|
||||
else {
|
||||
document.getElementById("FixedDiv").hidden = false;
|
||||
document.getElementById("ThermoDiv").hidden = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setSchedule(){
|
||||
//clearly need to add some code here to send the Json formatted data to the esp
|
||||
console.log("Set Schedule Button Press")
|
||||
}
|
||||
|
||||
Date.prototype.toDateInputValue = (function() {
|
||||
var local = new Date(this);
|
||||
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
|
||||
return local.toJSON().slice(0,10);
|
||||
});
|
||||
|
||||
function sendJSONobject(obj){
|
||||
var str = JSON.stringify(obj);
|
||||
console.log("JSON Tx:", str);
|
||||
Socket.send(str);
|
||||
}
|
||||
|
||||
// Scripts for date handling
|
||||
Date.prototype.today = function () {
|
||||
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
|
||||
}
|
||||
|
||||
// Scripts for setting date and time
|
||||
|
||||
function setcurrenttime(){
|
||||
var cmd = {};
|
||||
cmd.Time = document.getElementById("curtime").value;
|
||||
sendJSONobject(cmd);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function setcurrentdate(){
|
||||
var cmd = {};
|
||||
cmd.Date = document.getElementById("curdate").value;
|
||||
sendJSONobject(cmd);
|
||||
|
||||
}
|
||||
|
||||
function funcNavLinks() {
|
||||
var x = document.getElementById("myLinks");
|
||||
if (x.style.display === "block") {
|
||||
x.style.display = "none";
|
||||
} else {
|
||||
x.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
function checkTime(i)
|
||||
{
|
||||
if (i<10)
|
||||
{
|
||||
i="0" + i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function funcdispSettings() {
|
||||
document.getElementById("Settings").style.display = "block";
|
||||
currentTime = new Date();
|
||||
var h = currentTime.getHours();
|
||||
var m = currentTime.getMinutes();
|
||||
var s = currentTime.getSeconds();
|
||||
// add a zero in front of numbers<10
|
||||
h = checkTime(h);
|
||||
m = checkTime(m);
|
||||
s = checkTime(s);
|
||||
|
||||
console.log("Hours",h);
|
||||
console.log("Minutes",m);
|
||||
console.log("Seconds",s);
|
||||
document.getElementById("curtime").value = h + ":" + m + ":" + s;
|
||||
document.getElementById("curdate").value = currentTime.today()
|
||||
document.getElementById("Home").style.display = "none";
|
||||
document.getElementById("Advanced").style.display = "none";
|
||||
document.getElementById("myLinks").style.display ="none";
|
||||
document.getElementById('curdate').valueAsDate = new Date();
|
||||
|
||||
|
||||
}
|
||||
|
||||
function funcdispHome(){
|
||||
document.getElementById("Settings").style.display = "none";
|
||||
document.getElementById("Home").style.display = "block";
|
||||
document.getElementById("Advanced").style.display = "none";
|
||||
document.getElementById("myLinks").style.display ="none";
|
||||
|
||||
}
|
||||
|
||||
function funcdispAdvanced(){
|
||||
document.getElementById("Settings").style.display = "none";
|
||||
document.getElementById("Home").style.display = "none";
|
||||
document.getElementById("Advanced").style.display = "block";
|
||||
document.getElementById("myLinks").style.display ="none";
|
||||
|
||||
}
|
||||
|
||||
// Function to check the power on/off slide switch.
|
||||
function OnOffCheck(){
|
||||
|
||||
// Get the checkbox status and place in the checkbox variable
|
||||
var checkBox = document.getElementById("myonoffswitch");
|
||||
|
||||
// Send a message to the Devel console of web browser for debugging
|
||||
console.log("OnOffCheck:", document.getElementById("myonoffswitch").checked);
|
||||
|
||||
// If the checkbox is checked, display the output text
|
||||
// We also need to send a message back into the esp as we cannot directly run Arduino Functions from within the javascript
|
||||
|
||||
var cmd = {};
|
||||
if (checkBox.checked){
|
||||
//Insert Code Here To Turn On The Heater
|
||||
console.log("Turning On Heater");
|
||||
|
||||
cmd.RunState = 1;
|
||||
sendJSONobject(cmd);
|
||||
}
|
||||
else{
|
||||
//Insert Code Here To Turn Off The Heater
|
||||
console.log("Turning Off Heater");
|
||||
|
||||
cmd.RunState = 0;
|
||||
sendJSONobject(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
function onSlide(newVal, JSONKey) {
|
||||
//elementid must equal the JSON name for each setting
|
||||
|
||||
document.getElementById(JSONKey).innerHTML = newVal;
|
||||
|
||||
var cmd = {};
|
||||
cmd[JSONKey] = newVal; // note: variable name needs []
|
||||
cmd.NVsave = 8861; // named variable DOESN'T !!
|
||||
sendJSONobject(cmd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1">
|
||||
<style>
|
||||
|
||||
.throb_me {
|
||||
animation: throbber 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes throbber {
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.onoffswitch {
|
||||
position: relative; width: 90px;
|
||||
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
|
||||
}
|
||||
.onoffswitch-checkbox {
|
||||
display: none;
|
||||
}
|
||||
.onoffswitch-label {
|
||||
display: block; overflow: hidden; cursor: pointer;
|
||||
border: 2px solid #999999; border-radius: 20px;
|
||||
}
|
||||
.onoffswitch-inner {
|
||||
display: block; width: 200%; margin-left: -100%;
|
||||
transition: margin 0.3s ease-in 0s;
|
||||
}
|
||||
.onoffswitch-inner:before, .onoffswitch-inner:after {
|
||||
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
|
||||
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.onoffswitch-inner:before {
|
||||
content: "ON";
|
||||
padding-left: 10px;
|
||||
background-color: #34A7C1; color: #FFFFFF;
|
||||
}
|
||||
.onoffswitch-inner:after {
|
||||
content: "OFF";
|
||||
padding-right: 10px;
|
||||
background-color: #EEEEEE; color: #999999;
|
||||
text-align: right;
|
||||
}
|
||||
.onoffswitch-switch {
|
||||
display: block; width: 18px; margin: 6px;
|
||||
background: #FFFFFF;
|
||||
position: absolute; top: 0; bottom: 0;
|
||||
right: 56px;
|
||||
border: 2px solid #999999; border-radius: 20px;
|
||||
transition: all 0.3s ease-in 0s;
|
||||
}
|
||||
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
|
||||
margin-left: 0;
|
||||
}
|
||||
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
.mobile-container {
|
||||
|
||||
margin: auto;
|
||||
background-color: #555;
|
||||
height: 500px;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.topnav {
|
||||
overflow: hidden;
|
||||
background-color: #333;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.topnav #myLinks {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.topnav a {
|
||||
color: white;
|
||||
padding: 14px 16px;
|
||||
text-decoration: none;
|
||||
font-size: 17px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.topnav a.icon {
|
||||
background: black;
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.topnav a:hover {
|
||||
background-color: #ddd;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.active0 {
|
||||
background-color: #5e4fa2;
|
||||
color: black;
|
||||
}
|
||||
.active21 {
|
||||
background-color: #427bb1;
|
||||
color: #ffffff;
|
||||
}
|
||||
.active41 {
|
||||
background-color: #36c0a3;
|
||||
color: #ffffff;
|
||||
}
|
||||
.active61 {
|
||||
background-color: #29cf38;
|
||||
color: #000000;
|
||||
}
|
||||
.active81 {
|
||||
background-color: #92df1b;
|
||||
color: #ffffff;
|
||||
}
|
||||
.active101 {
|
||||
background-color: #efab0e;
|
||||
color: #ffffff;
|
||||
}
|
||||
.active121 {
|
||||
background-color: #ff0000;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #2196F3;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(26px);
|
||||
-ms-transform: translateX(26px);
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
||||
.slider.round {
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider.round:before {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
MainPage {
|
||||
display: block
|
||||
}
|
||||
#Advanced {
|
||||
display: none
|
||||
}
|
||||
#Settings {
|
||||
display: none
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="javascript:init()">
|
||||
<div class="mobile-container">
|
||||
|
||||
<!-- Top Navigation Menu -->
|
||||
<div class="topnav">
|
||||
<div id="TopBar" style="padding-left:30px"><a href="javascript:void(0);" onclick="funcdispHome()" >Chinese Diesel Heater Web Control</a></div>
|
||||
<div id="myLinks">
|
||||
<a href="javascript:void(0);" onclick="funcdispHome()">Home</a>
|
||||
<a href="javascript:void(0);" onclick="funcdispSettings()">Settings</a>
|
||||
<a href="javascript:void(0);" onclick="funcdispAdvanced()">Advanced Settings</a>
|
||||
</div>
|
||||
<a href="javascript:void(0);" class="icon" onclick="funcNavLinks()">=</a>
|
||||
</div>
|
||||
<div style="padding-left:16px">
|
||||
<span class="MaingPage" id="Home">
|
||||
<div><H2>Power Control</H2></div>
|
||||
|
||||
<div class="onoffswitch" id="onoffswitch">
|
||||
<input type="checkbox" onclick="OnOffCheck()" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" clicked>
|
||||
<label class="onoffswitch-label" for="myonoffswitch">
|
||||
<span class="onoffswitch-inner"></span>
|
||||
<span class="onoffswitch-switch"></span>
|
||||
</label>
|
||||
</div>
|
||||
<span class="throb_me" id="RunString" style="visibility:hidden"></span>
|
||||
|
||||
<div>
|
||||
<h2>Temperature Control</h2>
|
||||
</div>
|
||||
<input type="range" id="slide" min="8" max="35" step="1" value="22" oninput="onSlide(this.value, 'TempDesired')" onchange="onSlide(this.value, 'TempDesired')">
|
||||
<div id="ThermoDiv">
|
||||
<b>Desired Temp: </b>
|
||||
<span id="TempDesired"></span>
|
||||
</div>
|
||||
<div id="FixedDiv">
|
||||
<b>Fixed Hz: </b>
|
||||
<span id="PumpFixed"></span>
|
||||
</div>
|
||||
<div>
|
||||
<b>Current Temp: </b><span id="TempCurrent"></span>
|
||||
</div>
|
||||
<div id="ErrorDiv" style="color:crimson" hidden>
|
||||
<b>Error <span id="ErrorString"></span> </b>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="Advanced">
|
||||
Advanced Settings
|
||||
<b>Pump Min</b>
|
||||
<input type="range" id="PumpMinSlide" min=".5" max="35" step=".5" value="22" oninput="onSlide(this.value, 'PumpMin')" onchange="onSlide(this.value, 'PumpMin')"> <span id="PumpMin"></span>
|
||||
<div>
|
||||
<b>Pump Max</b>
|
||||
<input type="range" id="PumpMaxSlide" min=".5" max="5" step=".5" value="22" oninput="onSlide(this.value, 'PumpMax')" onchange="onSlide(this.value, 'PumpMax')"> <span id="PumpMax"></span>
|
||||
</div>
|
||||
<div>
|
||||
<b>Fan Min</b>
|
||||
<input type="range" id="FanMinSlide" min="1000" max="5000" step="50" value="22" oninput="onSlide(this.value, 'FanMin')" onchange="onSlide(this.value, 'FanMin')"> <span id="FanMin"></span>
|
||||
</div>
|
||||
<div>
|
||||
<b>Fan Max</b>
|
||||
<input type="range" id="FanMaxSlide" min="1000" max="5000" step="50" value="22" oninput="onSlide(this.value, 'FanMax')" onchange="onSlide(this.value, 'FanMax')"> <span id="FanMax"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<Div id="Settings">
|
||||
Current Date:<br>
|
||||
<input type="date" id="curdate"><input type="button" Value="Set Date" onclick="setcurrentdate()">
|
||||
|
||||
<br>
|
||||
Current Time (24 Hour Format):<br>
|
||||
<input type="time" id="curtime"> <input type="button" Value="Set Time" onclick="setcurrenttime()">
|
||||
|
||||
<hr>
|
||||
<br><br>
|
||||
Timer1: <input type="checkbox" border-radius="4px" name="Timer1" id="Timer1onoff"> <input type="text" class="schedule" id="Timer1Start"> <input type="text" id="Timer1End"> <br>
|
||||
Timer2: <input type="checkbox" border-radius="4px" name="Tue"> <input type="text" class="schedule" id="Timer2Start"> <input type="text" id="Timer2End"><br>
|
||||
<input type="button" Value="Save Schedule" onclick="setSchedule()">
|
||||
</Div>
|
||||
</body>
|
||||
</html>
|
|
@ -27,10 +27,8 @@
|
|||
#include "../cfg/BTCConfig.h"
|
||||
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// HC-05 BLUETOOTH with ESP32
|
||||
// |
|
||||
|
@ -60,7 +58,7 @@ CBluetoothESP32HC05::openSerial(int baudrate)
|
|||
|
||||
|
||||
|
||||
|
||||
#if USE_CLASSIC_BLUETOOTH == 1
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CLASSIC BLUETOOTH on ESP32
|
||||
// |
|
||||
|
@ -115,8 +113,10 @@ CBluetoothESP32Classic::isConnected()
|
|||
// |
|
||||
// CLASSIC BLUETOOTH on ESP32
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_BLE_BLUETOOTH == 1
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BLE on ESP32
|
||||
// |
|
||||
|
@ -327,6 +327,7 @@ CBluetoothESP32BLE::BLE_Send(std::string Data)
|
|||
// |
|
||||
// BLE on ESP32
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ bool
|
|||
CPasswordScreen::show()
|
||||
{
|
||||
CPasswordScreen::animate(); // precautionary, in case derived class forgets to call
|
||||
|
||||
if(_SaveTime) {
|
||||
_printInverted(_display.xCentre(), 28, " ", true, eCentreJustify);
|
||||
_printInverted(_display.xCentre(), 39, " ", true, eCentreJustify);
|
||||
|
|
165
Arduino/BTCDieselHeater/src/OLED/SettingsScreen.cpp
Normal file
165
Arduino/BTCDieselHeater/src/OLED/SettingsScreen.cpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* This file is part of the "bluetoothheater" distribution
|
||||
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
||||
*
|
||||
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CSettingsScreen
|
||||
//
|
||||
// This screen allows the fuel mixture endpoints to be adjusted
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SettingsScreen.h"
|
||||
#include "KeyPad.h"
|
||||
#include "../Protocol/helpers.h"
|
||||
#include "../Wifi/BTCWifi.h"
|
||||
|
||||
static const int Line3 = 20; // system voltage
|
||||
static const int Line2 = 30; // fan sensor
|
||||
static const int Line1 = 40; // plug drive
|
||||
static const int Column = 98;
|
||||
|
||||
static const int plugPowers[] = { 35, 40, 45, 80, 85, 90};
|
||||
|
||||
CSettingsScreen::CSettingsScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
||||
{
|
||||
_animateCount = 0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CSettingsScreen::show()
|
||||
{
|
||||
char str[16];
|
||||
|
||||
CScreenHeader::show();
|
||||
|
||||
_display.writeFillRect(0, 16, 96, 12, WHITE);
|
||||
_printInverted(3, 18, "Heater Settings", true);
|
||||
|
||||
if(!CPasswordScreen::show()) {
|
||||
|
||||
sprintf(str, "%.0fV", getHeaterInfo().getSystemVoltage());
|
||||
_printMenuText(_display.width(), Line3, str, false, eRightJustify);
|
||||
|
||||
sprintf(str, "Min: %.1f/%d", getHeaterInfo().getPump_Min(), getHeaterInfo().getFan_Min());
|
||||
_printMenuText(0, Line2, str);
|
||||
// sprintf(str, "SN-%d", getHeaterInfo().getFan_Sensor());
|
||||
// _printMenuText(_display.width(), yPos, str, false, eRightJustify);
|
||||
|
||||
sprintf(str, "Max: %.1f/%d", getHeaterInfo().getPump_Max(), getHeaterInfo().getFan_Max());
|
||||
_printMenuText(0, Line1, str);
|
||||
// sprintf(str, "PF-%d", getHeaterInfo().getGlow_Drive());
|
||||
// _printMenuText(_display.width(), yPos, str, false, eRightJustify);
|
||||
// navigation line
|
||||
int yPos = 53;
|
||||
int xPos = _display.xCentre();
|
||||
_printMenuText(xPos, yPos, "<- enter ->", true, eCentreJustify);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CSettingsScreen::animate()
|
||||
{
|
||||
char msg[16];
|
||||
|
||||
if(isPasswordBusy()) { // Password screen activity
|
||||
_printMenuText(Column, Line1, " ");
|
||||
_printMenuText(Column, Line2, " ");
|
||||
}
|
||||
else {
|
||||
_animateCount++;
|
||||
ROLLUPPERLIMIT(_animateCount, 9, 0);
|
||||
|
||||
int glowDrive = getHeaterInfo().getGlow_Drive();
|
||||
_printMenuText(Column, Line1, " ");
|
||||
if(_animateCount < 4) {
|
||||
sprintf(msg, "PF-%d", glowDrive);
|
||||
_printMenuText(Column+6, Line1, msg);
|
||||
}
|
||||
else {
|
||||
sprintf(msg, "(%dW)", plugPowers[glowDrive-1]);
|
||||
_printMenuText(Column, Line1, msg);
|
||||
}
|
||||
|
||||
int fanSensor = getHeaterInfo().getFan_Sensor();
|
||||
if(_animateCount < 4) {
|
||||
sprintf(msg, "SN-%d", fanSensor);
|
||||
_printMenuText(Column+6, Line2, msg);
|
||||
}
|
||||
else {
|
||||
int xPos = Column+6;
|
||||
_printMenuText(xPos, Line2, " "); // erase
|
||||
_printMenuText(xPos, Line2, "(");
|
||||
xPos += 6;
|
||||
// .
|
||||
// draw old fashioned divide symbol -----
|
||||
// .
|
||||
int barOfs = 3;
|
||||
_display.drawLine(xPos, Line2+barOfs, xPos+4, Line2+barOfs, WHITE);
|
||||
_display.drawPixel(xPos+2, Line2+barOfs-2, WHITE);
|
||||
_display.drawPixel(xPos+2, Line2+barOfs+2, WHITE);
|
||||
xPos += 6;
|
||||
sprintf(msg, "%d)", fanSensor);
|
||||
_printMenuText(xPos, Line2, msg);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CSettingsScreen::keyHandler(uint8_t event)
|
||||
{
|
||||
if(CPasswordScreen::keyHandler(event)) {
|
||||
if(_isPasswordOK()) {
|
||||
_ScreenManager.selectSettingsScreen(true);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
if(event & keyPressed) {
|
||||
// press LEFT
|
||||
if(event & key_Left) {
|
||||
_ScreenManager.prevScreen();
|
||||
}
|
||||
// press RIGHT
|
||||
if(event & key_Right) {
|
||||
_ScreenManager.nextScreen();
|
||||
}
|
||||
// press UP
|
||||
if(event & (key_Up | key_Centre)) {
|
||||
if(hasOEMcontroller())
|
||||
_reqOEMWarning();
|
||||
else {
|
||||
_getPassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ScreenManager.reqUpdate();
|
||||
return true;
|
||||
}
|
||||
|
40
Arduino/BTCDieselHeater/src/OLED/SettingsScreen.h
Normal file
40
Arduino/BTCDieselHeater/src/OLED/SettingsScreen.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the "bluetoothheater" distribution
|
||||
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
||||
*
|
||||
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SETTINGSSCREEN_H__
|
||||
#define __SETTINGSSCREEN_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "PasswordScreen.h"
|
||||
|
||||
class C128x64_OLED;
|
||||
class CScreenManager;
|
||||
|
||||
class CSettingsScreen : public CPasswordScreen {
|
||||
int _animateCount;
|
||||
public:
|
||||
CSettingsScreen(C128x64_OLED& display, CScreenManager& mgr);
|
||||
bool show();
|
||||
bool keyHandler(uint8_t event);
|
||||
bool animate();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -30,6 +30,9 @@
|
|||
#include "../Utility/BTC_JSON.h"
|
||||
#include "../Utility/Moderator.h"
|
||||
#include <WiFiManager.h>
|
||||
#if USE_SPIFFS == 1
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
extern WiFiManager wm;
|
||||
|
||||
|
@ -41,10 +44,60 @@ bool bTxWebData = false;
|
|||
|
||||
const int led = 13;
|
||||
|
||||
#if USE_SPIFFS == 1
|
||||
|
||||
String getContentType(String filename) { // convert the file extension to the MIME type
|
||||
if (filename.endsWith(".html")) return "text/html";
|
||||
else if (filename.endsWith(".css")) return "text/css";
|
||||
else if (filename.endsWith(".js")) return "application/javascript";
|
||||
else if (filename.endsWith(".ico")) return "image/x-icon";
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
bool handleFileRead(String path) { // send the right file to the client (if it exists)
|
||||
DebugPort.println("handleFileRead: " + path);
|
||||
if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file
|
||||
String contentType = getContentType(path); // Get the MIME type
|
||||
if (SPIFFS.exists(path)) { // If the file exists
|
||||
File file = SPIFFS.open(path, "r"); // Open it
|
||||
size_t sent = server.streamFile(file, contentType); // And send it to the client
|
||||
file.close(); // Then close the file again
|
||||
return true;
|
||||
}
|
||||
DebugPort.println("\tFile Not Found");
|
||||
return false; // If the file doesn't exist, return false
|
||||
}
|
||||
|
||||
void handleFavIcon() {
|
||||
handleFileRead("/favicon.ico");
|
||||
/* if(SPIFFS.exists("/favicon.ico")) {
|
||||
File favicon = SPIFFS.open("/favicon.ico");
|
||||
server.streamFile(favicon, "image/x-icon");
|
||||
favicon.close();
|
||||
}
|
||||
else {
|
||||
DebugPort.println("\"/favicon.ico\" does not exist!!!");
|
||||
}*/
|
||||
}
|
||||
|
||||
void handleBTCRoot() {
|
||||
handleFileRead("/index.html");
|
||||
/* if(SPIFFS.exists("/index.html")) {
|
||||
File html = SPIFFS.open("/index.html");
|
||||
server.streamFile(html, "text/html");
|
||||
html.close();
|
||||
}
|
||||
else {
|
||||
DebugPort.println("\"/index.html\" does not exist!!!");
|
||||
}*/
|
||||
}
|
||||
#else
|
||||
void handleBTCRoot() {
|
||||
String s = MAIN_PAGE; //Read HTML contents
|
||||
server.send(200, "text/html", s); //Send web page
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void handleWMConfig() {
|
||||
server.send(200, "text/plain", "Start Config Portal - Retaining credential");
|
||||
|
@ -89,7 +142,18 @@ void initWebServer(void) {
|
|||
DebugPort.println("MDNS responder started");
|
||||
}
|
||||
|
||||
// server.serveStatic("/", SPIFFS, "/index.html");
|
||||
// server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico");
|
||||
server.on("/", handleBTCRoot);
|
||||
// server.on("/favicon.ico", handleFavIcon);
|
||||
#if USE_SPIFFS == 1
|
||||
server.onNotFound([]()
|
||||
{ // If the client requests any URI
|
||||
if (!handleFileRead(server.uri())) // send it if it exists
|
||||
server.send(404, "text/plain", "404: Not Found"); // otherwise, respond with a 404 (Not Found) error
|
||||
}
|
||||
);
|
||||
#endif
|
||||
server.on("/wmconfig", handleWMConfig);
|
||||
server.on("/resetwifi",handleReset);
|
||||
server.onNotFound(handleBTCNotFound);
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../cfg/BTCConfig.h"
|
||||
|
||||
#if USE_SPIFFS != 1
|
||||
|
||||
const char* MAIN_PAGE PROGMEM = R"=====(
|
||||
<!DOCTYPE html>
|
||||
|
@ -527,3 +530,5 @@ Timer2: <input type="checkbox" border-radius="4px" name="Tue"> <input type="tex
|
|||
</html>
|
||||
|
||||
)=====";
|
||||
|
||||
#endif
|
|
@ -42,6 +42,8 @@
|
|||
#define USE_WIFI 1
|
||||
#define USE_OTA 1
|
||||
#define USE_WEBSERVER 1
|
||||
#define USE_SPIFFS 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue