manuelbl / zy12pdn-oss

Open-Source Firmware for ZY12PDN USB Power Delivery Trigger
MIT License
204 stars 28 forks source link

Triggering only if source can supply enough current #2

Closed DjordjeMandic closed 1 year ago

DjordjeMandic commented 3 years ago

I need to somehow trigger only if source can supply 3A or more at 20V

Can i somehow set those requirements in this firmware so it does not trigger if source cannot supply at least 3A at 20V?

manuelbl commented 3 years ago

Whenever the communication with the power supply is established, it announces it source capabilities, i.e. the voltages and currents it support. That's when the function on_source_caps_changed in main.cpp is called. So you could change that function to something like this:

void on_source_caps_changed()
{
    int voltage = 5000; // default voltage

    // Select 20V if available with 3A or more
    for (int i = 0; i < power_sink.num_source_caps; i++)
        if (power_sink.source_caps[i].voltage == 20000 && power_sink.source_caps[i].max_current >= 3000)
            voltage = 20000;

    power_sink.request_power(voltage);
}

This function checks if the 20V at 3A is support. If so, it selects 20V, otherwise it selects 5V.

The config mode and switching the voltage with the button make no longer sense and should probably be disabled (unless you want them for something else).