Skip to content

Commit

Permalink
Merge pull request #206 from mp-se/dev
Browse files Browse the repository at this point in the history
Merge 1.1
  • Loading branch information
mp-se authored Jan 13, 2025
2 parents 0738306 + 1a96299 commit c52fa32
Show file tree
Hide file tree
Showing 42 changed files with 342 additions and 602 deletions.
Binary file modified bin/firmware.bin
Binary file not shown.
Binary file modified bin/firmware32.bin
Binary file not shown.
Binary file modified bin/firmware32c3.bin
Binary file not shown.
Binary file modified bin/firmware32lite.bin
Binary file not shown.
Binary file modified bin/firmware32s2.bin
Binary file not shown.
Binary file modified bin/firmware32s3.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "project":"gravmon", "version":"2.0.1", "html": [ ] }
{ "project":"gravmon", "version":"2.1.0", "html": [ ] }
Binary file modified html/app.js.gz
Binary file not shown.
69 changes: 0 additions & 69 deletions patch/arduino/variants/lolin_s3_mini/pins_arduino.h

This file was deleted.

51 changes: 29 additions & 22 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ lib_dir = lib
include_dir = lib

[common_env_data]
upload_speed = 921600
; upload_speed = 921600
upload_speed = 460800
monitor_speed = 115200
platform = [email protected]
platform32 = espressif32@6.6.0
platform32 = espressif32@6.9.0
build_unflags =
build_flags =
-Wl,-Map,output.map
Expand All @@ -25,26 +26,27 @@ build_flags =
#-D FORCE_GRAVITY_MODE
#-D COLLECT_PERFDATA
-D USE_LITTLEFS=true
-D CFG_APPVER="\"2.0.1\""
#-D CFG_GITREV=\""beta-3\""
-D CFG_APPVER="\"2.1.0\""
; -D CFG_GITREV=\""beta-3\""
#-D ENABLE_REMOTE_UI_DEVELOPMENT
!python script/git_rev.py
-D MAX_SKETCH_SPACE=0x1c0000
lib_deps =
# Using local copy of these libraries
# https://github.com/mp-se/i2cdevlib.git#<document>
# https://github.com/mp-se/OneWire
# https://github.com/mp-se/Arduino-Temperature-Control-Library
https://github.com/mp-se/tinyexpr#v1.0.0
https://github.com/mp-se/Arduino-Log#1.1.2
https://github.com/mp-se/ArduinoJson#v6.21.5
https://github.com/mp-se/arduinoCurveFitting#v1.0.6
https://github.com/mp-se/arduino-mqtt#v2.5.2
https://github.com/mp-se/ESPAsyncWebServer#0.1.1
https://github.com/mp-se/ESPAsyncTCP#0.1.0
https://github.com/mp-se/espframework#1.0.7
https://github.com/mp-se/OneWireNg#0.13.3
https://github.com/bblanchon/ArduinoJson#v7.2.1
https://github.com/256dpi/arduino-mqtt#v2.5.2
https://github.com/mp-se/espframework#1.1.2
https://github.com/pstolarz/OneWireNg#0.13.3
https://github.com/mathieucarbou/ESPAsyncWebServer#v3.4.5
lib_deps8266 =
https://github.com/esphome/ESPAsyncTCP#v2.0.0
lib_deps32 =
https://github.com/mp-se/NimBLE-Arduino#1.4.1
https://github.com/mathieucarbou/AsyncTCP#v3.3.1
lib_ble32 =
https://github.com/h2zero/NimBLE-Arduino#2.1.1
extra_scripts =
script/copy_firmware.py
script/create_versionjson.py
Expand All @@ -64,12 +66,12 @@ build_unflags = ${common_env_data.build_unflags}
build_flags =
${common_env_data.build_flags}
-D LOG_LEVEL=5
-D DISABLE_LED
-D ESPFWK_DISABLE_LED
#-D USE_SERIAL_PINS # Use the TX/RX pins for the serial port
#-D RUN_HARDWARE_TEST # Will run diagnositc setup to validate the GPIO configurations
lib_deps =
https://github.com/mp-se/incbin#v1.0.0
${common_env_data.lib_deps}
${common_env_data.lib_deps8266}
board = d1_mini
build_type = release
board_build.filesystem = littlefs
Expand All @@ -87,9 +89,9 @@ build_flags =
${common_env_data.build_flags}
-D LOG_LEVEL=5
lib_deps =
https://github.com/mp-se/incbin#v1.0.0
https://github.com/bxparks/AUnit#v1.7.1
${common_env_data.lib_deps}
${common_env_data.lib_deps8266}
ESP8266httpUpdate
DNSServer
board = d1_mini
Expand All @@ -116,6 +118,7 @@ build_flags =
lib_deps =
${common_env_data.lib_deps}
${common_env_data.lib_deps32}
${common_env_data.lib_ble32}
lib_ignore =
board = wemos_d1_mini32
build_type = release
Expand All @@ -138,12 +141,13 @@ build_flags =
#-D CORE_DEBUG_LEVEL=6
-D ESP32C3
-D ARDUINO_ESP32C3_DEV
-D DISABLE_LED
-D ESPFWK_DISABLE_LED
#-D ARDUINO_USB_CDC_ON_BOOT=1
#-DUSE_SERIAL_PINS # Use the TX/RX pins for the serial port
lib_deps =
${common_env_data.lib_deps}
${common_env_data.lib_deps32}
${common_env_data.lib_deps32}
${common_env_data.lib_ble32}
lib_ignore =
board = lolin_c3_mini
build_type = release
Expand Down Expand Up @@ -171,6 +175,7 @@ build_flags =
#-D RUN_HARDWARE_TEST # Will run diagnositc setup to validate the GPIO configurations
lib_deps =
${common_env_data.lib_deps}
${common_env_data.lib_deps32}
lib_ignore =
board = lolin_s2_mini
build_type = release
Expand All @@ -184,7 +189,7 @@ platform = ${common_env_data.platform32}
upload_speed = ${common_env_data.upload_speed}
monitor_speed = ${common_env_data.monitor_speed}
extra_scripts =
pre:script/patch_arduino.py
; pre:script/patch_arduino.py
${common_env_data.extra_scripts}
build_unflags =
${common_env_data.build_unflags}
Expand All @@ -195,12 +200,13 @@ build_flags =
-D CORE_DEBUG_LEVEL=2
-D ESP32S3
-D ARDUINO_ESP32S3_DEV
#-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_CDC_ON_BOOT=1
#-D USE_SERIAL_PINS # Use the TX/RX pins for the serial port
#-D RUN_HARDWARE_TEST # Will run diagnositc setup to validate the GPIO configurations
lib_deps =
${common_env_data.lib_deps}
${common_env_data.lib_deps32}
${common_env_data.lib_deps32}
${common_env_data.lib_ble32}
lib_ignore =
board = lolin_s3_mini
build_type = release
Expand Down Expand Up @@ -228,6 +234,7 @@ build_flags =
lib_deps =
${common_env_data.lib_deps}
${common_env_data.lib_deps32}
${common_env_data.lib_ble32}
lib_ignore =
board = lolin32_lite
build_type = release
Expand Down
20 changes: 10 additions & 10 deletions script/patch_arduino.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Import("env")
import shutil
# Import("env")
# import shutil

