#include "PwrSupply_12V.h"

void C_PwrSupply_12V::Init() {
    INA_Init();

    pinMode(A3, OUTPUT);
    SetEnable(0);
}

void C_PwrSupply_12V::SetEnable(bool value) {
    digitalWrite(A3, value);
}

void C_PwrSupply_12V::ToggleEnable() {
    SetEnable(!IsEnabled());
}

bool C_PwrSupply_12V::IsEnabled() {
    return digitalRead(A3);
}

void C_PwrSupply_12V::CheckFuse() {
    if (current > fuseValue) {
        SetEnable(0);
        fuseTriggered = true;
    }
}

void C_PwrSupply_12V::Tasks() {
    current = fabs(ina3221.getCurrent(INA3221_CH3));
    voltage = ina3221.getVoltage(INA3221_CH3);
    power = voltage * current;
}