-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerMeter.h
73 lines (58 loc) · 1.99 KB
/
PowerMeter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __POWERMETER_H__
#define __POWERMETER_H__
#define DO1 5
#include <Arduino.h>
#include <esp_int_wdt.h>
#include <esp_task_wdt.h>
typedef struct Measure {
double realPower;
double realPowerSec;
double rmsVoltage;
double rmsCurrent;
double rmsCurrentSec;
String toString()const;
} Measure;
class PowerMeter {
public:
PowerMeter(double FS_V = 189.33E-3, double FS_I = 67.27E-3, double FS_I_SEC = 63.63E-3,
byte pinVoltageInput = 34, byte pinCurrentInput = 32, byte pinCurrentInputSec = 35, int ADCBits = 12);
~PowerMeter() {};
void loop(int timeoutForReadAll = 500, int semicyclesForReadAll = 20);
double getVoltage()const;
double getCurrent()const;
double getCurrentSec()const;
double getPower()const;
double getPowerSec()const;
Measure getMeasure()const;
void getADCValues(int values[])const;
void printADCValues()const;
void setPins(byte pinVoltageInput, byte pinCurrentInput, byte pinCurrentInputSec);
void setADCBits(uint8_t bits);
void setVoltageOffset(uint32_t ofset);
void setCurrentOffset(uint32_t ofset);
void setCurrentSecOffset(uint32_t ofset);
void setOffsets(uint32_t vOffset, uint32_t iOffset, uint32_t i2Offset);
void setDebug(bool debug);
protected:
Stream* DebugPort;
bool debug;
byte pinVoltageInput;
byte pinCurrentInput;
byte pinCurrentInputSec;
const double FS_V;
const double FS_I;
const double FS_I_SEC;
//----------------------------------------- Valori massimi e medi
int MAX_COUNT;
int MID_COUNT;
// ---------------------------------------- valori di tolleranza sullo 0 ZERO_MAX e ZERO_MIN
int ZERO_MAX;
int ZERO_MIN;
// ---------------------------------------- Low-pass filter output (starting at mid voltage for fast settling)
double voltageOffset;
double currentOffset;
double currentOffsetSec;
//----------------------------------------- Struct measure for the loop readings
Measure measure;
};
#endif