Download raw body.
upd(4): add more sensors (load, power..)
Le Thu, Nov 21, 2024 at 06:02:31PM +0100, Landry Breuil a écrit :
> Le Tue, Nov 19, 2024 at 10:51:00AM +0000, Stuart Henderson a écrit :
> > On 2024/11/19 10:19, Walter Alejandro Iglesias wrote:
> > > On Sat, Nov 16, 2024 at 12:30:47PM +0100, Landry Breuil wrote:
> > > > so if you have an upd(4) somewhere and you have sensors, i'll be glad to
> > > > know if:
> > > > - you get more sensors and they make sense
> > > > - you get values that make more sense than before
> > > > - you had a value for RunTimeToEmpty that made sense and now doesn't
> > > > (same for AtRateTimeToEmpty/AtRateTimeToFull if you have them)
> > > > - it now breaks/detaches/reattaches
<snip>
> i'll have to digest the laaarge output produced by usbhid-ups -DDDDD to
> understand what is read from which usb register/reportid, and how those
> are converted to the end-user values.
that'll be for a bit later..
> my idea would be to:
> - enable the PercentLoad sensor
> - fix RunTimeToEmpty for EATON models
here's a diff (below) that does _just_ that, for a start. gives this here:
hw.sensors.upd0.percent2=25.00% (PercentLoad), OK
hw.sensors.upd0.timedelta0=917.352000 secs (RunTimeToEmpty), OK
which matches the LCD. Afaict the 3 reports we got from EATON ups were
all broken so far, so i'm assuming all MGE (eg vendor 0x0463) have the
same issue. Lmk if the vendor matching is done wrong, or if a
quirks-like system has to be designed.
i'll try to come back to the power/realpower/apparentpower madness
later.
Landry
Index: upd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/upd.c,v
diff -u -r1.32 upd.c
--- upd.c 23 May 2024 03:21:09 -0000 1.32
+++ upd.c 25 Nov 2024 16:37:51 -0000
@@ -32,6 +32,7 @@
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbhid.h>
+#include <dev/usb/usbdevs.h>
#include <dev/usb/uhidev.h>
#ifdef UPD_DEBUG
@@ -60,6 +61,8 @@
SENSOR_PERCENT, "RemainingCapacity" },
{ HUP_BATTERY, HUB_FULLCHARGE_CAPACITY,
SENSOR_PERCENT, "FullChargeCapacity" },
+ { HUP_POWER, HUP_PERCENT_LOAD,
+ SENSOR_PERCENT, "PercentLoad" },
{ HUP_BATTERY, HUB_CHARGING,
SENSOR_INDICATOR, "Charging" },
{ HUP_BATTERY, HUB_DISCHARGING,
@@ -107,6 +110,7 @@
struct uhidev sc_hdev;
int sc_num_sensors;
u_int sc_max_repid;
+ int sc_vendor;
char sc_buf[256];
/* sensor framework */
@@ -186,6 +190,7 @@
strlcpy(sc->sc_sensordev.xname, DEVNAME(sc),
sizeof(sc->sc_sensordev.xname));
+ sc->sc_vendor = uha->uaa->vendor;
sc->sc_max_repid = uha->parent->sc_nrepid;
DPRINTF(("\nupd: devname=%s sc_max_repid=%d\n",
DEVNAME(sc), sc->sc_max_repid));
@@ -411,6 +416,7 @@
case HUB_ABS_STATEOF_CHARGE:
case HUB_REM_CAPACITY:
case HUB_FULLCHARGE_CAPACITY:
+ case HUP_PERCENT_LOAD:
adjust = 1000; /* scale adjust */
break;
case HUB_ATRATE_TIMETOFULL:
@@ -418,6 +424,8 @@
case HUB_RUNTIMETO_EMPTY:
/* spec says minutes, not seconds */
adjust = 1000000000LL;
+ if (sc->sc_vendor == USB_VENDOR_MGE)
+ adjust = 60*60*1000LL;
break;
default:
adjust = 1; /* no scale adjust */
upd(4): add more sensors (load, power..)