Skip to content

Commit

Permalink
drivers/usbhid-ups.c, NEWS.adoc: complete the support of onlinedischa…
Browse files Browse the repository at this point in the history
…rge_log_throttle_hovercharge setting [networkupstools#2215, networkupstools#2423]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed May 2, 2024
1 parent 64dcd87 commit 35bb8eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ https://github.com/networkupstools/nut/milestone/11
as known supported by `nutdrv_qx` (Megatec protocol) since at least
NUT v2.7.4 release [#2395]
- usbhid-ups updates:
* Support of the `onlinedischarge_log_throttle_hovercharge` in the NUT
v2.8.2 release was found to be incomplete. [#2423, follow-up to #2215]
- USB drivers could log `(nut_)libusb_get_string: Success` due to either
reading an empty string or getting a success code `0` from libusb.
This difference should now be better logged, and not into syslog. [#2399]
Expand Down
41 changes: 32 additions & 9 deletions drivers/usbhid-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* 2005-2006 Peter Selinger <[email protected]>
* 2007-2009 Arjen de Korte <[email protected]>
* 2016 Eaton / Arnaud Quette <[email protected]>
* 2020-2024 Jim Klimov <[email protected]>
*
* This program was sponsored by MGE UPS SYSTEMS, and now Eaton
*
Expand All @@ -28,7 +29,7 @@
*/

#define DRIVER_NAME "Generic HID driver"
#define DRIVER_VERSION "0.53"
#define DRIVER_VERSION "0.54"

#define HU_VAR_WAITBEFORERECONNECT "waitbeforereconnect"

Expand Down Expand Up @@ -1348,6 +1349,21 @@ void upsdrv_initups(void)
}
}

val = getval("onlinedischarge_log_throttle_hovercharge");
if (val) {
int ipv = atoi(val);
if (ipv < 1 || ipv > 100) {
onlinedischarge_log_throttle_hovercharge = 100;
upslogx(LOG_WARNING,
"Warning: invalid value for "
"onlinedischarge_log_throttle_hovercharge: %s, "
"defaulting to %d",
val, onlinedischarge_log_throttle_hovercharge);
} else {
onlinedischarge_log_throttle_hovercharge = ipv;
}
}

if (testvar("disable_fix_report_desc")) {
disable_fix_report_desc = 1;
}
Expand Down Expand Up @@ -2032,14 +2048,17 @@ static void ups_status_set(void)
) {
/* Charge has changed, but is it
* now low enough to worry? */
if (onlinedischarge_log_throttle_hovercharge
< onlinedischarge_log_throttle_charge
if (current_charge
< onlinedischarge_log_throttle_hovercharge
) {
upsdebugx(3, "%s: current "
"battery.charge=%d is under "
"onlinedischarge_log_throttle_charge=%d",
"onlinedischarge_log_throttle_hovercharge=%d "
"(previous onlinedischarge_log_throttle_charge=%d): %s",
__func__, current_charge,
onlinedischarge_log_throttle_charge);
onlinedischarge_log_throttle_hovercharge,
onlinedischarge_log_throttle_charge,
(current_charge > onlinedischarge_log_throttle_charge ? "charging" : "draining"));
do_logmsg = 1;
} else {
/* All seems OK, don't spam log
Expand All @@ -2048,9 +2067,12 @@ static void ups_status_set(void)
upsdebugx(5, "%s: current "
"battery.charge=%d "
"is okay compared to "
"onlinedischarge_log_throttle_charge=%d",
"onlinedischarge_log_throttle_hovercharge=%d "
"(previous onlinedischarge_log_throttle_charge=%d): %s",
__func__, current_charge,
onlinedischarge_log_throttle_charge);
onlinedischarge_log_throttle_hovercharge,
onlinedischarge_log_throttle_charge,
(current_charge > onlinedischarge_log_throttle_charge ? "charging" : "draining"));
}
}
} else {
Expand Down Expand Up @@ -2104,9 +2126,10 @@ static void ups_status_set(void)
} else {
snprintf(msg_charge, sizeof(msg_charge),
"Battery charge changed from %d to %d "
"since last such report. ",
"since last such report (%s). ",
onlinedischarge_log_throttle_charge,
current_charge);
current_charge,
(current_charge > onlinedischarge_log_throttle_charge ? "charging" : "draining"));
}
onlinedischarge_log_throttle_charge = current_charge;
}
Expand Down

0 comments on commit 35bb8eb

Please sign in to comment.