#include "ElectricityDevice.h"

ElectricityDevice::ElectricityDevice(/* args */)
{
}

ElectricityDevice::~ElectricityDevice()
{
}

bool IsSend = false;

void DataInit()
{
    for (size_t i = 0; i < AISLE; i++)
    {
        deviceModel[i].Current = 0.0;
        deviceModel[i].Energy = 0.0;
        deviceModel[i].Power = 0.0;
        deviceModel[i].Voltage = 0.0;
        Current[i] = 0;
    }
}

void blink()
{
    IsSend = digitalRead(21) == 1;
}

void ElectricityDevice::Init()
{
    Serial.begin(115200); // Lora 模块通讯串口
    pinMode(interruptPin, INPUT_PULLDOWN);
    attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
    myRtu.Init();
    DataInit();
}

void ElectricityDevice::Start()
{
    myRtu.Start();
    IsSend = true;
    String SendData = "A" + myJson.PowerHarvesting() + "B";
    Serial.print(SendData);
    while (IsSend)
        delay(1);
}

ElectricityDevice _electricityDevice;