Added storage mode
This commit is contained in:
parent
0cba58a0dd
commit
ded06d15a1
@ -403,7 +403,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-3 offset-sm-2">
|
||||
<div class="col-sm-4 offset-sm-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="gyro-temp" id="gyro-temp" data-bs-toggle="tooltip" title="Use the temperature sensor in the gyro instead of DS18B20, require 300s update interval to be accurate">
|
||||
<label class="form-check-label" for="gyro-temp">Use gyro temperature</label>
|
||||
@ -411,6 +411,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4 offset-sm-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="storage-sleep" id="storage-sleep" data-bs-toggle="tooltip" title="If enabled and the device is placed on its cap (less than 5 degress) it will go into sleep for 2000 minutes">
|
||||
<label class="form-check-label" for="storage-sleep">Enable storage mode when placed on cap</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<label class="col-sm-2 col-form-label" for="ble">Bluetooth tilt color:</label>
|
||||
<div class="col-sm-2">
|
||||
@ -860,6 +869,7 @@
|
||||
$("#temp-adjustment-value").val(cfg["temp-adjustment-value"]);
|
||||
$("#gravity-temp-adjustment").prop( "checked", cfg["gravity-temp-adjustment"] );
|
||||
$("#gyro-temp").prop( "checked", cfg["gyro-temp"] );
|
||||
$("#storage-sleep").prop( "checked", cfg["storage-sleep"] );
|
||||
$("#gyro-calibration-data").text( cfg["gyro-calibration-data"]["ax"] + "," + cfg["gyro-calibration-data"]["ay"] + "," + cfg["gyro-calibration-data"]["az"] + "," + cfg["gyro-calibration-data"]["gx"] + "," + cfg["gyro-calibration-data"]["gy"] + "," + cfg["gyro-calibration-data"]["gz"] );
|
||||
$("#battery").text(cfg["battery"] + " V");
|
||||
$("#angle").text(cfg["angle"]);
|
||||
|
File diff suppressed because one or more lines are too long
@ -33,9 +33,9 @@ build_flags =
|
||||
-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\""
|
||||
-D USER_SSID_PWD=\""\"" # =\""mypwd\""
|
||||
-D CFG_APPVER="\"1.0.1\""
|
||||
#-D CFG_GITREV=\""beta-2\""
|
||||
!python script/git_rev.py
|
||||
-D CFG_APPVER="\"1.1.0\""
|
||||
-D CFG_GITREV=\""alfa-1\""
|
||||
#!python script/git_rev.py
|
||||
lib_deps = # Switched to forks for better version control.
|
||||
# Using local copy of these libraries
|
||||
#https://github.com/mp-se/i2cdevlib.git#<document>
|
||||
|
@ -92,6 +92,7 @@ void Config::createJson(DynamicJsonDocument& doc) {
|
||||
doc[PARAM_TEMP_ADJ] = getTempSensorAdjC();
|
||||
doc[PARAM_GRAVITY_TEMP_ADJ] = isGravityTempAdj();
|
||||
doc[PARAM_GYRO_TEMP] = isGyroTemp();
|
||||
doc[PARAM_STORAGE_SLEEP] = isStorageSleep();
|
||||
|
||||
JsonObject cal = doc.createNestedObject(PARAM_GYRO_CALIBRATION);
|
||||
cal["ax"] = _gyroCalibration.ax;
|
||||
@ -261,6 +262,8 @@ bool Config::loadFile() {
|
||||
setGravityTempAdj(doc[PARAM_GRAVITY_TEMP_ADJ].as<bool>());
|
||||
if (!doc[PARAM_GYRO_TEMP].isNull())
|
||||
setGyroTemp(doc[PARAM_GYRO_TEMP].as<bool>());
|
||||
if (!doc[PARAM_STORAGE_SLEEP].isNull())
|
||||
setStorageSleep(doc[PARAM_STORAGE_SLEEP].as<bool>());
|
||||
if (!doc[PARAM_GRAVITY_FORMAT].isNull()) {
|
||||
String s = doc[PARAM_GRAVITY_FORMAT];
|
||||
setGravityFormat(s.charAt(0));
|
||||
|
@ -149,6 +149,7 @@ class Config {
|
||||
float _tempSensorAdjC = 0;
|
||||
int _sleepInterval = 900;
|
||||
bool _gyroTemp = false;
|
||||
bool _storageSleep = false;
|
||||
|
||||
// Wifi Config
|
||||
String _wifiSSID[2] = {"", ""};
|
||||
@ -207,6 +208,12 @@ class Config {
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const bool isStorageSleep() { return _storageSleep; }
|
||||
void setStorageSleep(bool b) {
|
||||
_storageSleep = b;
|
||||
_saveNeeded = true;
|
||||
}
|
||||
|
||||
const char* getOtaURL() { return _otaURL.c_str(); }
|
||||
void setOtaURL(String s) {
|
||||
_otaURL = s;
|
||||
|
22
src/main.cpp
22
src/main.cpp
@ -50,9 +50,6 @@ uint32_t stableGyroMillis; // Used to calculate the total time since last
|
||||
|
||||
RunMode runMode = RunMode::gravityMode;
|
||||
|
||||
//
|
||||
// Check if we should be in sleep mode
|
||||
//
|
||||
void checkSleepMode(float angle, float volt) {
|
||||
#if defined(SKIP_SLEEPMODE)
|
||||
runMode = RunMode::configurationMode;
|
||||
@ -85,6 +82,8 @@ void checkSleepMode(float angle, float volt) {
|
||||
runMode = RunMode::configurationMode;
|
||||
} else if ((volt < 4.15 && (angle > 85 && angle < 95)) || (volt > 4.15)) {
|
||||
runMode = RunMode::configurationMode;
|
||||
} else if (angle < 5 && myConfig.isStorageSleep()) {
|
||||
runMode = RunMode::storageMode;
|
||||
} else {
|
||||
runMode = RunMode::gravityMode;
|
||||
}
|
||||
@ -102,14 +101,16 @@ void checkSleepMode(float angle, float volt) {
|
||||
#if !defined(MAIN_DISABLE_LOGGING)
|
||||
Log.notice(F("MAIN: run mode GRAVITY (angle=%F volt=%F)." CR), angle,
|
||||
volt);
|
||||
#endif
|
||||
break;
|
||||
case RunMode::storageMode:
|
||||
#if !defined(MAIN_DISABLE_LOGGING)
|
||||
Log.notice(F("MAIN: run mode STORAGE (angle=%F)." CR), angle);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Setup
|
||||
//
|
||||
void setup() {
|
||||
LOG_PERF_START("run-time");
|
||||
LOG_PERF_START("main-setup");
|
||||
@ -190,6 +191,12 @@ void setup() {
|
||||
myBatteryVoltage.read();
|
||||
checkSleepMode(myGyro.getAngle(), myBatteryVoltage.getVoltage());
|
||||
|
||||
if (runMode == RunMode::storageMode) {
|
||||
// If we are in storage mode, just go back to sleep
|
||||
Log.notice(F("Main: Storage mode entered, going to sleep for maximum time." CR));
|
||||
ESP.deepSleep(ESP.deepSleepMax());
|
||||
}
|
||||
|
||||
#if defined(ESP32)
|
||||
if (!myConfig.isWifiPushActive() && runMode == RunMode::gravityMode) {
|
||||
Log.notice(
|
||||
@ -358,9 +365,6 @@ void goToSleep(int sleepInterval) {
|
||||
deepSleep(sleepInterval);
|
||||
}
|
||||
|
||||
//
|
||||
// Main loops
|
||||
//
|
||||
void loop() {
|
||||
switch (runMode) {
|
||||
case RunMode::configurationMode:
|
||||
|
@ -29,7 +29,7 @@ SOFTWARE.
|
||||
#include <ArduinoLog.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum RunMode { gravityMode = 0, configurationMode = 1, wifiSetupMode = 2 };
|
||||
enum RunMode { gravityMode = 0, configurationMode = 1, wifiSetupMode = 2, storageMode = 3 };
|
||||
extern RunMode runMode;
|
||||
|
||||
#if defined(ESP8266)
|
||||
|
@ -60,6 +60,7 @@ SOFTWARE.
|
||||
#define PARAM_TEMP_ADJ "temp-adjustment-value"
|
||||
#define PARAM_GYRO_CALIBRATION "gyro-calibration-data"
|
||||
#define PARAM_GYRO_TEMP "gyro-temp"
|
||||
#define PARAM_STORAGE_SLEEP "storage-sleep"
|
||||
#define PARAM_FORMULA_DATA "formula-calculation-data"
|
||||
#define PARAM_FILES "files"
|
||||
#define PARAM_FILE_NAME "file-name"
|
||||
|
@ -624,6 +624,11 @@ void WebServerHandler::webHandleConfigHardware() {
|
||||
_server->arg(PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false);
|
||||
else
|
||||
myConfig.setGyroTemp(false);
|
||||
if (_server->hasArg(PARAM_STORAGE_SLEEP))
|
||||
myConfig.setStorageSleep(
|
||||
_server->arg(PARAM_STORAGE_SLEEP).equalsIgnoreCase("on") ? true : false);
|
||||
else
|
||||
myConfig.setStorageSleep(false);
|
||||
|
||||
myConfig.saveFile();
|
||||
_server->sendHeader("Location", "/config.htm#collapseHardware", true);
|
||||
|
Loading…
Reference in New Issue
Block a user