Merged precommit branch

This commit is contained in:
Magnus Persson 2022-01-07 13:38:37 +01:00
parent 5612c0ce64
commit 1478430f03
15 changed files with 72 additions and 39 deletions

View File

@ -10,6 +10,17 @@ I use the following tools in order to build and manage the software:
* Git for Windows
* VSCode plugin: Minify (used to minimise the html files)
Code Formatting
===============
I use pre-commit and their cpp style checks to validate the code. Plugin defintions are found in **.pre-commit-config.yaml**
https://www.pre-commit.com
.. note::
There is not yet any automatic checks since this does not work on Windows. It works if running under WSL2 with Ubuntu.
Targets
=======
In the repository there are 3 targets defined

View File

@ -60,6 +60,8 @@ Experimental features
* Use the temperature sensor in the gyro instead of DS18B20
This works fine when the device has time to cool down between measurements and it saves a few milliseconds (reduced battery consumption). My testing shows that this is quite accurate.
There is lots of battery power to save, reading the temp sensor takes almost as long as the gyro. This could reduce the run time by 40-50% and probly extend battery life with the same.
However more testing is required. Might add this as an option in the UI.
.. note::

View File

@ -39,11 +39,13 @@
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="releases.html">Releases</a></li>
<li class="toctree-l1"><a class="reference internal" href="functionallity.html">Functionallity</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="configuration.html">Configuration</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Compiling the software</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#tools">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="#code-formatting">Code Formatting</a></li>
<li class="toctree-l2"><a class="reference internal" href="#targets">Targets</a></li>
<li class="toctree-l2"><a class="reference internal" href="#source-structure">Source structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="#options">Options</a></li>
@ -89,6 +91,15 @@
<li><p>VSCode plugin: Minify (used to minimise the html files)</p></li>
</ul>
</section>
<section id="code-formatting">
<h2>Code Formatting<a class="headerlink" href="#code-formatting" title="Permalink to this headline"></a></h2>
<p>I use pre-commit and their cpp style checks to validate the code. Plugin defintions are found in <strong>.pre-commit-config.yaml</strong></p>
<p><a class="reference external" href="https://www.pre-commit.com">https://www.pre-commit.com</a></p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is not yet any automatic checks since this does not work on Windows. It works if running under WSL2 with Ubuntu.</p>
</div>
</section>
<section id="targets">
<h2>Targets<a class="headerlink" href="#targets" title="Permalink to this headline"></a></h2>
<p>In the repository there are 3 targets defined</p>

View File

@ -39,6 +39,7 @@
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="releases.html">Releases</a></li>
<li class="toctree-l1"><a class="reference internal" href="functionallity.html">Functionallity</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Configuration</a><ul>

View File

@ -39,6 +39,7 @@
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="releases.html">Releases</a></li>
<li class="toctree-l1"><a class="reference internal" href="functionallity.html">Functionallity</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="configuration.html">Configuration</a></li>

View File

