#include "PwrSupply_USB_QC.h"

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

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

void C_PwrSupply_USB_QC::SetEnable(bool value) {
    digitalWrite(A1, value);
}

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

bool C_PwrSupply_USB_QC::IsEnabled() {
    return digitalRead(A1);
}

void C_PwrSupply_USB_QC::CheckFuse() {
    if (current > FUSE_CURRENT_QC) {
        SetEnable(0);
        fuseTriggered = true;
    }
}
void C_PwrSupply_USB_QC::Tasks() {
    current = fabs(ina3221.getCurrent(INA3221_CH1));
    voltage = ina3221.getVoltage(INA3221_CH1);
    power = voltage * current;
}