#pragma once

#include <cstdint>

// Uncomment for Version 2.0 where load cell is connected differently
//#define _HW_V_20
#define NEW_HEAVY_LOAD_CELL

constexpr const char *CONFIG_HOSTNAME = "swimtracker";

// ------------------------------------- Hardware & Measurement Settings ------------------------------------------------------------

constexpr uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1;     // number of measurements in normal phase
constexpr uint8_t CONFIG_TARE_AVG_COUNT = 20;           // number of measurements in tare-phase (to find 0 )
constexpr int CONFIG_MEASURE_DELAY = 100;               // interval in ms between measurements
constexpr uint32_t CONFIG_SESSION_MAX_LENGTH_HOURS = 3; // maximum length of one session
constexpr const char *CONFIG_DATA_PATH = "/dat";    // folder in SPIFFS file system to store measurement data
using MeasurementT = uint16_t;                      // data type for one measurement
#ifdef NEW_HEAVY_LOAD_CELL
const int CONFIG_VALUE_RIGHT_SHIFT = 3; // uint32 measurements are divided by this power, before stored in uint16_t
#else
const int CONFIG_VALUE_RIGHT_SHIFT = 7;
#endif
constexpr MeasurementT CONFIG_KG_FACTOR_INV = 701; // after shifting - how many "measurement units" are one kg

constexpr int MAX_WEBSOCKET_CONNECTIONS = 3; // maximal number of websocket connections maintained at the same time

constexpr const char *UPDATE_URL = "https://swimtracker-update.bauer.tech/firmware.bin";

// auto start/stop
constexpr MeasurementT CONFIG_AUTO_START_MIN_THRESHOLD = CONFIG_KG_FACTOR_INV * 1;
constexpr MeasurementT CONFIG_AUTO_START_MAX_THRESHOLD = CONFIG_KG_FACTOR_INV * 3;
constexpr uint32_t CONFIG_AUTO_START_MAX_MEASUREMENTS_BETWEEN_PEAKS = (1000 / CONFIG_MEASURE_DELAY) * 6;

constexpr MeasurementT CONFIG_AUTO_STOP_THRESHOLD = CONFIG_KG_FACTOR_INV * 1;
//uint32_t CONFIG_AUTO_STOP_NUM_MEASUREMENTS = (1000 / CONFIG_MEASURE_DELAY) * 60 * 15;
constexpr uint32_t CONFIG_AUTO_STOP_NUM_MEASUREMENTS = (1000 / CONFIG_MEASURE_DELAY) * 30;

constexpr unsigned long CONFIG_PING_INTERVAL_MS = 1000;

// ------------------------------------- Derived Settings -----------------------------------------------------------------------------

constexpr 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");

#ifdef _HW_V_20
constexpr int CONFIG_SCALE_DOUT_PIN = 23;
constexpr int CONFIG_SCALE_SCK_PIN = 22;
#else
constexpr int CONFIG_SCALE_DOUT_PIN = 22;
constexpr int CONFIG_SCALE_SCK_PIN = 23;
#endif