@ -19,7 +19,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Installation" href="installation.html" />
<link rel="prev" title="Welcome to GravityMons documentation!" href="index.html" />
<link rel="prev" title="Releases" href="releases.html" />
</head>
<body class="wy-body-for-nav">
@ -39,6 +39,7 @@
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="releases.html">Releases</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Functionallity</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#the-main-differences">The main differences</a></li>
<li class="toctree-l2"><a class="reference internal" href="#other-features">Other features</a></li>
@ -127,7 +128,9 @@ via an REST API so data can be pushed to the device via scripts (see API section
<h2>Experimental features<a class="headerlink" href="#experimental-features" title="Permalink to this headline"></a></h2>
<ul>
<li><p>Use the temperature sensor in the gyro instead of DS18B20</p>
<p>This works fine when the device has time to cool down between measurements and it saves a few milliseconds (reduced battery consumption). My testing shows that this is quite accurate.</p>
<p>This works fine when the device has time to cool down between measurements and it saves a few milliseconds (reduced battery consumption). My testing shows that this is quite accurate.
There is lots of battery power to save, reading the temp sensor takes almost as long as the gyro. This could reduce the run time by 40-50% and probly extend battery life with the same.
However more testing is required. Might add this as an option in the UI.</p>
</li>
</ul>
<div class="admonition note">
@ -147,7 +150,7 @@ via an REST API so data can be pushed to the device via scripts (see API section
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="index.html" class="btn btn-neutral float-left" title="Welcome to GravityMons documentation!" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="releases.html" class="btn btn-neutral float-left" title="Releases" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="installation.html" class="btn btn-neutral float-right" title="Installation" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>

View File

@ -175,6 +175,7 @@ over the last 6 months without any issues.</p>
</li>
<li class="toctree-l1"><a class="reference internal" href="compiling.html">Compiling the software</a><ul>
<li class="toctree-l2"><a class="reference internal" href="compiling.html#tools">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="compiling.html#code-formatting">Code Formatting</a></li>
<li class="toctree-l2"><a class="reference internal" href="compiling.html#targets">Targets</a></li>
<li class="toctree-l2"><a class="reference internal" href="compiling.html#source-structure">Source structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="compiling.html#options">Options</a></li>

View File

@ -39,6 +39,7 @@
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="releases.html">Releases</a></li>
<li class="toctree-l1"><a class="reference internal" href="functionallity.html">Functionallity</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#official-esptool">Official esptool</a></li>

File diff suppressed because one or more lines are too long

View File

@ -37,7 +37,7 @@ build_flags =
-D PUSH_DISABLE_LOGGING
-D TSEN_DISABLE_LOGGING
-D WEB_DISABLE_LOGGING
-D MAIN_DISABLE_LOGGING
#-D MAIN_DISABLE_LOGGING
-D USE_LITTLEFS=true
-D EMBED_HTML # If this is not used the html files needs to be on the file system (can be uploaded)
-D USER_SSID=\""\"" # =\""myssid\""
@ -113,7 +113,7 @@ build_unflags = ${common_env_data.build_unflags}
build_flags =
${common_env_data.build_flags}
-D COLLECT_PERFDATA # This option will collect runtime data for a few defined methods to measure time, dumped to serial and/or influxdb
-D LOG_LEVEL=5
-D LOG_LEVEL=6
lib_deps =
${common_env_data.lib_deps}
board = ${common_env_data.board}

View File

@ -50,7 +50,7 @@ void deepSleep(int t) {
#if LOG_LEVEL == 6
Log.verbose(F("HELP: Entering sleep mode for %ds." CR), t);
#endif
uint64_t wake = t * 1000000;
uint32_t wake = t * 1000000;
ESP.deepSleep(wake);
}
@ -78,14 +78,14 @@ void printBuildOptions() {
//
// Configure serial debug output
//
SerialDebug::SerialDebug(const int32 serialSpeed) {
SerialDebug::SerialDebug(const uint32_t serialSpeed) {
// Start serial with auto-detected rate (default to defined BAUD)
Serial.flush();
Serial.begin(serialSpeed);
getLog()->begin(LOG_LEVEL, &Serial, true);
getLog()->setPrefix(printTimestamp);
getLog()->notice(F("SDBG: Serial logging started at %l." CR), serialSpeed);
getLog()->notice(F("SDBG: Serial logging started at %u." CR), serialSpeed);
}
//
@ -168,7 +168,7 @@ void PerfLogging::print() {
while (pe != 0) {
// Log.notice( F("PERF: %s=%l ms (%l, %l)" CR), pe->key, (pe->end -
// pe->start), pe->start, pe->end );
Log.notice(F("PERF: %s %lms" CR), pe->key, pe->max);
Log.notice(F("PERF: %s %ums" CR), pe->key, pe->max);
pe = pe->next;
}
}

View File

@ -45,7 +45,7 @@ void printHeap();
// Classes
class SerialDebug {
public:
explicit SerialDebug(const int32 serialSpeed = 115200L);
explicit SerialDebug(const uint32_t serialSpeed = 115200L);
static Logging* getLog() { return &Log; }
};

View File

@ -105,6 +105,8 @@ void setup() {
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
bool dt = drd->detectDoubleReset();
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
delay(3000); // Wait a few seconds when using debug version so that serial is
// started.
Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str());
#endif
// Main startup
@ -141,18 +143,15 @@ void setup() {
myTempSensor.setup();
LOG_PERF_STOP("main-temp-setup");
// LOG_PERF_START("main-gyro-setup"); // Takes less than 5ms, so skip this
// measurment
if (!myGyro.setup()) Log.error(F("Main: Failed to initialize the gyro." CR));
// LOG_PERF_STOP("main-gyro-setup");
if (!myGyro.setup()) // Takes less than 5ms, so skip this
Log.error(F("Main: Failed to initialize the gyro." CR));
LOG_PERF_START("main-gyro-read");
myGyro.read();
LOG_PERF_STOP("main-gyro-read");
LOG_PERF_START("main-batt-read");
myBatteryVoltage.read();
LOG_PERF_STOP("main-batt-read");
myBatteryVoltage
.read(); // Takes less than 1ms, so skip this measuring time on this
checkSleepMode(myGyro.getAngle(), myBatteryVoltage.getVoltage());
if (myWifi.isConnected()) {
@ -164,10 +163,8 @@ void setup() {
LOG_PERF_STOP("main-wifi-ota");
#endif
if (!sleepModeActive) {
// LOG_PERF_START("main-webserver-setup"); // Takes less than 4ms , so
// skip this measurment
myWebServer.setupWebServer();
// LOG_PERF_STOP("main-webserver-setup");
myWebServer
.setupWebServer(); // Takes less than 4ms, so skip this measurement
}
}
@ -186,7 +183,6 @@ void loop() {
if (sleepModeActive || abs((int32_t)(millis() - loopMillis)) > interval) {
float angle = 0;
float volt = myBatteryVoltage.getVoltage();
// float sensorTemp = 0;
loopCounter++;
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
@ -207,16 +203,11 @@ void loop() {
float temp = myTempSensor.getTempC();
LOG_PERF_STOP("loop-temp-read");
// LOG_PERF_START("loop-gravity-calc"); // Takes less than 2ms , so skip
// this measurment
float gravity = calculateGravity(angle, temp);
// LOG_PERF_STOP("loop-gravity-calc");
// LOG_PERF_START("loop-gravity-corr"); // Takes less than 2ms , so skip
// this measurment Use default correction temperature of 20C
float corrGravity =
gravityTemperatureCorrection(gravity, temp, myConfig.getTempFormat());
// LOG_PERF_STOP("loop-gravity-corr");
float gravity = calculateGravity(
angle, temp); // Takes less than 2ms , so skip this measurment
float corrGravity = gravityTemperatureCorrection(
gravity, temp, myConfig.getTempFormat()); // Takes less than 2ms , so
// skip this measurment
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F, "
@ -299,17 +290,15 @@ void loop() {
myGyro.read();
LOG_PERF_STOP("loop-gyro-read");
// LOG_PERF_START("loop-batt-read"); // Takes less than 2ms , so skip this
// measurment
myBatteryVoltage.read();
// LOG_PERF_STOP("loop-batt-read");
myBatteryVoltage.read(); // Takes less than 2ms , so skip this measurment
loopMillis = millis();
// #if LOG_LEVEL==6 && !defined( MAIN_DISABLE_LOGGING )
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
Log.verbose(F("Main: Heap %d kb FreeSketch %d kb HeapFrag %d %%." CR),
ESP.getFreeHeap() / 1024, ESP.getFreeSketchSpace() / 1024,
ESP.getHeapFragmentation());
// #endif
#endif
LOG_PERF_PUSH();
}
myWebServer.loop();

View File

@ -10,6 +10,17 @@ I use the following tools in order to build and manage the software:
* Git for Windows
* VSCode plugin: Minify (used to minimise the html files)
Code Formatting
===============
I use pre-commit and their cpp style checks to validate the code. Plugin defintions are found in **.pre-commit-config.yaml**
https://www.pre-commit.com
.. note::
There is not yet any automatic checks since this does not work on Windows. It works if running under WSL2 with Ubuntu.
Targets
=======
In the repository there are 3 targets defined

View File

@ -60,6 +60,8 @@ Experimental features
* Use the temperature sensor in the gyro instead of DS18B20
This works fine when the device has time to cool down between measurements and it saves a few milliseconds (reduced battery consumption). My testing shows that this is quite accurate.
There is lots of battery power to save, reading the temp sensor takes almost as long as the gyro. This could reduce the run time by 40-50% and probly extend battery life with the same.
However more testing is required. Might add this as an option in the UI.
.. note::