-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensorEnergy.h
48 lines (39 loc) · 1.54 KB
/
SensorEnergy.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
#pragma once
#include "ArduinoWorkflow.h"
#include <EmonLib.h>
namespace AW {
class TSensorEnergy : public TActor {
public:
TActor* Owner;
TTime Period = AW::TTime::MilliSeconds(10000);
bool SendValues = true;
TSensorEnergy(TActor* owner, uint8_t vPin, double vCal, double phaseCal, uint8_t iPin, double iCal)
: Owner(owner)
{
EMon.voltage(vPin, vCal, phaseCal);
EMon.current(iPin, iCal);
}
protected:
EnergyMonitor EMon;
void OnEvent(TEventPtr event, const TActorContext& context) override {
switch (event->EventID) {
case TEventBootstrap::EventID:
return OnBootstrap(static_cast<TEventBootstrap*>(event.Release()), context);
case TEventReceive::EventID:
return OnReceive(static_cast<TEventReceive*>(event.Release()), context);
}
}
void OnBootstrap(TUniquePtr<TEventBootstrap>, const TActorContext& context) {
EMon.calcVI(100, 1000);
context.Send(this, this, new AW::TEventReceive(context.Now + Period));
}
void OnReceive(AW::TUniquePtr<AW::TEventReceive> event, const AW::TActorContext& context) {
EMon.calcVI(100, 1000);
//context.Send(this, Owner, new AW::TEventSensorData("energy.power", EMon.apparentPower));
//context.Send(this, Owner, new AW::TEventSensorData("energy.voltage", EMon.Vrms));
//context.Send(this, Owner, new AW::TEventSensorData("energy.current", EMon.Irms));
event->NotBefore = context.Now + Period;
context.Resend(this, event.Release());
}
};
}