diff --git a/firmware/lib/scale/Scale.h b/firmware/lib/scale/Scale.h index 55748d7..4555192 100644 --- a/firmware/lib/scale/Scale.h +++ b/firmware/lib/scale/Scale.h @@ -1,17 +1,17 @@ #include "HX711.h" -#include "ConfigHardware.h" +#include "SwimTrackerConfig.h" #include - -template +template class Scale { public: - bool measure(uint16_t & measurementOut) { + bool measure(uint16_t &measurementOut) + { if (hx711_.is_ready()) { long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_; - if(value < 0) + if (value < 0) measurementOut = (int16_t)(-value / DIVIDER); else measurementOut = 0; @@ -21,13 +21,17 @@ public: return false; } - void begin(uint32_t pinDOUT, uint32_t pinSCK) { + void begin(uint32_t pinDOUT, uint32_t pinSCK) + { hx711_.begin(pinDOUT, pinSCK); }; - void tare(uint32_t numMeasurementsToAverage=50) { + void tare(uint32_t numMeasurementsToAverage = 50) + { offset_ = hx711_.read_average(numMeasurementsToAverage); } + + long &offset() const { return offset_; } private: HX711 hx711_; diff --git a/firmware/src/ConfigHardware.h b/firmware/src/ConfigHardware.h deleted file mode 100644 index 616c537..0000000 --- a/firmware/src/ConfigHardware.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -//#define _HW_V_20 - -// HX711 load cell -#ifdef PLATFORM_ESP32 - -#ifdef _HW_V_20 -const int CONFIG_SCALE_DOUT_PIN = 23; -const int CONFIG_SCALE_SCK_PIN = 22; -#else -const int CONFIG_SCALE_DOUT_PIN = 22; -const int CONFIG_SCALE_SCK_PIN = 23; -#endif - -#else -const int CONFIG_SCALE_DOUT_PIN = D2; -const int CONFIG_SCALE_SCK_PIN = D3; -#endif -const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in normal phase -const uint8_t CONFIG_TARE_AVG_COUNT = 6; // number of measurements in tare-phase (to find 0 ) -const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements -//const int CONFIG_VALUE_DIVIDER = 8; // uint32 measurements are divided by this factor, before stored in uint16_t -const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t - -const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024; //1024*8 - 16 * sizeof(uint32_t); - -const uint32_t CONFIG_SESSION_MAX_LENGTH_HOURS = 1; -const uint32_t CONFIG_SESSION_MAX_SIZE = CONFIG_SESSION_MAX_LENGTH_HOURS * 3600 * (1000 / CONFIG_MEASURE_DELAY) * sizeof(uint16_t); - -const char *CONFIG_DATA_PATH = "/dat"; \ No newline at end of file diff --git a/firmware/src/ConfigWifi.h b/firmware/src/ConfigWifi.h deleted file mode 100644 index 5d32b30..0000000 --- a/firmware/src/ConfigWifi.h +++ /dev/null @@ -1,5 +0,0 @@ - - -const char *CONFIG_WIFI_SSID = "WLAN"; -const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN"; -const char* CONFIG_HOSTNAME = "smartswim"; diff --git a/firmware/src/SwimTrackerConfig.h b/firmware/src/SwimTrackerConfig.h new file mode 100644 index 0000000..3291fd6 --- /dev/null +++ b/firmware/src/SwimTrackerConfig.h @@ -0,0 +1,39 @@ +#pragma once + +#include + + +// ------------------------------------------ WiFi --------------------------------------------------------------------------------- + +const char *CONFIG_WIFI_SSID = "WLAN"; +const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN"; +const char *CONFIG_HOSTNAME = "smartswim"; + + +// ------------------------------------- Hardware & Measurement Settings ------------------------------------------------------------ + +// Uncomment for Version 2.0 where load cell is connected differently +//#define _HW_V_20 + +const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in normal phase +const uint8_t CONFIG_TARE_AVG_COUNT = 10; // number of measurements in tare-phase (to find 0 ) +const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements +const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t +const uint32_t CONFIG_SESSION_MAX_LENGTH_HOURS = 3; // maximum length of one session +const char *CONFIG_DATA_PATH = "/dat"; // folder in SPIFFS file system to store measurement data +using MeasurementT = uint16_t; // data type for one measurement + + +// ------------------------------------- Derived Settings ----------------------------------------------------------------------------- + +const uint32_t CONFIG_SESSION_MAX_SIZE = CONFIG_SESSION_MAX_LENGTH_HOURS * 3600 * (1000 / CONFIG_MEASURE_DELAY) * sizeof(uint16_t); +static_assert(CONFIG_SESSION_MAX_SIZE < 1024 * 1024, "Measurement data takes more than 1MiB space"); + +// HX711 load cell +#ifdef _HW_V_20 +const int CONFIG_SCALE_DOUT_PIN = 23; +const int CONFIG_SCALE_SCK_PIN = 22; +#else +const int CONFIG_SCALE_DOUT_PIN = 22; +const int CONFIG_SCALE_SCK_PIN = 23; +#endif \ No newline at end of file diff --git a/firmware/src/firmware_main.cpp b/firmware/src/firmware_main.cpp index 1c4f884..ed59777 100644 --- a/firmware/src/firmware_main.cpp +++ b/firmware/src/firmware_main.cpp @@ -1,14 +1,9 @@ // Arduino & ESP headers #include "Dtypes.h" +#include "SwimTrackerConfig.h" -#ifdef PLATFORM_ESP32 #include -#else -#include -#include -#endif -//#include #include // for NTP #include // for NTP @@ -19,18 +14,12 @@ #include "SpiffsStorage.h" #include "DeviceInfoLog.h" #include "SimpleMeasurementSession.h" - -// Configuration -#include "ConfigWifi.h" -#include "ConfigHardware.h" - #include "EspHttp.h" #include "WebDAV.h" WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org"); -//typedef MeasurementSession Session_T; using Session_T = SimpleMeasurementSession; template @@ -94,7 +83,7 @@ public: else { const long skipped = (cycleDuration / CONFIG_MEASURE_DELAY); - //Serial.printf("Warning: measurements skipped: %d, cycleDuration %d", skipped, cycleDuration); + Serial.printf("Warning: measurements skipped: %ld, cycleDuration %ld", skipped, cycleDuration); for (int i = 0; i < skipped; ++i) session.addPoint(measurement);