Refactored includes

This commit is contained in:
Magnus Persson 2022-01-19 19:08:16 +01:00
parent 37a1ca6058
commit 35f66e0458
18 changed files with 81 additions and 84 deletions

View File

@ -25,9 +25,7 @@ SOFTWARE.
#include <tinyexpr.h>
#include <calc.hpp>
#include <config.hpp>
#include <helper.hpp>
#include <tempsensor.hpp>
#include <main.hpp>
#define FORMULA_MAX_DEVIATION 1.6

View File

@ -24,14 +24,12 @@ SOFTWARE.
#ifndef SRC_CALC_HPP_
#define SRC_CALC_HPP_
// Includes
#include <config.hpp>
#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,

View File

@ -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 <LittleFS.h>
#include <config.hpp>
#include <helper.hpp>
#include <main.hpp>
Config myConfig;

View File

@ -24,14 +24,8 @@ SOFTWARE.
#ifndef SRC_CONFIG_HPP_
#define SRC_CONFIG_HPP_
// Includes
#include <Arduino.h>
#include <ArduinoJson.h>
#include <stdlib.h>
#include <helper.hpp>
// 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_

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
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;
}

View File

@ -27,13 +27,10 @@ SOFTWARE.
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE
// #define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_SBWIRE
// Includes
#include <Arduino.h>
#include <MPU6050.h>
#include <config.hpp>
// 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_

View File

@ -24,8 +24,10 @@ SOFTWARE.
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
#include <tempsensor.hpp>
#include <wifi.hpp>

View File

@ -25,7 +25,7 @@ SOFTWARE.
#define SRC_HELPER_HPP_
// Includes
#include <ArduinoLog.h>
#include <main.hpp>
// Sleep mode
void deepSleep(int t);

View File

@ -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 <LittleFS.h>
#include <calc.hpp>
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
#include <pushtarget.hpp>
#include <tempsensor.hpp>
#include <webserver.hpp>

33
src/main.hpp Normal file
View File

@ -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 <Arduino.h>
#include <ArduinoJson.h>
#include <ArduinoLog.h>
#include <LittleFS.h>
#include <stdlib.h>
#endif // SRC_MAIN_HPP_

View File

@ -25,7 +25,8 @@ SOFTWARE.
#include <MQTT.h>
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
#include <pushtarget.hpp>
#include <wifi.hpp>

View File

@ -24,13 +24,6 @@ SOFTWARE.
#ifndef SRC_PUSHTARGET_HPP_
#define SRC_PUSHTARGET_HPP_
// Includes
#include <Arduino.h>
#include <ArduinoJson.h>
#include <helper.hpp>
// Classes
class PushTarget {
private:
uint32_t _ms; // Used to check that we do not post to often

View File

@ -27,7 +27,7 @@ SOFTWARE.
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
#include <tempsensor.hpp>
OneWire myOneWire(D6);

View File

@ -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_

View File

@ -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 <ArduinoJson.h>
#include <LittleFS.h>
#include <calc.hpp>
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <main.hpp>
#include <tempsensor.hpp>
#include <webserver.hpp>
#include <wifi.hpp>
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();

View File

@ -24,13 +24,11 @@ SOFTWARE.
#ifndef SRC_WEBSERVER_HPP_
#define SRC_WEBSERVER_HPP_
// Include
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <incbin.h>
// 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

View File

@ -26,12 +26,8 @@ SOFTWARE.
#include <LittleFS.h>
#include <incbin.h>
#include <ArduinoJson.hpp>
#include <calc.hpp>
#include <config.hpp>
#include <gyro.hpp>
#include <helper.hpp>
#include <tempsensor.hpp>
#include <main.hpp>
#include <wifi.hpp>
// Settings for DRD

View File

@ -24,8 +24,6 @@ SOFTWARE.
#ifndef SRC_WIFI_HPP_
#define SRC_WIFI_HPP_
// Include
#include <Arduino.h>
#include <ESP8266WiFi.h>
// 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