Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
945 B

  1. /*
  2. EmonLiteESP
  3. Energy Monitor Library for ESP8266 based on EmonLib
  4. Currently only support current sensing
  5. */
  6. #ifndef EmonLiteESP_h
  7. #define EmonLiteESP_h
  8. #define ADC_BITS 10
  9. #define ADC_COUNTS (1<<ADC_BITS)
  10. #define COUNT_OFFSET 3
  11. #define FILTER_SPEED 1024.0
  12. #define WARMUP_COUNTS 3000
  13. typedef unsigned int (*current_c)();
  14. class EnergyMonitor {
  15. public:
  16. void initCurrent(current_c callback, double ref, double ratio);
  17. double getCurrent(unsigned int samples);
  18. byte getPrecision();
  19. void setPrecision(byte precision);
  20. void setReference(double ref);
  21. void setCurrentRatio(double ratio);
  22. void setCurrentOffset(double offset);
  23. void calculatePrecision();
  24. private:
  25. current_c _currentCallback;
  26. double _referenceVoltage;
  27. double _currentRatio;
  28. double _currentMidPoint;
  29. double _currentFactor;
  30. byte _precision;
  31. double _multiplier;
  32. void warmup();
  33. };
  34. #endif