parent
							
								
									f3f378a54a
								
							
						
					
					
						commit
						4fd7d8cf33
					
				|  | @ -1,17 +1,17 @@ | ||||||
| #include "HX711.h" | #include "HX711.h" | ||||||
| #include "ConfigHardware.h" | #include "SwimTrackerConfig.h" | ||||||
| #include <cstdint> | #include <cstdint> | ||||||
| 
 | 
 | ||||||
| 
 | template <int DIVIDER = 128> | ||||||
| template<int DIVIDER=128> |  | ||||||
| class Scale | class Scale | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     bool measure(uint16_t & measurementOut) { |     bool measure(uint16_t &measurementOut) | ||||||
|  |     { | ||||||
|         if (hx711_.is_ready()) |         if (hx711_.is_ready()) | ||||||
|         { |         { | ||||||
|             long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_; |             long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_; | ||||||
|             if(value < 0) |             if (value < 0) | ||||||
|                 measurementOut = (int16_t)(-value / DIVIDER); |                 measurementOut = (int16_t)(-value / DIVIDER); | ||||||
|             else |             else | ||||||
|                 measurementOut = 0; |                 measurementOut = 0; | ||||||
|  | @ -21,14 +21,18 @@ public: | ||||||
|             return false; |             return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void begin(uint32_t pinDOUT, uint32_t pinSCK) { |     void begin(uint32_t pinDOUT, uint32_t pinSCK) | ||||||
|  |     { | ||||||
|         hx711_.begin(pinDOUT, pinSCK); |         hx711_.begin(pinDOUT, pinSCK); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     void tare(uint32_t numMeasurementsToAverage=50) { |     void tare(uint32_t numMeasurementsToAverage = 50) | ||||||
|  |     { | ||||||
|         offset_ = hx711_.read_average(numMeasurementsToAverage); |         offset_ = hx711_.read_average(numMeasurementsToAverage); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     long &offset() const { return offset_; } | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     HX711 hx711_; |     HX711 hx711_; | ||||||
|     long offset_ = 0; |     long offset_ = 0; | ||||||
|  |  | ||||||
|  | @ -1,33 +0,0 @@ | ||||||
| #pragma once |  | ||||||
| 
 |  | ||||||
| #include <cstdint> |  | ||||||
| 
 |  | ||||||
| //#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"; |  | ||||||
|  | @ -1,5 +0,0 @@ | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| const char *CONFIG_WIFI_SSID = "WLAN"; |  | ||||||
| const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN"; |  | ||||||
| const char* CONFIG_HOSTNAME = "smartswim"; |  | ||||||
|  | @ -0,0 +1,39 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <cstdint> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | // ------------------------------------------ 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 | ||||||
|  | @ -1,14 +1,9 @@ | ||||||
| 
 | 
 | ||||||
| // Arduino & ESP headers
 | // Arduino & ESP headers
 | ||||||
| #include "Dtypes.h" | #include "Dtypes.h" | ||||||
|  | #include "SwimTrackerConfig.h" | ||||||
| 
 | 
 | ||||||
| #ifdef PLATFORM_ESP32 |  | ||||||
| #include <WiFi.h> | #include <WiFi.h> | ||||||
| #else |  | ||||||
| #include <ESP8266WiFi.h> |  | ||||||
| #include <ESPAsyncTCP.h> |  | ||||||
| #endif |  | ||||||
| //#include <ESPAsyncWebServer.h>
 |  | ||||||
| #include <WiFiUdp.h>   // for NTP
 | #include <WiFiUdp.h>   // for NTP
 | ||||||
| #include <NTPClient.h> // for NTP
 | #include <NTPClient.h> // for NTP
 | ||||||
| 
 | 
 | ||||||
|  | @ -19,18 +14,12 @@ | ||||||
| #include "SpiffsStorage.h" | #include "SpiffsStorage.h" | ||||||
| #include "DeviceInfoLog.h" | #include "DeviceInfoLog.h" | ||||||
| #include "SimpleMeasurementSession.h" | #include "SimpleMeasurementSession.h" | ||||||
| 
 |  | ||||||
| // Configuration
 |  | ||||||
| #include "ConfigWifi.h" |  | ||||||
| #include "ConfigHardware.h" |  | ||||||
| 
 |  | ||||||
| #include "EspHttp.h" | #include "EspHttp.h" | ||||||
| #include "WebDAV.h" | #include "WebDAV.h" | ||||||
| 
 | 
 | ||||||
| WiFiUDP ntpUDP; | WiFiUDP ntpUDP; | ||||||
| NTPClient timeClient(ntpUDP, "pool.ntp.org"); | NTPClient timeClient(ntpUDP, "pool.ntp.org"); | ||||||
| 
 | 
 | ||||||
| //typedef MeasurementSession<uint16_t, SpiffsStorageReader, SpiffsStorageWriter, CONFIG_SESSION_CHUNK_SIZE> Session_T;
 |  | ||||||
| using Session_T = SimpleMeasurementSession<uint16_t, CONFIG_SESSION_MAX_SIZE>; | using Session_T = SimpleMeasurementSession<uint16_t, CONFIG_SESSION_MAX_SIZE>; | ||||||
| 
 | 
 | ||||||
| template <typename Session_T> | template <typename Session_T> | ||||||
|  | @ -94,7 +83,7 @@ public: | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 const long skipped = (cycleDuration / CONFIG_MEASURE_DELAY); |                 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) |                 for (int i = 0; i < skipped; ++i) | ||||||
|                     session.addPoint(measurement); |                     session.addPoint(measurement); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue