-/* $OpenBSD: uhidpp.c,v 1.14 2021/05/11 16:40:57 anton Exp $ */
+/* $OpenBSD: uhidpp.c,v 1.15 2021/07/28 09:55:58 anton Exp $ */
/*
* Copyright (c) 2021 Anton Lindqvist <anton@openbsd.org>
int uhidpp_consume_notification(struct uhidpp_softc *, struct uhidpp_report *);
int uhidpp_is_notification(struct uhidpp_softc *, struct uhidpp_report *);
+static int uhidpp_has_sensors(struct uhidpp_softc *);
+
int hidpp_get_protocol_version(struct uhidpp_softc *, uint8_t, uint8_t *,
uint8_t *);
if (error)
printf(" error %d", error);
- strlcpy(sc->sc_sensdev.xname, sc->sc_hdev.sc_dev.dv_xname,
- sizeof(sc->sc_sensdev.xname));
- sensordev_install(&sc->sc_sensdev);
-
out:
mtx_leave(&sc->sc_mtx);
printf("\n");
KASSERT(sc->sc_resp_state == UHIDPP_RESP_NONE);
- if (sc->sc_sensdev.xname[0] != '\0')
+ if (uhidpp_has_sensors(sc))
sensordev_deinstall(&sc->sc_sensdev);
for (i = 0; i < UHIDPP_NDEVICES; i++) {
dev->d_connected = 1;
+ /*
+ * Delay installation of sensors until a device with battery support is
+ * connected. Allows sensorsd(8) to pick up hotplugged devices.
+ */
+ if (!uhidpp_has_sensors(sc)) {
+ strlcpy(sc->sc_sensdev.xname, sc->sc_hdev.sc_dev.dv_xname,
+ sizeof(sc->sc_sensdev.xname));
+ sensordev_install(&sc->sc_sensdev);
+ }
+
sens = &dev->d_battery.b_sens[0];
strlcpy(sens->desc, "battery level", sizeof(sens->desc));
sens->type = SENSOR_PERCENT;
return 1;
}
+static int
+uhidpp_has_sensors(struct uhidpp_softc *sc)
+{
+ return sc->sc_sensdev.xname[0] != '\0';
+}
+
int
hidpp_get_protocol_version(struct uhidpp_softc *sc, uint8_t device_id,
uint8_t *major, uint8_t *minor)