[C++] how do the voltage functions work? (int vs. float)[SOLVED]


#1

how do the voltage functions work? (int vs. float)


    // Get the voltages of the four power rails
    int     get_voltage_3v3    (float &voltage);
    float   get_voltage_3v3    ();
    int     get_voltage_5v     (float &voltage);
    float   get_voltage_5v     ();
    int     get_voltage_9v     (float &voltage);
    float   get_voltage_9v     ();
    int     get_voltage_battery(float &voltage);
    float   get_voltage_battery();

#2

If you use e.g. float get_voltage_5v(); it will return the voltage of the 5v rail if it’s successful, otherwise it will return the error (which will be < 0).

If you use e.g. int get_voltage_5v (float &voltage); it will return the error code, and through the pass-by-reference it will return the voltage of the 5v rail (unless the error code is not ERROR_NONE, in which case the voltage value will probably be 0).

Either way the voltage is returned as a floating point voltage e.g. 5.025 if it is read successfully.


#3

ok, I understand. :slight_smile:
Thank you for your explanation!


#4