zy12pdn-oss icon indicating copy to clipboard operation
zy12pdn-oss copied to clipboard

Triggering only if source can supply enough current

Open DjordjeMandic opened this issue 2 years ago • 1 comments

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?

DjordjeMandic avatar Jul 17 '21 20:07 DjordjeMandic

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).

manuelbl avatar Jul 18 '21 09:07 manuelbl