parent
f3f378a54a
commit
4fd7d8cf33
|
@ -1,17 +1,17 @@
|
|||
#include "HX711.h"
|
||||
#include "ConfigHardware.h"
|
||||
#include "SwimTrackerConfig.h"
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
template<int DIVIDER=128>
|
||||
template <int DIVIDER = 128>
|
||||
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,14 +21,18 @@ 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_;
|
||||
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
|
||||
#include "Dtypes.h"
|
||||
#include "SwimTrackerConfig.h"
|
||||
|
||||
#ifdef PLATFORM_ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#endif
|
||||
//#include <ESPAsyncWebServer.h>
|
||||
#include <WiFiUdp.h> // for NTP
|
||||
#include <NTPClient.h> // 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<uint16_t, SpiffsStorageReader, SpiffsStorageWriter, CONFIG_SESSION_CHUNK_SIZE> Session_T;
|
||||
using Session_T = SimpleMeasurementSession<uint16_t, CONFIG_SESSION_MAX_SIZE>;
|
||||
|
||||
template <typename Session_T>
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue