Refactored class members

This commit is contained in:
Magnus Persson 2022-01-18 23:33:34 +01:00
parent ddb34e129d
commit 37a1ca6058
20 changed files with 386 additions and 386 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content=""><title>Beer Gravity Monitor</title><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item active"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item"><a class="nav-link" href="/device.htm">Device</a></li><li class="nav-item"><a class="nav-link" href="/config.htm">Configuration</a></li><li class="nav-item"><a class="nav-link" href="/calibration.htm">Calibration</a></li><li class="nav-item"><a class="nav-link" href="/about.htm">About</a></li></ul><div class="spinner-border text-light" id="spinner" role="status"></div></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-4"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><script type="text/javascript">function showError(s){$(".alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$(".alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$(".alert").addClass("d-none").removeClass("show")})</script><div class="" id="id" hidden></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Gravity:</div><div class="col-md-4 themed-grid-col bg-light" id="gravity">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Temperature:</div><div class="col-md-4 themed-grid-col bg-light" id="temp">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Angle/Tilt:</div><div class="col-md-4 themed-grid-col bg-light" id="angle">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Battery:</div><div class="col-md-4 themed-grid-col bg-light" id="battery">Loading...</div></div><div class="row mb-3"><div class="col-md-12 px-md-5 themed-grid-col bg-light custom-control custom-checkbox"><input type="checkbox" class="custom-control-input" name="sleep-mode" id="sleep-mode" disabled> <label class="custom-control-label" for="sleep-mode">Do not enter sleep mode when floating (check this if you are collecting angles/tilt for calibration).</label></div></div><hr class="my-4"></div><script type="text/javascript">function getStatus(){var e="/api/status";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#id").text(e.id),$("#angle").text(e.angle),$("#gravity").text(e.gravity+" SG"),$("#battery").text(e.battery+" V"),"C"==e["temp-format"]?$("#temp").text(e["temp-c"]+" C"):$("#temp").text(e["temp-f"]+" F"),e["sleep-mode"]?$("#sleep-mode").attr("checked",!0):$("#sleep-mode").attr("checked",!1),$("#sleep-mode").removeAttr("disabled")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}function start(){setInterval(getStatus,3e3)}window.onload=start,$("#sleep-mode").click(function(e){console.log("Blocking sleep mode = "+$("#sleep-mode").is(":checked")),$.ajax({type:"POST",url:"/api/status/sleepmode",data:{id:$("#id").text(),"sleep-mode":$("#sleep-mode").is(":checked")},success:function(e){},error:function(e){showError("Could not update sleep mode for device.")}})})</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></body></html> <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content=""><title>Beer Gravity Monitor</title><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item active"><a class="nav-link" href="/index.htm">Home <span class="sr-only">(current)</span></a></li><li class="nav-item"><a class="nav-link" href="/device.htm">Device</a></li><li class="nav-item"><a class="nav-link" href="/config.htm">Configuration</a></li><li class="nav-item"><a class="nav-link" href="/calibration.htm">Calibration</a></li><li class="nav-item"><a class="nav-link" href="/about.htm">About</a></li></ul><div class="spinner-border text-light" id="spinner" role="status"></div></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-4"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><script type="text/javascript">function showError(s){$(".alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$(".alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$(".alert").addClass("d-none").removeClass("show")})</script><div class="" id="id" hidden></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Gravity:</div><div class="col-md-4 themed-grid-col bg-light" id="gravity">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Temperature:</div><div class="col-md-4 themed-grid-col bg-light" id="temp">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Angle/Tilt:</div><div class="col-md-4 themed-grid-col bg-light" id="angle">Loading...</div></div><div class="row mb-3"><div class="col-md-8 themed-grid-col bg-light">Battery:</div><div class="col-md-4 themed-grid-col bg-light" id="battery">Loading...</div></div><div class="row mb-3"><div class="col-md-12 px-md-5 themed-grid-col bg-light custom-control custom-checkbox"><input type="checkbox" class="custom-control-input" name="sleep-mode" id="sleep-mode" disabled> <label class="custom-control-label" for="sleep-mode">Do not enter sleep mode when floating (check this if you are collecting angles/tilt for calibration).</label></div></div><hr class="my-4"></div><script type="text/javascript">function getStatus(){var e="/api/status";$("#spinner").show(),$.getJSON(e,function(e){console.log(e),$("#id").text(e.id),$("#angle").text(e.angle),"G"==e["gravity-format"]?$("#gravity").text(e.gravity+" SG"):$("#gravity").text(e.gravity+" °P"),$("#battery").text(e.battery+" V"),"C"==e["temp-format"]?$("#temp").text(e["temp-c"]+" C"):$("#temp").text(e["temp-f"]+" F"),e["sleep-mode"]?$("#sleep-mode").attr("checked",!0):$("#sleep-mode").attr("checked",!1),$("#sleep-mode").removeAttr("disabled")}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}function start(){setInterval(getStatus,3e3)}window.onload=start,$("#sleep-mode").click(function(e){console.log("Blocking sleep mode = "+$("#sleep-mode").is(":checked")),$.ajax({type:"POST",url:"/api/status/sleepmode",data:{id:$("#id").text(),"sleep-mode":$("#sleep-mode").is(":checked")},success:function(e){},error:function(e){showError("Could not update sleep mode for device.")}})})</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></body></html>

View File

@ -1 +1 @@
{ "project":"gravmon", "version":"0.6.0", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "calibration.min.htm", "about.min.htm" ] } { "project":"gravmon", "version":"0.6.1", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "calibration.min.htm", "about.min.htm" ] }

View File

