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.

97 lines
2.8 KiB

  1. // -----------------------------------------------------------------------------
  2. // Abstract emon sensor class (other sensor classes extend this class)
  3. // Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. // -----------------------------------------------------------------------------
  5. #pragma once
  6. #include "../sensor.h"
  7. #include "BaseSensor.h"
  8. class BaseEmonSensor : public BaseSensor {
  9. public:
  10. BaseEmonSensor(size_t devices) :
  11. _energy(devices),
  12. _devices(devices)
  13. {}
  14. BaseEmonSensor() :
  15. BaseEmonSensor(1)
  16. {}
  17. unsigned char type() {
  18. return sensor::type::Emon;
  19. }
  20. virtual void resizeDevices(size_t devices) {
  21. _energy.resize(devices);
  22. _devices = devices;
  23. }
  24. virtual size_t countDevices() {
  25. return _devices;
  26. }
  27. virtual void resetEnergy(unsigned char index, sensor::Energy energy) {
  28. _energy[index] = energy;
  29. }
  30. virtual void resetEnergy(unsigned char index) {
  31. _energy[index].reset();
  32. };
  33. virtual void resetEnergy() {
  34. for (auto& energy : _energy) {
  35. energy.reset();
  36. }
  37. }
  38. virtual sensor::Energy totalEnergy(unsigned char index) {
  39. return _energy[index];
  40. }
  41. virtual sensor::Energy totalEnergy() {
  42. return totalEnergy(0);
  43. }
  44. virtual double getEnergy(unsigned char index) {
  45. return _energy[index].asDouble();
  46. }
  47. virtual double getEnergy() {
  48. return getEnergy(0);
  49. }
  50. virtual void setCurrentRatio(double) {}
  51. virtual void setVoltageRatio(double) {}
  52. virtual void setPowerRatio(double) {}
  53. virtual void setEnergyRatio(double) {}
  54. // when sensor implements a single device
  55. virtual double getCurrentRatio() { return 0.0; }
  56. virtual double getVoltageRatio() { return 0.0; }
  57. virtual double getPowerRatio() { return 0.0; }
  58. virtual double getEnergyRatio() { return 0.0; }
  59. // when sensor implements more than one device
  60. virtual double getCurrentRatio(unsigned char index) { return getCurrentRatio(); }
  61. virtual double getVoltageRatio(unsigned char index) { return getCurrentRatio(); }
  62. virtual double getPowerRatio(unsigned char index) { return getCurrentRatio(); }
  63. virtual double getEnergyRatio(unsigned char index) { return getCurrentRatio(); }
  64. virtual void expectedCurrent(double value) {}
  65. virtual void expectedVoltage(unsigned int value) {}
  66. virtual void expectedPower(unsigned int value) {}
  67. virtual void resetCalibration(double value) {}
  68. virtual void resetRatios() {}
  69. protected:
  70. std::vector<sensor::Energy> _energy;
  71. size_t _devices;
  72. };