diff --git a/src/calc.cpp b/src/calc.cpp index 48ee0ed..7f0fba0 100644 --- a/src/calc.cpp +++ b/src/calc.cpp @@ -25,9 +25,7 @@ SOFTWARE. #include #include -#include -#include -#include +#include #define FORMULA_MAX_DEVIATION 1.6 diff --git a/src/calc.hpp b/src/calc.hpp index 854d39d..ba795fc 100644 --- a/src/calc.hpp +++ b/src/calc.hpp @@ -24,14 +24,12 @@ SOFTWARE. #ifndef SRC_CALC_HPP_ #define SRC_CALC_HPP_ -// Includes #include #define ERR_FORMULA_NOTENOUGHVALUES -1 #define ERR_FORMULA_INTERNAL -2 #define ERR_FORMULA_UNABLETOFFIND -3 -// Functions double calculateGravity(double angle, double tempC, const char *tempFormula = 0); double gravityTemperatureCorrectionC(double gravity, double tempC, diff --git a/src/config.cpp b/src/config.cpp index eea679a..531a85e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -21,10 +21,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include - #include -#include +#include Config myConfig; diff --git a/src/config.hpp b/src/config.hpp index d7c6c71..9763349 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -24,14 +24,8 @@ SOFTWARE. #ifndef SRC_CONFIG_HPP_ #define SRC_CONFIG_HPP_ -// Includes -#include -#include -#include - #include -// defintions #define CFG_JSON_BUFSIZE 3192 #define CFG_APPNAME "GravityMon " // Name of firmware @@ -43,7 +37,6 @@ SOFTWARE. #define WIFI_PORTAL_TIMEOUT \ 120 // Number of seconds until the config portal is closed -// These are used in API + Savefile #define CFG_PARAM_ID "id" #define CFG_PARAM_MDNS "mdns" // Device name #define CFG_PARAM_OTA "ota-url" @@ -79,7 +72,6 @@ SOFTWARE. #define CFG_PARAM_FORMULA_DATA \ "formula-calculation-data" // Raw data for the formula calculation -// These are used in API's #define CFG_PARAM_APP_NAME "app-name" #define CFG_PARAM_APP_VER "app-ver" #define CFG_PARAM_ANGLE "angle" @@ -110,7 +102,6 @@ struct RawFormulaData { double g[5]; }; -// Main configuration class class Config { private: bool _saveNeeded; @@ -348,7 +339,6 @@ class Config { void setSaveNeeded() { _saveNeeded = true; } }; -// Global instance created extern Config myConfig; #endif // SRC_CONFIG_HPP_ diff --git a/src/gyro.cpp b/src/gyro.cpp index 41a10f4..cf696b9 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include -#include +#include GyroSensor myGyro; MPU6050 accelgyro; @@ -46,7 +46,7 @@ bool GyroSensor::setup() { Wire.begin(D3, D4); Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having // compilation difficulties - + if (!accelgyro.testConnection()) { Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR)); _sensorConnected = false; @@ -260,7 +260,8 @@ bool GyroSensor::read() { // 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 - if (_initialSensorTemp == INVALID_TEMPERATURE) _initialSensorTemp = _sensorTemp; + if (_initialSensorTemp == INVALID_TEMPERATURE) + _initialSensorTemp = _sensorTemp; return _validValue; } diff --git a/src/gyro.hpp b/src/gyro.hpp index 287ce37..72153ad 100644 --- a/src/gyro.hpp +++ b/src/gyro.hpp @@ -27,13 +27,10 @@ SOFTWARE. #define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE // #define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_SBWIRE -// Includes -#include #include #include -// Classes struct RawGyroDataL { // Used for average multiple readings int32_t ax; // Raw Acceleration int32_t ay; @@ -80,7 +77,6 @@ class GyroSensor { void enterSleep(); }; -// Global instance created extern GyroSensor myGyro; #endif // SRC_GYRO_HPP_ diff --git a/src/helper.cpp b/src/helper.cpp index b64efa2..4cc7173 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -24,8 +24,10 @@ SOFTWARE. #include #include +#include #include #include +#include #include #include diff --git a/src/helper.hpp b/src/helper.hpp index aa88cdb..bbabaab 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -25,7 +25,7 @@ SOFTWARE. #define SRC_HELPER_HPP_ // Includes -#include +#include // Sleep mode void deepSleep(int t); diff --git a/src/main.cpp b/src/main.cpp index 34fba25..3400d7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,12 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include - #include #include #include #include +#include #include #include #include diff --git a/src/main.hpp b/src/main.hpp new file mode 100644 index 0000000..ff15bbb --- /dev/null +++ b/src/main.hpp @@ -0,0 +1,33 @@ +/* +MIT License + +Copyright (c) 2021-22 Magnus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ +#ifndef SRC_MAIN_HPP_ +#define SRC_MAIN_HPP_ + +#include +#include +#include +#include +#include + +#endif // SRC_MAIN_HPP_ diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index b6f97b7..62c12e8 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -25,7 +25,8 @@ SOFTWARE. #include #include -#include +#include +#include #include #include diff --git a/src/pushtarget.hpp b/src/pushtarget.hpp index df2b302..c77fab6 100644 --- a/src/pushtarget.hpp +++ b/src/pushtarget.hpp @@ -24,13 +24,6 @@ SOFTWARE. #ifndef SRC_PUSHTARGET_HPP_ #define SRC_PUSHTARGET_HPP_ -// Includes -#include -#include - -#include - -// Classes class PushTarget { private: uint32_t _ms; // Used to check that we do not post to often diff --git a/src/tempsensor.cpp b/src/tempsensor.cpp index 5a5a191..9eeeb3a 100644 --- a/src/tempsensor.cpp +++ b/src/tempsensor.cpp @@ -27,7 +27,7 @@ SOFTWARE. #include #include -#include +#include #include OneWire myOneWire(D6); diff --git a/src/tempsensor.hpp b/src/tempsensor.hpp index 968a615..fbb210f 100644 --- a/src/tempsensor.hpp +++ b/src/tempsensor.hpp @@ -24,9 +24,6 @@ SOFTWARE. #ifndef SRC_TEMPSENSOR_HPP_ #define SRC_TEMPSENSOR_HPP_ -// definitions - -// classes class TempSensor { private: bool _hasSensor = false; @@ -41,7 +38,6 @@ class TempSensor { } }; -// Global instance created extern TempSensor myTempSensor; #endif // SRC_TEMPSENSOR_HPP_ diff --git a/src/webserver.cpp b/src/webserver.cpp index 2a368f1..82bf561 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -21,15 +21,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include - #include #include #include #include +#include #include #include +#include WebServer myWebServer; // My wrapper class fr webserver functions extern bool sleepModeActive; @@ -263,7 +262,7 @@ void WebServer::webHandleClearWIFI() { if (!id.compareTo(myConfig.getID())) { _server->send(200, "text/plain", - "Clearing WIFI credentials and doing reset..."); + "Clearing WIFI credentials and doing reset..."); delay(1000); WiFi.disconnect(); // Clear credentials ESP.reset(); @@ -350,7 +349,8 @@ void WebServer::webHandleConfigPush() { myConfig.setHttpPushUrl(_server->arg(CFG_PARAM_PUSH_HTTP).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.setInfluxDb2PushOrg( _server->arg(CFG_PARAM_PUSH_INFLUXDB2_ORG).c_str()); @@ -411,7 +411,7 @@ void WebServer::webHandleConfigGravity() { myConfig.setGravityFormula(_server->arg(CFG_PARAM_GRAVITY_FORMULA).c_str()); myConfig.setGravityTempAdj( _server->arg(CFG_PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true - : false); + : false); myConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseThree", true); _server->send(302, "text/plain", "Gravity config updated"); @@ -663,7 +663,7 @@ bool WebServer::setupWebServer() { _server->on("/device.htm", std::bind(&WebServer::webReturnDeviceHtm, this)); _server->on("/config.htm", std::bind(&WebServer::webReturnConfigHtm, this)); _server->on("/calibration.htm", - std::bind(&WebServer::webReturnCalibrationHtm, this)); + std::bind(&WebServer::webReturnCalibrationHtm, this)); _server->on("/about.htm", std::bind(&WebServer::webReturnAboutHtm, this)); #else // Show files in the filessytem at startup @@ -703,18 +703,18 @@ bool WebServer::setupWebServer() { // Dynamic content _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, - std::bind(&WebServer::webHandleDevice, this)); // Get device.json + std::bind(&WebServer::webHandleDevice, this)); // Get device.json _server->on("/api/formula", HTTP_GET, - std::bind(&WebServer::webHandleFormulaRead, - this)); // Get formula.json (calibration page) + std::bind(&WebServer::webHandleFormulaRead, + this)); // Get formula.json (calibration page) _server->on("/api/formula", HTTP_POST, - std::bind(&WebServer::webHandleFormulaWrite, - this)); // Get formula.json (calibration page) + std::bind(&WebServer::webHandleFormulaWrite, + this)); // Get formula.json (calibration page) _server->on("/api/calibrate", HTTP_POST, - std::bind(&WebServer::webHandleCalibrate, - this)); // Run calibration routine (param id) + std::bind(&WebServer::webHandleCalibrate, + this)); // Run calibration routine (param id) _server->on( "/api/factory", HTTP_GET, std::bind(&WebServer::webHandleFactoryReset, this)); // Reset the device @@ -725,26 +725,26 @@ bool WebServer::setupWebServer() { "/api/clearwifi", HTTP_GET, std::bind(&WebServer::webHandleClearWIFI, this)); // Clear wifi settings _server->on("/api/upload", HTTP_GET, - std::bind(&WebServer::webHandleUpload, this)); // Get upload.json + std::bind(&WebServer::webHandleUpload, this)); // Get upload.json _server->on( "/api/upload", HTTP_POST, std::bind(&WebServer::webReturnOK, this), std::bind(&WebServer::webHandleUploadFile, this)); // File upload data _server->on("/api/status/sleepmode", HTTP_POST, - std::bind(&WebServer::webHandleStatusSleepmode, - this)); // Change sleep mode + std::bind(&WebServer::webHandleStatusSleepmode, + this)); // Change sleep mode _server->on("/api/config/device", HTTP_POST, - std::bind(&WebServer::webHandleConfigDevice, - this)); // Change device settings + std::bind(&WebServer::webHandleConfigDevice, + this)); // Change device settings _server->on("/api/config/push", HTTP_POST, - std::bind(&WebServer::webHandleConfigPush, - this)); // Change push settings + std::bind(&WebServer::webHandleConfigPush, + this)); // Change push settings _server->on("/api/config/gravity", HTTP_POST, - std::bind(&WebServer::webHandleConfigGravity, - this)); // Change gravity settings + std::bind(&WebServer::webHandleConfigGravity, + this)); // Change gravity settings _server->on("/api/config/hardware", HTTP_POST, - std::bind(&WebServer::webHandleConfigHardware, - this)); // Change hardware settings + std::bind(&WebServer::webHandleConfigHardware, + this)); // Change hardware settings _server->onNotFound(std::bind(&WebServer::webHandlePageNotFound, this)); _server->begin(); diff --git a/src/webserver.hpp b/src/webserver.hpp index 4208aa6..3c31d8f 100644 --- a/src/webserver.hpp +++ b/src/webserver.hpp @@ -24,13 +24,11 @@ SOFTWARE. #ifndef SRC_WEBSERVER_HPP_ #define SRC_WEBSERVER_HPP_ -// Include #include #include #include #include -// Binary resouces #if defined(EMBED_HTML) INCBIN_EXTERN(IndexHtm); INCBIN_EXTERN(DeviceHtm); @@ -41,7 +39,6 @@ INCBIN_EXTERN(AboutHtm); INCBIN_EXTERN(UploadHtm); #endif -// classes class WebServer { private: ESP8266WebServer* _server = 0; @@ -71,27 +68,29 @@ class WebServer { void webReturnOK() { _server->send(200); } #if defined(EMBED_HTML) void webReturnIndexHtm() { - _server->send_P(200, "text/html", (const char*)gIndexHtmData, gIndexHtmSize); + _server->send_P(200, "text/html", (const char*)gIndexHtmData, + gIndexHtmSize); } void webReturnDeviceHtm() { _server->send_P(200, "text/html", (const char*)gDeviceHtmData, - gDeviceHtmSize); + gDeviceHtmSize); } void webReturnConfigHtm() { _server->send_P(200, "text/html", (const char*)gConfigHtmData, - gConfigHtmSize); + gConfigHtmSize); } void webReturnCalibrationHtm() { _server->send_P(200, "text/html", (const char*)gCalibrationHtmData, - gCalibrationHtmSize); + gCalibrationHtmSize); } void webReturnAboutHtm() { - _server->send_P(200, "text/html", (const char*)gAboutHtmData, gAboutHtmSize); + _server->send_P(200, "text/html", (const char*)gAboutHtmData, + gAboutHtmSize); } #else void webReturnUploadHtm() { _server->send_P(200, "text/html", (const char*)gUploadHtmData, - gUploadHtmSize); + gUploadHtmSize); } #endif diff --git a/src/wifi.cpp b/src/wifi.cpp index 5d238d2..b24f156 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -26,12 +26,8 @@ SOFTWARE. #include #include -#include -#include #include -#include -#include -#include +#include #include // Settings for DRD diff --git a/src/wifi.hpp b/src/wifi.hpp index 8a893fe..67ba59a 100644 --- a/src/wifi.hpp +++ b/src/wifi.hpp @@ -24,8 +24,6 @@ SOFTWARE. #ifndef SRC_WIFI_HPP_ #define SRC_WIFI_HPP_ -// Include -#include #include // tcp cleanup, to avoid memory crash. @@ -33,7 +31,6 @@ struct tcp_pcb; extern struct tcp_pcb* tcp_tw_pcbs; extern "C" void tcp_abort(struct tcp_pcb* pcb); -// classes class WifiConnection { private: // WIFI