@ -98,7 +98,7 @@ int createFormula(RawFormulaData &fd, char *formulaBuffer,
// If the deviation is more than 2 degress we mark it as failed. // If the deviation is more than 2 degress we mark it as failed.
if (dev * 1000 > FORMULA_MAX_DEVIATION) { if (dev * 1000 > FORMULA_MAX_DEVIATION) {
#if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING)
char s[10]; char s[20];
snprintf(&s[0], sizeof(s), "%.8f", dev); snprintf(&s[0], sizeof(s), "%.8f", dev);
Log.verbose(F("CALC: Deviation is: %s" CR), &s[0]); Log.verbose(F("CALC: Deviation is: %s" CR), &s[0]);
#endif #endif
@ -154,7 +154,7 @@ double calculateGravity(double angle, double temp, const char *tempFormula) {
te_free(expr); te_free(expr);
#if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING)
char s[10]; char s[20];
snprintf(&s[0], sizeof(s), "%.8f", g); snprintf(&s[0], sizeof(s), "%.8f", g);
Log.verbose(F("CALC: Calculated gravity is %s." CR), &s[0]); Log.verbose(F("CALC: Calculated gravity is %s." CR), &s[0]);
#endif #endif

View File

@ -35,13 +35,13 @@ Config::Config() {
// Assiging default values // Assiging default values
char buf[30]; char buf[30];
snprintf(&buf[0], sizeof(buf), "%6x", (unsigned int)ESP.getChipId()); snprintf(&buf[0], sizeof(buf), "%6x", (unsigned int)ESP.getChipId());
id = String(&buf[0]); _id = String(&buf[0]);
snprintf(&buf[0], sizeof(buf), "" WIFI_MDNS "%s", getID()); snprintf(&buf[0], sizeof(buf), "" WIFI_MDNS "%s", getID());
mDNS = String(&buf[0]); _mDNS = String(&buf[0]);
#if LOG_LEVEL == 6 && !defined(CFG_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(CFG_DISABLE_LOGGING)
Log.verbose(F("CFG : Created config for %s (%s)." CR), id.c_str(), Log.verbose(F("CFG : Created config for %s (%s)." CR), _id.c_str(),
mDNS.c_str()); _mDNS.c_str());
#endif #endif
setTempFormat('C'); setTempFormat('C');
@ -50,10 +50,10 @@ Config::Config() {
setVoltageFactor(1.59); // Conversion factor for battery setVoltageFactor(1.59); // Conversion factor for battery
setTempSensorAdjC(0.0); setTempSensorAdjC(0.0);
setGravityTempAdj(false); setGravityTempAdj(false);
gyroCalibration = {0, 0, 0, 0, 0, 0}; _gyroCalibration = {0, 0, 0, 0, 0, 0};
formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}}; _formulaData = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}};
gyroTemp = false; _gyroTemp = false;
saveNeeded = false; _saveNeeded = false;
} }
// //
@ -87,32 +87,32 @@ void Config::createJson(DynamicJsonDocument& doc) {
doc[CFG_PARAM_GYRO_TEMP] = isGyroTemp(); doc[CFG_PARAM_GYRO_TEMP] = isGyroTemp();
JsonObject cal = doc.createNestedObject(CFG_PARAM_GYRO_CALIBRATION); JsonObject cal = doc.createNestedObject(CFG_PARAM_GYRO_CALIBRATION);
cal["ax"] = gyroCalibration.ax; cal["ax"] = _gyroCalibration.ax;
cal["ay"] = gyroCalibration.ay; cal["ay"] = _gyroCalibration.ay;
cal["az"] = gyroCalibration.az; cal["az"] = _gyroCalibration.az;
cal["gx"] = gyroCalibration.gx; cal["gx"] = _gyroCalibration.gx;
cal["gy"] = gyroCalibration.gy; cal["gy"] = _gyroCalibration.gy;
cal["gz"] = gyroCalibration.gz; cal["gz"] = _gyroCalibration.gz;
JsonObject cal2 = doc.createNestedObject(CFG_PARAM_FORMULA_DATA); JsonObject cal2 = doc.createNestedObject(CFG_PARAM_FORMULA_DATA);
cal2["a1"] = reduceFloatPrecision(formulaData.a[0], 2); cal2["a1"] = reduceFloatPrecision(_formulaData.a[0], 2);
cal2["a2"] = reduceFloatPrecision(formulaData.a[1], 2); cal2["a2"] = reduceFloatPrecision(_formulaData.a[1], 2);
cal2["a3"] = reduceFloatPrecision(formulaData.a[2], 2); cal2["a3"] = reduceFloatPrecision(_formulaData.a[2], 2);
cal2["a4"] = reduceFloatPrecision(formulaData.a[3], 2); cal2["a4"] = reduceFloatPrecision(_formulaData.a[3], 2);
cal2["a5"] = reduceFloatPrecision(formulaData.a[4], 2); cal2["a5"] = reduceFloatPrecision(_formulaData.a[4], 2);
cal2["g1"] = reduceFloatPrecision(formulaData.g[0], 4); cal2["g1"] = reduceFloatPrecision(_formulaData.g[0], 4);
cal2["g2"] = reduceFloatPrecision(formulaData.g[1], 4); cal2["g2"] = reduceFloatPrecision(_formulaData.g[1], 4);
cal2["g3"] = reduceFloatPrecision(formulaData.g[2], 4); cal2["g3"] = reduceFloatPrecision(_formulaData.g[2], 4);
cal2["g4"] = reduceFloatPrecision(formulaData.g[3], 4); cal2["g4"] = reduceFloatPrecision(_formulaData.g[3], 4);
cal2["g5"] = reduceFloatPrecision(formulaData.g[4], 4); cal2["g5"] = reduceFloatPrecision(_formulaData.g[4], 4);
} }
// //
// Save json document to file // Save json document to file
// //
bool Config::saveFile() { bool Config::saveFile() {
if (!saveNeeded) { if (!_saveNeeded) {
#if LOG_LEVEL == 6 && !defined(CFG_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(CFG_DISABLE_LOGGING)
Log.verbose(F("CFG : Skipping save, not needed." CR)); Log.verbose(F("CFG : Skipping save, not needed." CR));
#endif #endif
@ -142,7 +142,7 @@ bool Config::saveFile() {
configFile.flush(); configFile.flush();
configFile.close(); configFile.close();
saveNeeded = false; _saveNeeded = false;
myConfig.debug(); myConfig.debug();
Log.notice(F("CFG : Configuration saved to " CFG_FILENAME "." CR)); Log.notice(F("CFG : Configuration saved to " CFG_FILENAME "." CR));
return true; return true;
@ -242,42 +242,42 @@ bool Config::loadFile() {
setTempSensorAdjC(doc[CFG_PARAM_TEMP_ADJ].as<float>()); setTempSensorAdjC(doc[CFG_PARAM_TEMP_ADJ].as<float>());
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ax"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ax"].isNull())
gyroCalibration.ax = doc[CFG_PARAM_GYRO_CALIBRATION]["ax"]; _gyroCalibration.ax = doc[CFG_PARAM_GYRO_CALIBRATION]["ax"];
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ay"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["ay"].isNull())
gyroCalibration.ay = doc[CFG_PARAM_GYRO_CALIBRATION]["ay"]; _gyroCalibration.ay = doc[CFG_PARAM_GYRO_CALIBRATION]["ay"];
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["az"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["az"].isNull())
gyroCalibration.az = doc[CFG_PARAM_GYRO_CALIBRATION]["az"]; _gyroCalibration.az = doc[CFG_PARAM_GYRO_CALIBRATION]["az"];
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gx"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gx"].isNull())
gyroCalibration.gx = doc[CFG_PARAM_GYRO_CALIBRATION]["gx"]; _gyroCalibration.gx = doc[CFG_PARAM_GYRO_CALIBRATION]["gx"];
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gy"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gy"].isNull())
gyroCalibration.gy = doc[CFG_PARAM_GYRO_CALIBRATION]["gy"]; _gyroCalibration.gy = doc[CFG_PARAM_GYRO_CALIBRATION]["gy"];
if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gz"].isNull()) if (!doc[CFG_PARAM_GYRO_CALIBRATION]["gz"].isNull())
gyroCalibration.gz = doc[CFG_PARAM_GYRO_CALIBRATION]["gz"]; _gyroCalibration.gz = doc[CFG_PARAM_GYRO_CALIBRATION]["gz"];
if (!doc[CFG_PARAM_FORMULA_DATA]["a1"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["a1"].isNull())
formulaData.a[0] = doc[CFG_PARAM_FORMULA_DATA]["a1"].as<double>(); _formulaData.a[0] = doc[CFG_PARAM_FORMULA_DATA]["a1"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["a2"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["a2"].isNull())
formulaData.a[1] = doc[CFG_PARAM_FORMULA_DATA]["a2"].as<double>(); _formulaData.a[1] = doc[CFG_PARAM_FORMULA_DATA]["a2"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["a3"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["a3"].isNull())
formulaData.a[2] = doc[CFG_PARAM_FORMULA_DATA]["a3"].as<double>(); _formulaData.a[2] = doc[CFG_PARAM_FORMULA_DATA]["a3"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["a4"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["a4"].isNull())
formulaData.a[3] = doc[CFG_PARAM_FORMULA_DATA]["a4"].as<double>(); _formulaData.a[3] = doc[CFG_PARAM_FORMULA_DATA]["a4"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["a5"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["a5"].isNull())
formulaData.a[4] = doc[CFG_PARAM_FORMULA_DATA]["a5"].as<double>(); _formulaData.a[4] = doc[CFG_PARAM_FORMULA_DATA]["a5"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["g1"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["g1"].isNull())
formulaData.g[0] = doc[CFG_PARAM_FORMULA_DATA]["g1"].as<double>(); _formulaData.g[0] = doc[CFG_PARAM_FORMULA_DATA]["g1"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["g2"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["g2"].isNull())
formulaData.g[1] = doc[CFG_PARAM_FORMULA_DATA]["g2"].as<double>(); _formulaData.g[1] = doc[CFG_PARAM_FORMULA_DATA]["g2"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["g3"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["g3"].isNull())
formulaData.g[2] = doc[CFG_PARAM_FORMULA_DATA]["g3"].as<double>(); _formulaData.g[2] = doc[CFG_PARAM_FORMULA_DATA]["g3"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["g4"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["g4"].isNull())
formulaData.g[3] = doc[CFG_PARAM_FORMULA_DATA]["g4"].as<double>(); _formulaData.g[3] = doc[CFG_PARAM_FORMULA_DATA]["g4"].as<double>();
if (!doc[CFG_PARAM_FORMULA_DATA]["g5"].isNull()) if (!doc[CFG_PARAM_FORMULA_DATA]["g5"].isNull())
formulaData.g[4] = doc[CFG_PARAM_FORMULA_DATA]["g5"].as<double>(); _formulaData.g[4] = doc[CFG_PARAM_FORMULA_DATA]["g5"].as<double>();
myConfig.debug(); myConfig.debug();
saveNeeded = false; // Reset save flag _saveNeeded = false; // Reset save flag
Log.notice(F("CFG : Configuration file " CFG_FILENAME " loaded." CR)); Log.notice(F("CFG : Configuration file " CFG_FILENAME " loaded." CR));
return true; return true;
} }

View File

@ -113,230 +113,230 @@ struct RawFormulaData {
// Main configuration class // Main configuration class
class Config { class Config {
private: private:
bool saveNeeded; bool _saveNeeded;
// Device configuration // Device configuration
String id; String _id;
String mDNS; String _mDNS;
String otaURL; String _otaURL;
char tempFormat; char _tempFormat;
float voltageFactor; float _voltageFactor;
float tempSensorAdjC; float _tempSensorAdjC;
int sleepInterval; int _sleepInterval;
bool gyroTemp; bool _gyroTemp;
// Wifi Config // Wifi Config
String wifiSSID; String _wifiSSID;
String wifiPASS; String _wifiPASS;
// Push target settings // Push target settings
String brewfatherPushUrl; String _brewfatherPushUrl;
String httpPushUrl; String _httpPushUrl;
String httpPushUrl2; String _httpPushUrl2;
String influxDb2Url; String _influxDb2Url;
String influxDb2Org; String _influxDb2Org;
String influxDb2Bucket; String _influxDb2Bucket;
String influxDb2Token; String _influxDb2Token;
String mqttUrl; String _mqttUrl;
String mqttTopic; String _mqttTopic;
String mqttUser; String _mqttUser;
String mqttPass; String _mqttPass;
// Gravity and temperature calculations // Gravity and temperature calculations
String gravityFormula; String _gravityFormula;
bool gravityTempAdj; bool _gravityTempAdj;
char gravityFormat; char _gravityFormat;
// Gyro calibration and formula calculation data // Gyro calibration and formula calculation data
RawGyroData gyroCalibration; RawGyroData _gyroCalibration;
RawFormulaData formulaData; RawFormulaData _formulaData;
void debug(); void debug();
void formatFileSystem(); void formatFileSystem();
public: public:
Config(); Config();
const char* getID() { return id.c_str(); } const char* getID() { return _id.c_str(); }
const char* getMDNS() { return mDNS.c_str(); } const char* getMDNS() { return _mDNS.c_str(); }
void setMDNS(String s) { void setMDNS(String s) {
mDNS = s; _mDNS = s;
saveNeeded = true; _saveNeeded = true;
} }
const bool isGyroTemp() { return gyroTemp; } const bool isGyroTemp() { return _gyroTemp; }
void setGyroTemp(bool b) { void setGyroTemp(bool b) {
gyroTemp = b; _gyroTemp = b;
saveNeeded = true; _saveNeeded = true;
} }
const char* getOtaURL() { return otaURL.c_str(); } const char* getOtaURL() { return _otaURL.c_str(); }
void setOtaURL(String s) { void setOtaURL(String s) {
otaURL = s; _otaURL = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isOtaActive() { return otaURL.length() ? true : false; } bool isOtaActive() { return _otaURL.length() ? true : false; }
const char* getWifiSSID() { return wifiSSID.c_str(); } const char* getWifiSSID() { return _wifiSSID.c_str(); }
void setWifiSSID(String s) { void setWifiSSID(String s) {
wifiSSID = s; _wifiSSID = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getWifiPass() { return wifiPASS.c_str(); } const char* getWifiPass() { return _wifiPASS.c_str(); }
void setWifiPass(String s) { void setWifiPass(String s) {
wifiPASS = s; _wifiPASS = s;
saveNeeded = true; _saveNeeded = true;
} }
// Brewfather // Brewfather
const char* getBrewfatherPushUrl() { return brewfatherPushUrl.c_str(); } const char* getBrewfatherPushUrl() { return _brewfatherPushUrl.c_str(); }
void setBrewfatherPushUrl(String s) { void setBrewfatherPushUrl(String s) {
brewfatherPushUrl = s; _brewfatherPushUrl = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isBrewfatherActive() { bool isBrewfatherActive() {
return brewfatherPushUrl.length() ? true : false; return _brewfatherPushUrl.length() ? true : false;
} }
// Standard HTTP // Standard HTTP
const char* getHttpPushUrl() { return httpPushUrl.c_str(); } const char* getHttpPushUrl() { return _httpPushUrl.c_str(); }
void setHttpPushUrl(String s) { void setHttpPushUrl(String s) {
httpPushUrl = s; _httpPushUrl = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isHttpActive() { return httpPushUrl.length() ? true : false; } bool isHttpActive() { return _httpPushUrl.length() ? true : false; }
const char* getHttpPushUrl2() { return httpPushUrl2.c_str(); } const char* getHttpPushUrl2() { return _httpPushUrl2.c_str(); }
void setHttpPushUrl2(String s) { void setHttpPushUrl2(String s) {
httpPushUrl2 = s; _httpPushUrl2 = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isHttpActive2() { return httpPushUrl2.length() ? true : false; } bool isHttpActive2() { return _httpPushUrl2.length() ? true : false; }
// InfluxDB2 // InfluxDB2
const char* getInfluxDb2PushUrl() { return influxDb2Url.c_str(); } const char* getInfluxDb2PushUrl() { return _influxDb2Url.c_str(); }
void setInfluxDb2PushUrl(String s) { void setInfluxDb2PushUrl(String s) {
influxDb2Url = s; _influxDb2Url = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isInfluxDb2Active() { return influxDb2Url.length() ? true : false; } bool isInfluxDb2Active() { return _influxDb2Url.length() ? true : false; }
const char* getInfluxDb2PushOrg() { return influxDb2Org.c_str(); } const char* getInfluxDb2PushOrg() { return _influxDb2Org.c_str(); }
void setInfluxDb2PushOrg(String s) { void setInfluxDb2PushOrg(String s) {
influxDb2Org = s; _influxDb2Org = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getInfluxDb2PushBucket() { return influxDb2Bucket.c_str(); } const char* getInfluxDb2PushBucket() { return _influxDb2Bucket.c_str(); }
void setInfluxDb2PushBucket(String s) { void setInfluxDb2PushBucket(String s) {
influxDb2Bucket = s; _influxDb2Bucket = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getInfluxDb2PushToken() { return influxDb2Token.c_str(); } const char* getInfluxDb2PushToken() { return _influxDb2Token.c_str(); }
void setInfluxDb2PushToken(String s) { void setInfluxDb2PushToken(String s) {
influxDb2Token = s; _influxDb2Token = s;
saveNeeded = true; _saveNeeded = true;
} }
// MQTT // MQTT
bool isMqttActive() { return mqttUrl.length() ? true : false; } bool isMqttActive() { return _mqttUrl.length() ? true : false; }
const char* getMqttUrl() { return mqttUrl.c_str(); } const char* getMqttUrl() { return _mqttUrl.c_str(); }
void setMqttUrl(String s) { void setMqttUrl(String s) {
mqttUrl = s; _mqttUrl = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getMqttTopic() { return mqttTopic.c_str(); } const char* getMqttTopic() { return _mqttTopic.c_str(); }
void setMqttTopic(String s) { void setMqttTopic(String s) {
mqttTopic = s; _mqttTopic = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getMqttUser() { return mqttUser.c_str(); } const char* getMqttUser() { return _mqttUser.c_str(); }
void setMqttUser(String s) { void setMqttUser(String s) {
mqttUser = s; _mqttUser = s;
saveNeeded = true; _saveNeeded = true;
} }
const char* getMqttPass() { return mqttPass.c_str(); } const char* getMqttPass() { return _mqttPass.c_str(); }
void setMqttPass(String s) { void setMqttPass(String s) {
mqttPass = s; _mqttPass = s;
saveNeeded = true; _saveNeeded = true;
} }
int getSleepInterval() { return sleepInterval; } int getSleepInterval() { return _sleepInterval; }
void setSleepInterval(int v) { void setSleepInterval(int v) {
sleepInterval = v; _sleepInterval = v;
saveNeeded = true; _saveNeeded = true;
} }
void setSleepInterval(String s) { void setSleepInterval(String s) {
sleepInterval = s.toInt(); _sleepInterval = s.toInt();
saveNeeded = true; _saveNeeded = true;
} }
char getTempFormat() { return tempFormat; } char getTempFormat() { return _tempFormat; }
void setTempFormat(char c) { void setTempFormat(char c) {
if (c == 'C' || c == 'F') { if (c == 'C' || c == 'F') {
tempFormat = c; _tempFormat = c;
saveNeeded = true; _saveNeeded = true;
} }
} }
bool isTempC() { return tempFormat == 'C'; } bool isTempC() { return _tempFormat == 'C'; }
bool isTempF() { return tempFormat == 'F'; } bool isTempF() { return _tempFormat == 'F'; }
float getVoltageFactor() { return voltageFactor; } float getVoltageFactor() { return _voltageFactor; }
void setVoltageFactor(float f) { void setVoltageFactor(float f) {
voltageFactor = f; _voltageFactor = f;
saveNeeded = true; _saveNeeded = true;
} }
void setVoltageFactor(String s) { void setVoltageFactor(String s) {
voltageFactor = s.toFloat(); _voltageFactor = s.toFloat();
saveNeeded = true; _saveNeeded = true;
} }
float getTempSensorAdjC() { return tempSensorAdjC; } float getTempSensorAdjC() { return _tempSensorAdjC; }
void setTempSensorAdjC(float f) { void setTempSensorAdjC(float f) {
tempSensorAdjC = f; _tempSensorAdjC = f;
saveNeeded = true; _saveNeeded = true;
} }
void setTempSensorAdjC(String s) { void setTempSensorAdjC(String s) {
tempSensorAdjC = s.toFloat(); _tempSensorAdjC = s.toFloat();
saveNeeded = true; _saveNeeded = true;
} }
void setTempSensorAdjF(String s) { void setTempSensorAdjF(String s) {
tempSensorAdjC = convertFtoC(s.toFloat()); _tempSensorAdjC = convertFtoC(s.toFloat());
saveNeeded = true; _saveNeeded = true;
} }
const char* getGravityFormula() { return gravityFormula.c_str(); } const char* getGravityFormula() { return _gravityFormula.c_str(); }
void setGravityFormula(String s) { void setGravityFormula(String s) {
gravityFormula = s; _gravityFormula = s;
saveNeeded = true; _saveNeeded = true;
} }
bool isGravityTempAdj() { return gravityTempAdj; } bool isGravityTempAdj() { return _gravityTempAdj; }
void setGravityTempAdj(bool b) { void setGravityTempAdj(bool b) {
gravityTempAdj = b; _gravityTempAdj = b;
saveNeeded = true; _saveNeeded = true;
} }
char getGravityFormat() { return gravityFormat; } char getGravityFormat() { return _gravityFormat; }
void setGravityFormat(char c) { void setGravityFormat(char c) {
if (c == 'G' || c == 'P') { if (c == 'G' || c == 'P') {
gravityFormat = c; _gravityFormat = c;
saveNeeded = true; _saveNeeded = true;
} }
} }
bool isGravitySG() { return gravityFormat == 'G'; } bool isGravitySG() { return _gravityFormat == 'G'; }
bool isGravityPlato() { return gravityFormat == 'P'; } bool isGravityPlato() { return _gravityFormat == 'P'; }
const RawGyroData& getGyroCalibration() { return gyroCalibration; } const RawGyroData& getGyroCalibration() { return _gyroCalibration; }
void setGyroCalibration(const RawGyroData& r) { void setGyroCalibration(const RawGyroData& r) {
gyroCalibration = r; _gyroCalibration = r;
saveNeeded = true; _saveNeeded = true;
} }
const RawFormulaData& getFormulaData() { return formulaData; } const RawFormulaData& getFormulaData() { return _formulaData; }
void setFormulaData(const RawFormulaData& r) { void setFormulaData(const RawFormulaData& r) {
formulaData = r; _formulaData = r;
saveNeeded = true; _saveNeeded = true;
} }
// IO functions // IO functions
@ -344,8 +344,8 @@ class Config {
bool saveFile(); bool saveFile();
bool loadFile(); bool loadFile();
void checkFileSystem(); void checkFileSystem();
bool isSaveNeeded() { return saveNeeded; } bool isSaveNeeded() { return _saveNeeded; }
void setSaveNeeded() { saveNeeded = true; } void setSaveNeeded() { _saveNeeded = true; }
}; };
// Global instance created // Global instance created

View File

@ -49,13 +49,13 @@ bool GyroSensor::setup() {
if (!accelgyro.testConnection()) { if (!accelgyro.testConnection()) {
Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR)); Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR));
sensorConnected = false; _sensorConnected = false;
} else { } else {
#if !defined(GYRO_DISABLE_LOGGING) #if !defined(GYRO_DISABLE_LOGGING)
Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR)); Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR));
#endif #endif
accelgyro.initialize(); accelgyro.initialize();
sensorConnected = true; _sensorConnected = true;
// Configure the sensor // Configure the sensor
accelgyro.setTempSensorEnabled(true); accelgyro.setTempSensorEnabled(true);
@ -77,10 +77,10 @@ bool GyroSensor::setup() {
// Once we have calibration values stored we just apply them from the // Once we have calibration values stored we just apply them from the
// config. // config.
calibrationOffset = myConfig.getGyroCalibration(); _calibrationOffset = myConfig.getGyroCalibration();
applyCalibration(); applyCalibration();
} }
return sensorConnected; return _sensorConnected;
} }
// //
@ -234,35 +234,35 @@ bool GyroSensor::read() {
Log.verbose(F("GYRO: Getting new gyro position." CR)); Log.verbose(F("GYRO: Getting new gyro position." CR));
#endif #endif
if (!sensorConnected) return false; if (!_sensorConnected) return false;
readSensor(lastGyroData, SENSOR_READ_COUNT, readSensor(_lastGyroData, SENSOR_READ_COUNT,
SENSOR_READ_DELAY); // Last param is unused if GYRO_USE_INTERRUPT SENSOR_READ_DELAY); // Last param is unused if GYRO_USE_INTERRUPT
// is defined. // is defined.
// If the sensor is unstable we return false to signal we dont have valid // If the sensor is unstable we return false to signal we dont have valid
// value // value
if (isSensorMoving(lastGyroData)) { if (isSensorMoving(_lastGyroData)) {
#if !defined(GYRO_DISABLE_LOGGING) #if !defined(GYRO_DISABLE_LOGGING)
Log.notice(F("GYRO: Sensor is moving." CR)); Log.notice(F("GYRO: Sensor is moving." CR));
#endif #endif
validValue = false; _validValue = false;
} else { } else {
validValue = true; _validValue = true;
angle = calculateAngle(lastGyroData); _angle = calculateAngle(_lastGyroData);
#if !defined(GYRO_DISABLE_LOGGING) #if !defined(GYRO_DISABLE_LOGGING)
Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), lastGyroData.ax, Log.notice(F("GYRO: Sensor values %d,%d,%d\t%F" CR), _lastGyroData.ax,
lastGyroData.ay, lastGyroData.az, angle); _lastGyroData.ay, _lastGyroData.az, _angle);
#endif #endif
} }
sensorTemp = (static_cast<float>(lastGyroData.temp)) / 340 + 36.53; _sensorTemp = (static_cast<float>(_lastGyroData.temp)) / 340 + 36.53;
// The first read value is close to the DS18 value according to my tests, if // The first read value is close to the DS18 value according to my tests, if
// more reads are done then the gyro temp will increase to much // more reads are done then the gyro temp will increase to much
if (initialSensorTemp == INVALID_TEMPERATURE) initialSensorTemp = sensorTemp; if (_initialSensorTemp == INVALID_TEMPERATURE) _initialSensorTemp = _sensorTemp;
return validValue; return _validValue;
} }
// //
@ -270,10 +270,10 @@ bool GyroSensor::read() {
// //
void GyroSensor::dumpCalibration() { void GyroSensor::dumpCalibration() {
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
Log.verbose(F("GYRO: Accel offset\t%d\t%d\t%d" CR), calibrationOffset.ax, Log.verbose(F("GYRO: Accel offset\t%d\t%d\t%d" CR), _calibrationOffset.ax,
calibrationOffset.ay, calibrationOffset.az); _calibrationOffset.ay, _calibrationOffset.az);
Log.verbose(F("GYRO: Gyro offset \t%d\t%d\t%d" CR), calibrationOffset.gx, Log.verbose(F("GYRO: Gyro offset \t%d\t%d\t%d" CR), _calibrationOffset.gx,
calibrationOffset.gy, calibrationOffset.gz); _calibrationOffset.gy, _calibrationOffset.gz);
#endif #endif
} }
@ -285,19 +285,19 @@ void GyroSensor::applyCalibration() {
Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR)); Log.verbose(F("GYRO: Applying calibration offsets to sensor." CR));
#endif #endif
if ((calibrationOffset.ax + calibrationOffset.ay + calibrationOffset.az + if ((_calibrationOffset.ax + _calibrationOffset.ay + _calibrationOffset.az +
calibrationOffset.gx + calibrationOffset.gy + calibrationOffset.gz) == _calibrationOffset.gx + _calibrationOffset.gy + _calibrationOffset.gz) ==
0) { 0) {
Log.error(F("GYRO: No valid calibraion values exist, aborting." CR)); Log.error(F("GYRO: No valid calibraion values exist, aborting." CR));
return; return;
} }
accelgyro.setXAccelOffset(calibrationOffset.ax); accelgyro.setXAccelOffset(_calibrationOffset.ax);
accelgyro.setYAccelOffset(calibrationOffset.ay); accelgyro.setYAccelOffset(_calibrationOffset.ay);
accelgyro.setZAccelOffset(calibrationOffset.az); accelgyro.setZAccelOffset(_calibrationOffset.az);
accelgyro.setXGyroOffset(calibrationOffset.gx); accelgyro.setXGyroOffset(_calibrationOffset.gx);
accelgyro.setYGyroOffset(calibrationOffset.gy); accelgyro.setYGyroOffset(_calibrationOffset.gy);
accelgyro.setZGyroOffset(calibrationOffset.gz); accelgyro.setZGyroOffset(_calibrationOffset.gz);
} }
// //
@ -317,15 +317,15 @@ void GyroSensor::calibrateSensor() {
accelgyro.PrintActiveOffsets(); accelgyro.PrintActiveOffsets();
Serial.print(CR); Serial.print(CR);
calibrationOffset.ax = accelgyro.getXAccelOffset(); _calibrationOffset.ax = accelgyro.getXAccelOffset();
calibrationOffset.ay = accelgyro.getYAccelOffset(); _calibrationOffset.ay = accelgyro.getYAccelOffset();
calibrationOffset.az = accelgyro.getZAccelOffset(); _calibrationOffset.az = accelgyro.getZAccelOffset();
calibrationOffset.gx = accelgyro.getXGyroOffset(); _calibrationOffset.gx = accelgyro.getXGyroOffset();
calibrationOffset.gy = accelgyro.getYGyroOffset(); _calibrationOffset.gy = accelgyro.getYGyroOffset();
calibrationOffset.gz = accelgyro.getZGyroOffset(); _calibrationOffset.gz = accelgyro.getZGyroOffset();
// Save the calibrated values // Save the calibrated values
myConfig.setGyroCalibration(calibrationOffset); myConfig.setGyroCalibration(_calibrationOffset);
myConfig.saveFile(); myConfig.saveFile();
} }
@ -380,17 +380,17 @@ void GyroSensor::debug() {
} }
Log.verbose(F("GYRO: Debug - Acc OffX %d\t%d." CR), Log.verbose(F("GYRO: Debug - Acc OffX %d\t%d." CR),
accelgyro.getXAccelOffset(), calibrationOffset.az); accelgyro.getXAccelOffset(), _calibrationOffset.az);
Log.verbose(F("GYRO: Debug - Acc OffY %d\t%d." CR), Log.verbose(F("GYRO: Debug - Acc OffY %d\t%d." CR),
accelgyro.getYAccelOffset(), calibrationOffset.ay); accelgyro.getYAccelOffset(), _calibrationOffset.ay);
Log.verbose(F("GYRO: Debug - Acc OffZ %d\t%d." CR), Log.verbose(F("GYRO: Debug - Acc OffZ %d\t%d." CR),
accelgyro.getZAccelOffset(), calibrationOffset.az); accelgyro.getZAccelOffset(), _calibrationOffset.az);
Log.verbose(F("GYRO: Debug - Gyr OffX %d\t%d." CR), Log.verbose(F("GYRO: Debug - Gyr OffX %d\t%d." CR),
accelgyro.getXGyroOffset(), calibrationOffset.gx); accelgyro.getXGyroOffset(), _calibrationOffset.gx);
Log.verbose(F("GYRO: Debug - Gyr OffY %d\t%d." CR), Log.verbose(F("GYRO: Debug - Gyr OffY %d\t%d." CR),
accelgyro.getYGyroOffset(), calibrationOffset.gy); accelgyro.getYGyroOffset(), _calibrationOffset.gy);
Log.verbose(F("GYRO: Debug - Gyr OffZ %d\t%d." CR), Log.verbose(F("GYRO: Debug - Gyr OffZ %d\t%d." CR),
accelgyro.getZGyroOffset(), calibrationOffset.gz); accelgyro.getZGyroOffset(), _calibrationOffset.gz);
#endif #endif
} }

View File

@ -50,13 +50,13 @@ struct RawGyroDataL { // Used for average multiple readings
class GyroSensor { class GyroSensor {
private: private:
bool sensorConnected = false; bool _sensorConnected = false;
bool validValue = false; bool _validValue = false;
float angle = 0; float _angle = 0;
float sensorTemp = 0; float _sensorTemp = 0;
float initialSensorTemp = INVALID_TEMPERATURE; float _initialSensorTemp = INVALID_TEMPERATURE;
RawGyroData calibrationOffset; RawGyroData _calibrationOffset;
RawGyroData lastGyroData; RawGyroData _lastGyroData;
void debug(); void debug();
void applyCalibration(); void applyCalibration();
@ -71,12 +71,12 @@ class GyroSensor {
bool read(); bool read();
void calibrateSensor(); void calibrateSensor();
const RawGyroData &getLastGyroData() { return lastGyroData; } const RawGyroData &getLastGyroData() { return _lastGyroData; }
float getAngle() { return angle; } float getAngle() { return _angle; }
float getSensorTempC() { return sensorTemp; } float getSensorTempC() { return _sensorTemp; }
float getInitialSensorTempC() { return initialSensorTemp; } float getInitialSensorTempC() { return _initialSensorTemp; }
bool isConnected() { return sensorConnected; } bool isConnected() { return _sensorConnected; }
bool hasValue() { return validValue; } bool hasValue() { return _validValue; }
void enterSleep(); void enterSleep();
}; };

View File

@ -125,11 +125,11 @@ void BatteryVoltage::read() {
// the voltage (from max 5V) // the voltage (from max 5V)
float factor = myConfig.getVoltageFactor(); // Default value is 1.63 float factor = myConfig.getVoltageFactor(); // Default value is 1.63
int v = analogRead(A0); int v = analogRead(A0);
batteryLevel = ((3.3 / 1023) * v) * factor; _batteryLevel = ((3.3 / 1023) * v) * factor;
#if LOG_LEVEL == 6 && !defined(HELPER_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(HELPER_DISABLE_LOGGING)
Log.verbose( Log.verbose(
F("BATT: Reading voltage level. Factor=%F Value=%d, Voltage=%F." CR), F("BATT: Reading voltage level. Factor=%F Value=%d, Voltage=%F." CR),
factor, v, batteryLevel); factor, v, _batteryLevel);
#endif #endif
} }

View File

@ -57,11 +57,11 @@ class SerialDebug {
class BatteryVoltage { class BatteryVoltage {
private: private:
float batteryLevel; float _batteryLevel;
public: public:
void read(); void read();
float getVoltage() { return batteryLevel; } float getVoltage() { return _batteryLevel; }
}; };
#if defined(COLLECT_PERFDATA) #if defined(COLLECT_PERFDATA)

View File

@ -36,7 +36,7 @@ PushTarget myPushTarget;
// //
void PushTarget::send(float angle, float gravity, float corrGravity, void PushTarget::send(float angle, float gravity, float corrGravity,
float tempC, float runTime, bool force) { float tempC, float runTime, bool force) {
uint32_t timePassed = abs((int32_t)(millis() - ms)); uint32_t timePassed = abs((int32_t)(millis() - _ms));
uint32_t interval = myConfig.getSleepInterval() * 1000; uint32_t interval = myConfig.getSleepInterval() * 1000;
if ((timePassed < interval) && !force) { if ((timePassed < interval) && !force) {
@ -47,7 +47,7 @@ void PushTarget::send(float angle, float gravity, float corrGravity,
return; return;
} }
ms = millis(); _ms = millis();
if (myConfig.isBrewfatherActive()) { if (myConfig.isBrewfatherActive()) {
LOG_PERF_START("push-brewfather"); LOG_PERF_START("push-brewfather");

View File

@ -33,7 +33,7 @@ SOFTWARE.
// Classes // Classes
class PushTarget { class PushTarget {
private: private:
uint32_t ms; // Used to check that we do not post to often uint32_t _ms; // Used to check that we do not post to often
void sendBrewfather(float angle, float gravity, float corrGravity, void sendBrewfather(float angle, float gravity, float corrGravity,
float tempC); float tempC);
@ -48,7 +48,7 @@ class PushTarget {
float runTime); float runTime);
public: public:
PushTarget() { ms = millis(); } PushTarget() { _ms = millis(); }
void send(float angle, float gravity, float corrGravity, float temp, void send(float angle, float gravity, float corrGravity, float temp,
float runTime, bool force = false); float runTime, bool force = false);
}; };

View File

@ -59,11 +59,11 @@ void TempSensor::setup() {
} }
// Set the temp sensor adjustment values // Set the temp sensor adjustment values
tempSensorAdjC = myConfig.getTempSensorAdjC(); _tempSensorAdjC = myConfig.getTempSensorAdjC();
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
Log.verbose(F("TSEN: Adjustment values for temp sensor %F C." CR), Log.verbose(F("TSEN: Adjustment values for temp sensor %F C." CR),
tempSensorAdjC); _tempSensorAdjC);
#endif #endif
} }
@ -82,7 +82,7 @@ float TempSensor::getValue(bool useGyro) {
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
Log.verbose(F("TSEN: Reciving temp value for gyro sensor %F C." CR), c); Log.verbose(F("TSEN: Reciving temp value for gyro sensor %F C." CR), c);
#endif #endif
hasSensor = true; _hasSensor = true;
return c; return c;
} }
@ -105,7 +105,7 @@ float TempSensor::getValue(bool useGyro) {
#if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING) #if LOG_LEVEL == 6 && !defined(TSEN_DISABLE_LOGGING)
Log.verbose(F("TSEN: Reciving temp value for DS18B20 sensor %F C." CR), c); Log.verbose(F("TSEN: Reciving temp value for DS18B20 sensor %F C." CR), c);
#endif #endif
hasSensor = true; _hasSensor = true;
} }
return c; return c;
} }

View File

@ -29,15 +29,15 @@ SOFTWARE.
// classes // classes
class TempSensor { class TempSensor {
private: private:
bool hasSensor = false; bool _hasSensor = false;
float tempSensorAdjC = 0; float _tempSensorAdjC = 0;
float getValue(bool useGyro); float getValue(bool useGyro);
public: public:
void setup(); void setup();
bool isSensorAttached() { return hasSensor; } bool isSensorAttached() { return _hasSensor; }
float getTempC(bool useGyro = false) { float getTempC(bool useGyro = false) {
return getValue(useGyro) + tempSensorAdjC; return getValue(useGyro) + _tempSensorAdjC;
} }
}; };

View File

@ -55,7 +55,7 @@ void WebServer::webHandleDevice() {
#endif #endif
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str()); _server->send(200, "application/json", out.c_str());
LOG_PERF_STOP("webserver-api-device"); LOG_PERF_STOP("webserver-api-device");
} }
@ -98,7 +98,7 @@ void WebServer::webHandleConfig() {
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str()); _server->send(200, "application/json", out.c_str());
LOG_PERF_STOP("webserver-api-config"); LOG_PERF_STOP("webserver-api-config");
} }
@ -123,7 +123,7 @@ void WebServer::webHandleUpload() {
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str()); _server->send(200, "application/json", out.c_str());
LOG_PERF_STOP("webserver-api-upload"); LOG_PERF_STOP("webserver-api-upload");
} }
@ -133,7 +133,7 @@ void WebServer::webHandleUpload() {
void WebServer::webHandleUploadFile() { void WebServer::webHandleUploadFile() {
LOG_PERF_START("webserver-api-upload-file"); LOG_PERF_START("webserver-api-upload-file");
Log.notice(F("WEB : webServer callback for /api/upload/file." CR)); Log.notice(F("WEB : webServer callback for /api/upload/file." CR));
HTTPUpload& upload = server->upload(); HTTPUpload& upload = _server->upload();
String f = upload.filename; String f = upload.filename;
bool validFilename = false; bool validFilename = false;
@ -153,23 +153,23 @@ void WebServer::webHandleUploadFile() {
if (upload.status == UPLOAD_FILE_START) { if (upload.status == UPLOAD_FILE_START) {
Log.notice(F("WEB : Start upload." CR)); Log.notice(F("WEB : Start upload." CR));
if (validFilename) uploadFile = LittleFS.open(f, "w"); if (validFilename) _uploadFile = LittleFS.open(f, "w");
} else if (upload.status == UPLOAD_FILE_WRITE) { } else if (upload.status == UPLOAD_FILE_WRITE) {
Log.notice(F("WEB : Writing upload." CR)); Log.notice(F("WEB : Writing upload." CR));
if (uploadFile) if (_uploadFile)
uploadFile.write( _uploadFile.write(
upload.buf, upload.buf,
upload.currentSize); // Write the received bytes to the file upload.currentSize); // Write the received bytes to the file
} else if (upload.status == UPLOAD_FILE_END) { } else if (upload.status == UPLOAD_FILE_END) {
Log.notice(F("WEB : Finish upload." CR)); Log.notice(F("WEB : Finish upload." CR));
if (uploadFile) { if (_uploadFile) {
uploadFile.close(); _uploadFile.close();
Log.notice(F("WEB : File uploaded %d bytes." CR), upload.totalSize); Log.notice(F("WEB : File uploaded %d bytes." CR), upload.totalSize);
} }
server->sendHeader("Location", "/"); _server->sendHeader("Location", "/");
server->send(303); _server->send(303);
} else { } else {
server->send(500, "text/plain", "Couldn't create file."); _server->send(500, "text/plain", "Couldn't create file.");
} }
LOG_PERF_STOP("webserver-api-upload-file"); LOG_PERF_STOP("webserver-api-upload-file");
} }
@ -179,18 +179,18 @@ void WebServer::webHandleUploadFile() {
// //
void WebServer::webHandleCalibrate() { void WebServer::webHandleCalibrate() {
LOG_PERF_START("webserver-api-calibrate"); LOG_PERF_START("webserver-api-calibrate");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/calibrate." CR)); Log.notice(F("WEB : webServer callback for /api/calibrate." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-calibrate"); LOG_PERF_STOP("webserver-api-calibrate");
return; return;
} }
myGyro.calibrateSensor(); myGyro.calibrateSensor();
server->send(200, "text/plain", "Device calibrated"); _server->send(200, "text/plain", "Device calibrated");
LOG_PERF_STOP("webserver-api-calibrate"); LOG_PERF_STOP("webserver-api-calibrate");
} }
@ -198,17 +198,17 @@ void WebServer::webHandleCalibrate() {
// Callback from webServer when / has been accessed. // Callback from webServer when / has been accessed.
// //
void WebServer::webHandleFactoryReset() { void WebServer::webHandleFactoryReset() {
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/factory." CR)); Log.notice(F("WEB : webServer callback for /api/factory." CR));
if (!id.compareTo(myConfig.getID())) { if (!id.compareTo(myConfig.getID())) {
server->send(200, "text/plain", "Doing reset..."); _server->send(200, "text/plain", "Doing reset...");
LittleFS.remove(CFG_FILENAME); LittleFS.remove(CFG_FILENAME);
LittleFS.end(); LittleFS.end();
delay(500); delay(500);
ESP.reset(); ESP.reset();
} else { } else {
server->send(400, "text/plain", "Unknown ID."); _server->send(400, "text/plain", "Unknown ID.");
} }
} }
@ -250,7 +250,7 @@ void WebServer::webHandleStatus() {
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str()); _server->send(200, "application/json", out.c_str());
LOG_PERF_STOP("webserver-api-status"); LOG_PERF_STOP("webserver-api-status");
} }
@ -258,17 +258,17 @@ void WebServer::webHandleStatus() {
// Callback from webServer when / has been accessed. // Callback from webServer when / has been accessed.
// //
void WebServer::webHandleClearWIFI() { void WebServer::webHandleClearWIFI() {
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/clearwifi." CR)); Log.notice(F("WEB : webServer callback for /api/clearwifi." CR));
if (!id.compareTo(myConfig.getID())) { if (!id.compareTo(myConfig.getID())) {
server->send(200, "text/plain", _server->send(200, "text/plain",
"Clearing WIFI credentials and doing reset..."); "Clearing WIFI credentials and doing reset...");
delay(1000); delay(1000);
WiFi.disconnect(); // Clear credentials WiFi.disconnect(); // Clear credentials
ESP.reset(); ESP.reset();
} else { } else {
server->send(400, "text/plain", "Unknown ID."); _server->send(400, "text/plain", "Unknown ID.");
} }
} }
@ -277,13 +277,13 @@ void WebServer::webHandleClearWIFI() {
// //
void WebServer::webHandleStatusSleepmode() { void WebServer::webHandleStatusSleepmode() {
LOG_PERF_START("webserver-api-sleepmode"); LOG_PERF_START("webserver-api-sleepmode");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/status/sleepmode." CR)); Log.notice(F("WEB : webServer callback for /api/status/sleepmode." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-sleepmode"); LOG_PERF_STOP("webserver-api-sleepmode");
return; return;
} }
@ -292,11 +292,11 @@ void WebServer::webHandleStatusSleepmode() {
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
#endif #endif
if (server->arg(CFG_PARAM_SLEEP_MODE).equalsIgnoreCase("true")) if (_server->arg(CFG_PARAM_SLEEP_MODE).equalsIgnoreCase("true"))
sleepModeAlwaysSkip = true; sleepModeAlwaysSkip = true;
else else
sleepModeAlwaysSkip = false; sleepModeAlwaysSkip = false;
server->send(200, "text/plain", "Sleep mode updated"); _server->send(200, "text/plain", "Sleep mode updated");
LOG_PERF_STOP("webserver-api-sleepmode"); LOG_PERF_STOP("webserver-api-sleepmode");
} }
@ -305,13 +305,13 @@ void WebServer::webHandleStatusSleepmode() {
// //
void WebServer::webHandleConfigDevice() { void WebServer::webHandleConfigDevice() {
LOG_PERF_START("webserver-api-config-device"); LOG_PERF_START("webserver-api-config-device");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/config/device." CR)); Log.notice(F("WEB : webServer callback for /api/config/device." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-device"); LOG_PERF_STOP("webserver-api-config-device");
return; return;
} }
@ -320,12 +320,12 @@ void WebServer::webHandleConfigDevice() {
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
#endif #endif
myConfig.setMDNS(server->arg(CFG_PARAM_MDNS).c_str()); myConfig.setMDNS(_server->arg(CFG_PARAM_MDNS).c_str());
myConfig.setTempFormat(server->arg(CFG_PARAM_TEMPFORMAT).charAt(0)); myConfig.setTempFormat(_server->arg(CFG_PARAM_TEMPFORMAT).charAt(0));
myConfig.setSleepInterval(server->arg(CFG_PARAM_SLEEP_INTERVAL).c_str()); myConfig.setSleepInterval(_server->arg(CFG_PARAM_SLEEP_INTERVAL).c_str());
myConfig.saveFile(); myConfig.saveFile();
server->sendHeader("Location", "/config.htm#collapseOne", true); _server->sendHeader("Location", "/config.htm#collapseOne", true);
server->send(302, "text/plain", "Device config updated"); _server->send(302, "text/plain", "Device config updated");
LOG_PERF_STOP("webserver-api-config-device"); LOG_PERF_STOP("webserver-api-config-device");
} }
@ -334,13 +334,13 @@ void WebServer::webHandleConfigDevice() {
// //
void WebServer::webHandleConfigPush() { void WebServer::webHandleConfigPush() {
LOG_PERF_START("webserver-api-config-push"); LOG_PERF_START("webserver-api-config-push");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/config/push." CR)); Log.notice(F("WEB : webServer callback for /api/config/push." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-push"); LOG_PERF_STOP("webserver-api-config-push");
return; return;
} }
@ -348,23 +348,23 @@ void WebServer::webHandleConfigPush() {
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
#endif #endif
myConfig.setHttpPushUrl(server->arg(CFG_PARAM_PUSH_HTTP).c_str()); myConfig.setHttpPushUrl(_server->arg(CFG_PARAM_PUSH_HTTP).c_str());
myConfig.setHttpPushUrl2(server->arg(CFG_PARAM_PUSH_HTTP2).c_str()); myConfig.setHttpPushUrl2(_server->arg(CFG_PARAM_PUSH_HTTP2).c_str());
myConfig.setBrewfatherPushUrl(server->arg(CFG_PARAM_PUSH_BREWFATHER).c_str()); myConfig.setBrewfatherPushUrl(_server->arg(CFG_PARAM_PUSH_BREWFATHER).c_str());
myConfig.setInfluxDb2PushUrl(server->arg(CFG_PARAM_PUSH_INFLUXDB2).c_str()); myConfig.setInfluxDb2PushUrl(_server->arg(CFG_PARAM_PUSH_INFLUXDB2).c_str());
myConfig.setInfluxDb2PushOrg( myConfig.setInfluxDb2PushOrg(
server->arg(CFG_PARAM_PUSH_INFLUXDB2_ORG).c_str()); _server->arg(CFG_PARAM_PUSH_INFLUXDB2_ORG).c_str());
myConfig.setInfluxDb2PushBucket( myConfig.setInfluxDb2PushBucket(
server->arg(CFG_PARAM_PUSH_INFLUXDB2_BUCKET).c_str()); _server->arg(CFG_PARAM_PUSH_INFLUXDB2_BUCKET).c_str());
myConfig.setInfluxDb2PushToken( myConfig.setInfluxDb2PushToken(
server->arg(CFG_PARAM_PUSH_INFLUXDB2_AUTH).c_str()); _server->arg(CFG_PARAM_PUSH_INFLUXDB2_AUTH).c_str());
myConfig.setMqttUrl(server->arg(CFG_PARAM_PUSH_MQTT).c_str()); myConfig.setMqttUrl(_server->arg(CFG_PARAM_PUSH_MQTT).c_str());
myConfig.setMqttTopic(server->arg(CFG_PARAM_PUSH_MQTT_TOPIC).c_str()); myConfig.setMqttTopic(_server->arg(CFG_PARAM_PUSH_MQTT_TOPIC).c_str());
myConfig.setMqttUser(server->arg(CFG_PARAM_PUSH_MQTT_USER).c_str()); myConfig.setMqttUser(_server->arg(CFG_PARAM_PUSH_MQTT_USER).c_str());
myConfig.setMqttPass(server->arg(CFG_PARAM_PUSH_MQTT_PASS).c_str()); myConfig.setMqttPass(_server->arg(CFG_PARAM_PUSH_MQTT_PASS).c_str());
myConfig.saveFile(); myConfig.saveFile();
server->sendHeader("Location", "/config.htm#collapseTwo", true); _server->sendHeader("Location", "/config.htm#collapseTwo", true);
server->send(302, "text/plain", "Push config updated"); _server->send(302, "text/plain", "Push config updated");
LOG_PERF_STOP("webserver-api-config-push"); LOG_PERF_STOP("webserver-api-config-push");
} }
@ -374,14 +374,14 @@ void WebServer::webHandleConfigPush() {
String WebServer::getRequestArguments() { String WebServer::getRequestArguments() {
String debug; String debug;
for (int i = 0; i < server->args(); i++) { for (int i = 0; i < _server->args(); i++) {
if (!server->argName(i).equals( if (!_server->argName(i).equals(
"plain")) { // this contains all the arguments, we dont need that. "plain")) { // this contains all the arguments, we dont need that.
if (debug.length()) debug += ", "; if (debug.length()) debug += ", ";
debug += server->argName(i); debug += _server->argName(i);
debug += "="; debug += "=";
debug += server->arg(i); debug += _server->arg(i);
} }
} }
return debug; return debug;
@ -392,13 +392,13 @@ String WebServer::getRequestArguments() {
// //
void WebServer::webHandleConfigGravity() { void WebServer::webHandleConfigGravity() {
LOG_PERF_START("webserver-api-config-gravity"); LOG_PERF_START("webserver-api-config-gravity");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/config/gravity." CR)); Log.notice(F("WEB : webServer callback for /api/config/gravity." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-gravity"); LOG_PERF_STOP("webserver-api-config-gravity");
return; return;
} }
@ -407,14 +407,14 @@ void WebServer::webHandleConfigGravity() {
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
#endif #endif
myConfig.setGravityFormat(server->arg(CFG_PARAM_GRAVITY_FORMAT).charAt(0)); myConfig.setGravityFormat(_server->arg(CFG_PARAM_GRAVITY_FORMAT).charAt(0));
myConfig.setGravityFormula(server->arg(CFG_PARAM_GRAVITY_FORMULA).c_str()); myConfig.setGravityFormula(_server->arg(CFG_PARAM_GRAVITY_FORMULA).c_str());
myConfig.setGravityTempAdj( myConfig.setGravityTempAdj(
server->arg(CFG_PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true _server->arg(CFG_PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true
: false); : false);
myConfig.saveFile(); myConfig.saveFile();
server->sendHeader("Location", "/config.htm#collapseThree", true); _server->sendHeader("Location", "/config.htm#collapseThree", true);
server->send(302, "text/plain", "Gravity config updated"); _server->send(302, "text/plain", "Gravity config updated");
LOG_PERF_STOP("webserver-api-config-gravity"); LOG_PERF_STOP("webserver-api-config-gravity");
} }
@ -423,13 +423,13 @@ void WebServer::webHandleConfigGravity() {
// //
void WebServer::webHandleConfigHardware() { void WebServer::webHandleConfigHardware() {
LOG_PERF_START("webserver-api-config-hardware"); LOG_PERF_START("webserver-api-config-hardware");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/config/hardware." CR)); Log.notice(F("WEB : webServer callback for /api/config/hardware." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-config-hardware"); LOG_PERF_STOP("webserver-api-config-hardware");
return; return;
} }
@ -438,18 +438,18 @@ void WebServer::webHandleConfigHardware() {
Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str());
#endif #endif
myConfig.setVoltageFactor(server->arg(CFG_PARAM_VOLTAGEFACTOR).toFloat()); myConfig.setVoltageFactor(_server->arg(CFG_PARAM_VOLTAGEFACTOR).toFloat());
if (myConfig.isTempC()) { if (myConfig.isTempC()) {
myConfig.setTempSensorAdjC(server->arg(CFG_PARAM_TEMP_ADJ)); myConfig.setTempSensorAdjC(_server->arg(CFG_PARAM_TEMP_ADJ));
} else { } else {
myConfig.setTempSensorAdjF(server->arg(CFG_PARAM_TEMP_ADJ)); myConfig.setTempSensorAdjF(_server->arg(CFG_PARAM_TEMP_ADJ));
} }
myConfig.setOtaURL(server->arg(CFG_PARAM_OTA).c_str()); myConfig.setOtaURL(_server->arg(CFG_PARAM_OTA).c_str());
myConfig.setGyroTemp( myConfig.setGyroTemp(
server->arg(CFG_PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false); _server->arg(CFG_PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false);
myConfig.saveFile(); myConfig.saveFile();
server->sendHeader("Location", "/config.htm#collapseFour", true); _server->sendHeader("Location", "/config.htm#collapseFour", true);
server->send(302, "text/plain", "Hardware config updated"); _server->send(302, "text/plain", "Hardware config updated");
LOG_PERF_STOP("webserver-api-config-hardware"); LOG_PERF_STOP("webserver-api-config-hardware");
} }
@ -473,7 +473,7 @@ void WebServer::webHandleFormulaRead() {
doc[CFG_PARAM_GRAVITY_FORMULA] = ""; doc[CFG_PARAM_GRAVITY_FORMULA] = "";
doc[CFG_PARAM_ERROR] = ""; doc[CFG_PARAM_ERROR] = "";
switch (lastFormulaCreateError) { switch (_lastFormulaCreateError) {
case ERR_FORMULA_INTERNAL: case ERR_FORMULA_INTERNAL:
doc[CFG_PARAM_ERROR] = "Internal error creating formula."; doc[CFG_PARAM_ERROR] = "Internal error creating formula.";
break; break;
@ -516,7 +516,7 @@ void WebServer::webHandleFormulaRead() {
String out; String out;
serializeJson(doc, out); serializeJson(doc, out);
server->send(200, "application/json", out.c_str()); _server->send(200, "application/json", out.c_str());
LOG_PERF_STOP("webserver-api-formula-read"); LOG_PERF_STOP("webserver-api-formula-read");
} }
@ -525,13 +525,13 @@ void WebServer::webHandleFormulaRead() {
// //
void WebServer::webHandleFormulaWrite() { void WebServer::webHandleFormulaWrite() {
LOG_PERF_START("webserver-api-formula-write"); LOG_PERF_START("webserver-api-formula-write");
String id = server->arg(CFG_PARAM_ID); String id = _server->arg(CFG_PARAM_ID);
Log.notice(F("WEB : webServer callback for /api/formula/post." CR)); Log.notice(F("WEB : webServer callback for /api/formula/post." CR));
if (!id.equalsIgnoreCase(myConfig.getID())) { if (!id.equalsIgnoreCase(myConfig.getID())) {
Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(), Log.error(F("WEB : Wrong ID received %s, expected %s" CR), id.c_str(),
myConfig.getID()); myConfig.getID());
server->send(400, "text/plain", "Invalid ID."); _server->send(400, "text/plain", "Invalid ID.");
LOG_PERF_STOP("webserver-api-formula-write"); LOG_PERF_STOP("webserver-api-formula-write");
return; return;
} }
@ -541,24 +541,24 @@ void WebServer::webHandleFormulaWrite() {
#endif #endif
RawFormulaData fd; RawFormulaData fd;
fd.a[0] = server->arg("a1").toDouble(); fd.a[0] = _server->arg("a1").toDouble();
fd.a[1] = server->arg("a2").toDouble(); fd.a[1] = _server->arg("a2").toDouble();
fd.a[2] = server->arg("a3").toDouble(); fd.a[2] = _server->arg("a3").toDouble();
fd.a[3] = server->arg("a4").toDouble(); fd.a[3] = _server->arg("a4").toDouble();
fd.a[4] = server->arg("a5").toDouble(); fd.a[4] = _server->arg("a5").toDouble();
if (myConfig.isGravityPlato()) { if (myConfig.isGravityPlato()) {
fd.g[0] = convertToSG(server->arg("g1").toDouble()); fd.g[0] = convertToSG(_server->arg("g1").toDouble());
fd.g[1] = convertToSG(server->arg("g2").toDouble()); fd.g[1] = convertToSG(_server->arg("g2").toDouble());
fd.g[2] = convertToSG(server->arg("g3").toDouble()); fd.g[2] = convertToSG(_server->arg("g3").toDouble());
fd.g[3] = convertToSG(server->arg("g4").toDouble()); fd.g[3] = convertToSG(_server->arg("g4").toDouble());
fd.g[4] = convertToSG(server->arg("g5").toDouble()); fd.g[4] = convertToSG(_server->arg("g5").toDouble());
} else { } else {
fd.g[0] = server->arg("g1").toDouble(); fd.g[0] = _server->arg("g1").toDouble();
fd.g[1] = server->arg("g2").toDouble(); fd.g[1] = _server->arg("g2").toDouble();
fd.g[2] = server->arg("g3").toDouble(); fd.g[2] = _server->arg("g3").toDouble();
fd.g[3] = server->arg("g4").toDouble(); fd.g[3] = _server->arg("g4").toDouble();
fd.g[4] = server->arg("g5").toDouble(); fd.g[4] = _server->arg("g5").toDouble();
} }
myConfig.setFormulaData(fd); myConfig.setFormulaData(fd);
@ -585,17 +585,17 @@ void WebServer::webHandleFormulaWrite() {
Log.error( Log.error(
F("WEB : Unable to find formula based on provided values err=%d." CR), F("WEB : Unable to find formula based on provided values err=%d." CR),
e); e);
lastFormulaCreateError = e; _lastFormulaCreateError = e;
} else { } else {
// Save the formula as succesful // Save the formula as succesful
Log.info(F("WEB : Found valid formula: '%s'" CR), &buf[0]); Log.info(F("WEB : Found valid formula: '%s'" CR), &buf[0]);
myConfig.setGravityFormula(buf); myConfig.setGravityFormula(buf);
lastFormulaCreateError = 0; _lastFormulaCreateError = 0;
} }
myConfig.saveFile(); myConfig.saveFile();
server->sendHeader("Location", "/calibration.htm", true); _server->sendHeader("Location", "/calibration.htm", true);
server->send(302, "text/plain", "Formula updated"); _server->send(302, "text/plain", "Formula updated");
LOG_PERF_STOP("webserver-api-formula-write"); LOG_PERF_STOP("webserver-api-formula-write");
} }
@ -641,8 +641,8 @@ bool WebServer::checkHtmlFile(HtmlFile item) {
// Handler for page not found // Handler for page not found
// //
void WebServer::webHandlePageNotFound() { void WebServer::webHandlePageNotFound() {
Log.error(F("WEB : URL not found %s received." CR), server->uri().c_str()); Log.error(F("WEB : URL not found %s received." CR), _server->uri().c_str());
server->send(404, "text/plain", F("URL not found")); _server->send(404, "text/plain", F("URL not found"));
} }
// //
@ -651,20 +651,20 @@ void WebServer::webHandlePageNotFound() {
bool WebServer::setupWebServer() { bool WebServer::setupWebServer() {
Log.notice(F("WEB : Configuring web server." CR)); Log.notice(F("WEB : Configuring web server." CR));
server = new ESP8266WebServer(); _server = new ESP8266WebServer();
MDNS.begin(myConfig.getMDNS()); MDNS.begin(myConfig.getMDNS());
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
// Static content // Static content
#if defined(EMBED_HTML) #if defined(EMBED_HTML)
server->on("/", std::bind(&WebServer::webReturnIndexHtm, this)); _server->on("/", std::bind(&WebServer::webReturnIndexHtm, this));
server->on("/index.htm", std::bind(&WebServer::webReturnIndexHtm, this)); _server->on("/index.htm", std::bind(&WebServer::webReturnIndexHtm, this));
server->on("/device.htm", std::bind(&WebServer::webReturnDeviceHtm, this)); _server->on("/device.htm", std::bind(&WebServer::webReturnDeviceHtm, this));
server->on("/config.htm", std::bind(&WebServer::webReturnConfigHtm, this)); _server->on("/config.htm", std::bind(&WebServer::webReturnConfigHtm, this));
server->on("/calibration.htm", _server->on("/calibration.htm",
std::bind(&WebServer::webReturnCalibrationHtm, this)); std::bind(&WebServer::webReturnCalibrationHtm, this));
server->on("/about.htm", std::bind(&WebServer::webReturnAboutHtm, this)); _server->on("/about.htm", std::bind(&WebServer::webReturnAboutHtm, this));
#else #else
// Show files in the filessytem at startup // Show files in the filessytem at startup
@ -685,69 +685,69 @@ bool WebServer::setupWebServer() {
checkHtmlFile(HTML_ABOUT)) { checkHtmlFile(HTML_ABOUT)) {
Log.notice(F("WEB : All html files exist, starting in normal mode." CR)); Log.notice(F("WEB : All html files exist, starting in normal mode." CR));
server->serveStatic("/", LittleFS, "/index.min.htm"); _server->serveStatic("/", LittleFS, "/index.min.htm");
server->serveStatic("/index.htm", LittleFS, "/index.min.htm"); _server->serveStatic("/index.htm", LittleFS, "/index.min.htm");
server->serveStatic("/device.htm", LittleFS, "/device.min.htm"); _server->serveStatic("/device.htm", LittleFS, "/device.min.htm");
server->serveStatic("/config.htm", LittleFS, "/config.min.htm"); _server->serveStatic("/config.htm", LittleFS, "/config.min.htm");
server->serveStatic("/about.htm", LittleFS, "/about.min.htm"); _server->serveStatic("/about.htm", LittleFS, "/about.min.htm");
server->serveStatic("/calibration.htm", LittleFS, "/calibration.min.htm"); _server->serveStatic("/calibration.htm", LittleFS, "/calibration.min.htm");
// Also add the static upload view in case we we have issues that needs to // Also add the static upload view in case we we have issues that needs to
// be fixed. // be fixed.
server->on("/upload.htm", std::bind(&WebServer::webReturnUploadHtm, this)); _server->on("/upload.htm", std::bind(&WebServer::webReturnUploadHtm, this));
} else { } else {
Log.error(F("WEB : Missing html files, starting with upload UI." CR)); Log.error(F("WEB : Missing html files, starting with upload UI." CR));
server->on("/", std::bind(&WebServer::webReturnUploadHtm, this)); _server->on("/", std::bind(&WebServer::webReturnUploadHtm, this));
} }
#endif #endif
// Dynamic content // Dynamic content
server->on("/api/config", HTTP_GET, _server->on("/api/config", HTTP_GET,
std::bind(&WebServer::webHandleConfig, this)); // Get config.json std::bind(&WebServer::webHandleConfig, this)); // Get config.json
server->on("/api/device", HTTP_GET, _server->on("/api/device", HTTP_GET,
std::bind(&WebServer::webHandleDevice, this)); // Get device.json std::bind(&WebServer::webHandleDevice, this)); // Get device.json
server->on("/api/formula", HTTP_GET, _server->on("/api/formula", HTTP_GET,
std::bind(&WebServer::webHandleFormulaRead, std::bind(&WebServer::webHandleFormulaRead,
this)); // Get formula.json (calibration page) this)); // Get formula.json (calibration page)
server->on("/api/formula", HTTP_POST, _server->on("/api/formula", HTTP_POST,
std::bind(&WebServer::webHandleFormulaWrite, std::bind(&WebServer::webHandleFormulaWrite,
this)); // Get formula.json (calibration page) this)); // Get formula.json (calibration page)
server->on("/api/calibrate", HTTP_POST, _server->on("/api/calibrate", HTTP_POST,
std::bind(&WebServer::webHandleCalibrate, std::bind(&WebServer::webHandleCalibrate,
this)); // Run calibration routine (param id) this)); // Run calibration routine (param id)
server->on( _server->on(
"/api/factory", HTTP_GET, "/api/factory", HTTP_GET,
std::bind(&WebServer::webHandleFactoryReset, this)); // Reset the device std::bind(&WebServer::webHandleFactoryReset, this)); // Reset the device
server->on( _server->on(
"/api/status", HTTP_GET, "/api/status", HTTP_GET,
std::bind(&WebServer::webHandleStatus, this)); // Get the status.json std::bind(&WebServer::webHandleStatus, this)); // Get the status.json
server->on( _server->on(
"/api/clearwifi", HTTP_GET, "/api/clearwifi", HTTP_GET,
std::bind(&WebServer::webHandleClearWIFI, this)); // Clear wifi settings std::bind(&WebServer::webHandleClearWIFI, this)); // Clear wifi settings
server->on("/api/upload", HTTP_GET, _server->on("/api/upload", HTTP_GET,
std::bind(&WebServer::webHandleUpload, this)); // Get upload.json std::bind(&WebServer::webHandleUpload, this)); // Get upload.json
server->on( _server->on(
"/api/upload", HTTP_POST, std::bind(&WebServer::webReturnOK, this), "/api/upload", HTTP_POST, std::bind(&WebServer::webReturnOK, this),
std::bind(&WebServer::webHandleUploadFile, this)); // File upload data std::bind(&WebServer::webHandleUploadFile, this)); // File upload data
server->on("/api/status/sleepmode", HTTP_POST, _server->on("/api/status/sleepmode", HTTP_POST,
std::bind(&WebServer::webHandleStatusSleepmode, std::bind(&WebServer::webHandleStatusSleepmode,
this)); // Change sleep mode this)); // Change sleep mode
server->on("/api/config/device", HTTP_POST, _server->on("/api/config/device", HTTP_POST,
std::bind(&WebServer::webHandleConfigDevice, std::bind(&WebServer::webHandleConfigDevice,
this)); // Change device settings this)); // Change device settings
server->on("/api/config/push", HTTP_POST, _server->on("/api/config/push", HTTP_POST,
std::bind(&WebServer::webHandleConfigPush, std::bind(&WebServer::webHandleConfigPush,
this)); // Change push settings this)); // Change push settings
server->on("/api/config/gravity", HTTP_POST, _server->on("/api/config/gravity", HTTP_POST,
std::bind(&WebServer::webHandleConfigGravity, std::bind(&WebServer::webHandleConfigGravity,
this)); // Change gravity settings this)); // Change gravity settings
server->on("/api/config/hardware", HTTP_POST, _server->on("/api/config/hardware", HTTP_POST,
std::bind(&WebServer::webHandleConfigHardware, std::bind(&WebServer::webHandleConfigHardware,
this)); // Change hardware settings this)); // Change hardware settings
server->onNotFound(std::bind(&WebServer::webHandlePageNotFound, this)); _server->onNotFound(std::bind(&WebServer::webHandlePageNotFound, this));
server->begin(); _server->begin();
Log.notice(F("WEB : Web server started." CR)); Log.notice(F("WEB : Web server started." CR));
return true; return true;
} }
@ -757,7 +757,7 @@ bool WebServer::setupWebServer() {
// //
void WebServer::loop() { void WebServer::loop() {
MDNS.update(); MDNS.update();
server->handleClient(); _server->handleClient();
} }
// EOF // EOF

View File

@ -44,9 +44,9 @@ INCBIN_EXTERN(UploadHtm);
// classes // classes
class WebServer { class WebServer {
private: private:
ESP8266WebServer* server = 0; ESP8266WebServer* _server = 0;
File uploadFile; File _uploadFile;
int lastFormulaCreateError = 0; int _lastFormulaCreateError = 0;
void webHandleConfig(); void webHandleConfig();
void webHandleFormulaWrite(); void webHandleFormulaWrite();
@ -68,29 +68,29 @@ class WebServer {
String getRequestArguments(); String getRequestArguments();
// Inline functions. // Inline functions.
void webReturnOK() { server->send(200); } void webReturnOK() { _server->send(200); }
#if defined(EMBED_HTML) #if defined(EMBED_HTML)
void webReturnIndexHtm() { void webReturnIndexHtm() {
server->send_P(200, "text/html", (const char*)gIndexHtmData, gIndexHtmSize); _server->send_P(200, "text/html", (const char*)gIndexHtmData, gIndexHtmSize);
} }
void webReturnDeviceHtm() { void webReturnDeviceHtm() {
server->send_P(200, "text/html", (const char*)gDeviceHtmData, _server->send_P(200, "text/html", (const char*)gDeviceHtmData,
gDeviceHtmSize); gDeviceHtmSize);
} }
void webReturnConfigHtm() { void webReturnConfigHtm() {
server->send_P(200, "text/html", (const char*)gConfigHtmData, _server->send_P(200, "text/html", (const char*)gConfigHtmData,
gConfigHtmSize); gConfigHtmSize);
} }
void webReturnCalibrationHtm() { void webReturnCalibrationHtm() {
server->send_P(200, "text/html", (const char*)gCalibrationHtmData, _server->send_P(200, "text/html", (const char*)gCalibrationHtmData,
gCalibrationHtmSize); gCalibrationHtmSize);
} }
void webReturnAboutHtm() { void webReturnAboutHtm() {
server->send_P(200, "text/html", (const char*)gAboutHtmData, gAboutHtmSize); _server->send_P(200, "text/html", (const char*)gAboutHtmData, gAboutHtmSize);
} }
#else #else
void webReturnUploadHtm() { void webReturnUploadHtm() {
server->send_P(200, "text/html", (const char*)gUploadHtmData, _server->send_P(200, "text/html", (const char*)gUploadHtmData,
gUploadHtmSize); gUploadHtmSize);
} }
#endif #endif

View File

@ -224,7 +224,7 @@ bool WifiConnection::disconnect() {
// //
// //
bool WifiConnection::updateFirmware() { bool WifiConnection::updateFirmware() {
if (!newFirmware) { if (!_newFirmware) {
Log.notice(F("WIFI: No newer version exist, skipping update." CR)); Log.notice(F("WIFI: No newer version exist, skipping update." CR));
return false; return false;
} }
@ -345,19 +345,19 @@ bool WifiConnection::checkFirmwareVersion() {
curVer[2]); curVer[2]);
#endif #endif
// Compare major version // Compare major version
if (newVer[0] > curVer[0]) newFirmware = true; if (newVer[0] > curVer[0]) _newFirmware = true;
// Compare minor version // Compare minor version
if (newVer[0] == curVer[0] && newVer[1] > curVer[1]) if (newVer[0] == curVer[0] && newVer[1] > curVer[1])
newFirmware = true; _newFirmware = true;
// Compare patch version // Compare patch version
if (newVer[0] == curVer[0] && newVer[1] == curVer[1] && if (newVer[0] == curVer[0] && newVer[1] == curVer[1] &&
newVer[2] > curVer[2]) newVer[2] > curVer[2])
newFirmware = true; _newFirmware = true;
} }
} }
// Download new html files to filesystem if they are present. // Download new html files to filesystem if they are present.
if (!ver["html"].isNull() && newFirmware) { if (!ver["html"].isNull() && _newFirmware) {
Log.notice(F("WIFI: OTA downloading new html files." CR)); Log.notice(F("WIFI: OTA downloading new html files." CR));
JsonArray htmlFiles = ver["html"].as<JsonArray>(); JsonArray htmlFiles = ver["html"].as<JsonArray>();
for (JsonVariant v : htmlFiles) { for (JsonVariant v : htmlFiles) {
@ -377,9 +377,9 @@ bool WifiConnection::checkFirmwareVersion() {
myWifi.closeWifiClient(); myWifi.closeWifiClient();
#if LOG_LEVEL == 6 #if LOG_LEVEL == 6
Log.verbose(F("WIFI: OTA found new version %s." CR), Log.verbose(F("WIFI: OTA found new version %s." CR),
newFirmware ? "true" : "false"); _newFirmware ? "true" : "false");
#endif #endif
return newFirmware; return _newFirmware;
} }
// //

View File

@ -41,7 +41,7 @@ class WifiConnection {
WiFiClientSecure _secureClient; WiFiClientSecure _secureClient;
// OTA // OTA
bool newFirmware = false; bool _newFirmware = false;
bool parseFirmwareVersionString(int (&num)[3], const char* version); bool parseFirmwareVersionString(int (&num)[3], const char* version);
void downloadFile(const char* fname); void downloadFile(const char* fname);
void connectAsync(); void connectAsync();