#include "PwrSupply_USB_PD.h"

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

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

void C_PwrSupply_USB_PD::SetEnable(bool value) {
    digitalWrite(A2, value);
}

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

bool C_PwrSupply_USB_PD::IsEnabled() {
    return digitalRead(A2);
}

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

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