Skip to content

Commit

Permalink
Merge pull request #2188 from kellybyrd/krb/arduino_report_more_things
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov authored Nov 16, 2023
2 parents 98a4607 + 4c1d048 commit 77348ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 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]

Release notes for NUT 2.8.1 - what's new since 2.8.0
----------------------------------------------------
Expand Down
37 changes: 36 additions & 1 deletion drivers/arduino-hid.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* 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 <[email protected]>
* 2005 - 2006 Peter Selinger <[email protected]>
* 2008 - 2009 Arjen de Korte <[email protected]>
* 2013 Charles Lepple <[email protected]>
* 2021 Alex Bratchik <[email protected]>
* 2023 Kelly Byrd <[email protected]>
*
* Note: this subdriver was initially generated as a "stub" by the
* gen-usbhid-subdriver script. It must be customized.
Expand All @@ -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.21"
/* FIXME: experimental flag to be put in upsdrv_info */

/* Arduino */
Expand Down Expand Up @@ -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 }
};
Expand Down

0 comments on commit 77348ef

Please sign in to comment.