zmk icon indicating copy to clipboard operation
zmk copied to clipboard

fix(battery): Error sensor channel name

Open dymax-jp opened this issue 1 year ago • 1 comments

When using CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE get a message in the log Failed to fetch battery values: -...

In battery.c sensor channel name: SENSOR_CHAN_VOLTAGE but in battery_common.c : SENSOR_CHAN_GAUGE_VOLTAGE

battery_common.c :

int battery_channel_get(const struct battery_value *value, enum sensor_channel chan,
                        struct sensor_value *val_out) {
    switch (chan) {
    case SENSOR_CHAN_GAUGE_VOLTAGE:
        val_out->val1 = value->millivolts / 1000;
        val_out->val2 = (value->millivolts % 1000) * 1000U;
        break;

    case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE:
        val_out->val1 = value->state_of_charge;
        val_out->val2 = 0;
        break;

    default:
        return -ENOTSUP;
    }

    return 0;
}

dymax-jp avatar May 27 '24 11:05 dymax-jp

I believe this was intentional, as Zephyr's voltage divider driver uses SENSOR_CHAN_VOLTAGE and not SENSOR_CHAN_GAUGE_VOLTAGE. Using the default value of CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE should work with ZMK's battery drivers.

(I have a PR that would change the battery drivers over to using SENSOR_CHAN_VOLTAGE instead at #2256, but I still need to address Pete's feedback on it.)

joelspadin avatar May 27 '24 15:05 joelspadin

Closing as no files are being changed.

nmunnich avatar Aug 02 '24 21:08 nmunnich