framework_dir = env.PioPlatform().get_package_dir("framework-arduinoespressif32")
name = env.get( "PIOENV" )#print(FRAMEWORK_DIR)
dir = env.GetLaunchDir()
# framework_dir = env.PioPlatform().get_package_dir("framework-arduinoespressif32")
# name = env.get( "PIOENV" )#print(FRAMEWORK_DIR)
# dir = env.GetLaunchDir()

if name == "gravity32s3-release" :
source = dir + "/patch/arduino/variants/lolin_s3_mini/pins_arduino.h"
target = framework_dir + "/variants/lolin_s3_mini/pins_arduino.h"
print( "Copy file : " + source + " -> " + target )
shutil.copyfile( source, target )
# if name == "gravity32s3-release" :
# source = dir + "/patch/arduino/variants/lolin_s3_mini/pins_arduino.h"
# target = framework_dir + "/variants/lolin_s3_mini/pins_arduino.h"
# print( "Copy file : " + source + " -> " + target )
# shutil.copyfile( source, target )
11 changes: 8 additions & 3 deletions src/ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ void BleSender::sendTiltData(String& color, float tempF, float gravSG,

BLEAdvertisementData advData = BLEAdvertisementData();
advData.setFlags(0x04);
advData.setManufacturerData(beacon.getData());
const NimBLEBeacon::BeaconData& beaconData = beacon.getData();
// advData.setManufacturerData(beacon.getData());
advData.setManufacturerData(
std::string(reinterpret_cast<const char*>(&beaconData), sizeof(beaconData)));

_advertising->setAdvertisementData(advData);
_advertising->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
// _advertising->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
_advertising->setConnectableMode(BLE_GAP_CONN_MODE_NON);

_advertising->start();
delay(_beaconTime);
Expand Down Expand Up @@ -194,7 +198,8 @@ void BleSender::sendCustomBeaconData(float battery, float tempC, float gravity,
advData.setManufacturerData(mf);
_advertising->setAdvertisementData(advData);

_advertising->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
// _advertising->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
_advertising->setConnectableMode(BLE_GAP_CONN_MODE_NON);
_advertising->start();
delay(_beaconTime);
_advertising->stop();
Expand Down
90 changes: 1 addition & 89 deletions src/calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,101 +21,13 @@ 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 <curveFitting.h>
#include <tinyexpr.h>

#include <calc.hpp>
#include <cstdio>
#include <log.hpp>
#include <utils.hpp>

int createFormula(RawFormulaData &fd, char *formulaBuffer,
int formulaBufferSize, int order) {
int noAngles = 0;
RawFormulaData fd2;

// Check how many valid values we have got and make sure we have a full
// series.
for (int i = 0; i < FORMULA_DATA_SIZE; i++) {
if (fd.a[i]) {
fd2.a[noAngles] = fd.a[i];
fd2.g[noAngles] = fd.g[i];
noAngles++;
}
}

#if LOG_LEVEL == 6
Log.verbose(
F("CALC: Trying to create formula using order = %d, found %d angles" CR),
order, noAngles);
#endif

if (noAngles < 3) {
writeErrorLog("CALC: Not enough values for deriving formula");
return ERR_FORMULA_NOTENOUGHVALUES;
} else {
double coeffs[order + 1];
int ret = fitCurve(order, noAngles, fd2.a, fd2.g,
sizeof(coeffs) / sizeof(double), coeffs);

// Returned value is 0 if no error
if (ret == 0) {
#if LOG_LEVEL == 6
Log.verbose(F("CALC: Finshied processing data points, order = %d." CR),
order);
#endif

// Print the formula based on 'order'
if (order == 4) {
snprintf(formulaBuffer, formulaBufferSize,
"%.8f*tilt^4+%.8f*tilt^3+%.8f*tilt^2+%.8f*tilt+%.8f",
coeffs[0], coeffs[1], coeffs[2], coeffs[3], coeffs[4]);
} else if (order == 3) {
snprintf(formulaBuffer, formulaBufferSize,
"%.8f*tilt^3+%.8f*tilt^2+%.8f*tilt+%.8f", coeffs[0], coeffs[1],
coeffs[2], coeffs[3]);
} else if (order == 2) {
snprintf(formulaBuffer, formulaBufferSize, "%.8f*tilt^2+%.8f*tilt+%.8f",
coeffs[0], coeffs[1], coeffs[2]);
} else { // order == 1
snprintf(formulaBuffer, formulaBufferSize, "%.8f*tilt+%.8f", coeffs[0],
coeffs[1]);
}

#if LOG_LEVEL == 6
Log.verbose(F("CALC: Formula: %s" CR), formulaBuffer);
#endif

bool valid = true;

for (int i = 0; i < 5; i++) {
if (fd.a[i] == 0 && valid) break;

double g = calculateGravity(fd.a[i], 0, formulaBuffer);
double dev = (g - fd.g[i]) < 0 ? (fd.g[i] - g) : (g - fd.g[i]);

// If the deviation is more than 2 degress we mark it as failed.
if (dev * 1000 > myConfig.getMaxFormulaCreationDeviation()) {
writeErrorLog(
"CALC: Validation failed on angle %.2f, deviation too large %.4f "
"SG, formula order %d",
fd.a[i], dev * 1000, order);
valid = false;
}
}

if (!valid) {
return ERR_FORMULA_UNABLETOFFIND;
}

Log.info(F("CALC: Found formula '%s'." CR), formulaBuffer);
return 0;
}
}

writeErrorLog("CALC: Internal error finding formula.");
return ERR_FORMULA_INTERNAL;
}

double calculateGravity(double angle, double temp, const char *tempFormula) {
const char *formula = myConfig.getGravityFormula();

Expand Down
6 changes: 0 additions & 6 deletions src/calc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ SOFTWARE.

#include <config.hpp>

constexpr auto ERR_FORMULA_NOTENOUGHVALUES = -1;
constexpr auto ERR_FORMULA_INTERNAL = -2;
constexpr auto ERR_FORMULA_UNABLETOFFIND = -3;

double calculateGravity(double angle, double tempC,
const char *tempFormula = 0);
double gravityTemperatureCorrectionC(double gravity, double tempC,
double calTempC);
int createFormula(RawFormulaData &fd, char *formulaBuffer,
int formulaBufferSize, int order);

#endif // SRC_CALC_HPP_

Expand Down
Loading

0 comments on commit c52fa32

Please sign in to comment.