From a3ddccceb83912d248470a06ff7e7a9b871b0422 Mon Sep 17 00:00:00 2001 From: Kelly Byrd Date: Wed, 15 Nov 2023 10:23:39 -0800 Subject: [PATCH 1/4] battery.runtime, status OL/OB and more for Arduino subdriver Add support for the common status flags as well as time remaining, battery voltage and other variables found in other HID subdrivers. The Arduino library always supported these items, just the NUT subdriver didn't pick them up so things like status were always OB. Signed-off-by: Kelly Byrd --- drivers/arduino-hid.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/arduino-hid.c b/drivers/arduino-hid.c index 5b74c12802..4cfff3f55b 100644 --- a/drivers/arduino-hid.c +++ b/drivers/arduino-hid.c @@ -1,4 +1,7 @@ /* arduino-hid.c - subdriver to monitor Arduino USB/HID devices with NUT + * + * This was written assuming it would be used to communicate with code + * using this Arduino library: https://github.com/abratchik/HIDPowerDevice * * Copyright (C) * 2003 - 2012 Arnaud Quette @@ -6,6 +9,7 @@ * 2008 - 2009 Arjen de Korte * 2013 Charles Lepple * 2021 Alex Bratchik + * 2023 Kelly Byrd * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. @@ -32,7 +36,7 @@ #include "main.h" /* for getval() */ #include "usb-common.h" -#define ARDUINO_HID_VERSION "Arduino HID 0.2" +#define ARDUINO_HID_VERSION "Arduino HID 0.3" /* FIXME: experimental flag to be put in upsdrv_info */ /* Arduino */ @@ -90,6 +94,37 @@ static hid_info_t arduino_hid2nut[] = { { "shutdown.stop", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.PowerSummary.DelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL }, + /* Battery */ + { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, stringid_conversion}, + /* In the sample for the Arduino library, this isn't a date */ + /*{ "battery.mfr.date", 0, 0, "UPS.PowerSummary.iOEMInformation", NULL, "%s", HU_FLAG_STATIC, stringid_conversion},*/ + { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.2f", HU_FLAG_QUICK_POLL, NULL}, + { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.2f", HU_FLAG_QUICK_POLL, NULL}, + { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, + { "battery.runtime.low", 0, 0, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, + /* Parse `*Capacity` values assuming `UPS.PowerSummary.CapacityMode` is set to 2, which means the `*Capacity` + units are percent. The Arduino HID Powerdevice library is capable of doing other modes, if the Sketch wants + to use them, but it appears most drivers just assume percent. + */ + { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, + { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL}, + { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL}, + + /* USB HID PresentStatus Flags + TODO: Parse these into battery.charger.status + */ + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info}, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info}, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info}, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info}, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BatteryPresent", NULL, NULL, 0, nobattery_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyCharged", NULL, NULL, HU_FLAG_QUICK_POLL, fullycharged_info }, + { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyDischarged", NULL, NULL, HU_FLAG_QUICK_POLL, depleted_info }, + /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; From fb0d5785be23f6019e65e5b82578b35cfbbf4ad5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 16 Nov 2023 08:56:09 +0100 Subject: [PATCH 2/4] Update arduino-hid.c Signed-off-by: Jim Klimov --- drivers/arduino-hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/arduino-hid.c b/drivers/arduino-hid.c index 4cfff3f55b..59206cbfd0 100644 --- a/drivers/arduino-hid.c +++ b/drivers/arduino-hid.c @@ -36,7 +36,7 @@ #include "main.h" /* for getval() */ #include "usb-common.h" -#define ARDUINO_HID_VERSION "Arduino HID 0.3" +#define ARDUINO_HID_VERSION "Arduino HID 0.21" /* FIXME: experimental flag to be put in upsdrv_info */ /* Arduino */ From 6ced3665ec3d14b71d7d9d25d82bd8677013509c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 16 Nov 2023 08:59:45 +0100 Subject: [PATCH 3/4] Update NEWS.adoc Signed-off-by: Jim Klimov --- NEWS.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.adoc b/NEWS.adoc index 7800cf2f13..feaec19e5e 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -79,6 +79,11 @@ https://github.com/networkupstools/nut/milestone/10 - powerpanel text driver now handles status responses in any format and should support most devices [#2156] + - usbhid-ups driver: + * `arduino-hid` subdriver was enhanced from "initial barebones" experimental + set of mapped data points to support some 20 more mappings to make it more + useful as an UPS driver, not just a controller developer sandbox. [#2188] + Release notes for NUT 2.8.1 - what's new since 2.8.0 ---------------------------------------------------- From 4c1d0487c0b5fa1feb559a25b3728855ec2135df Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 16 Nov 2023 09:38:54 +0100 Subject: [PATCH 4/4] NEWS.adoc: update for arduino-hid [#2188] Signed-off-by: Jim Klimov --- NEWS.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.adoc b/NEWS.adoc index feaec19e5e..fd7da4db11 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -80,7 +80,7 @@ https://github.com/networkupstools/nut/milestone/10 support most devices [#2156] - usbhid-ups driver: - * `arduino-hid` subdriver was enhanced from "initial barebones" experimental + * `arduino-hid` subdriver was enhanced from "initial bare bones" experimental set of mapped data points to support some 20 more mappings to make it more useful as an UPS driver, not just a controller developer sandbox. [#2188]