2323#include "nut_stdint.h"
2424
2525#define DRIVER_NAME "PiJuice UPS driver"
26- #define DRIVER_VERSION "0.14 "
26+ #define DRIVER_VERSION "0.15 "
2727
2828/*
2929 * Linux I2C userland is a bit of a mess until distros refresh to
@@ -340,12 +340,9 @@ static void get_charge_level_hi_res(void)
340340static void get_status (void )
341341{
342342 uint8_t cmd = STATUS_CMD , data , batteryStatus , powerInput , powerInput5vIo ;
343- char status_buf [ST_MAX_VALUE_LEN ];
344343
345344 upsdebugx ( 3 , __func__ );
346345
347- memset ( status_buf , 0 , ST_MAX_VALUE_LEN );
348-
349346 I2C_READ_BYTE ( upsfd , cmd , __func__ )
350347
351348 batteryStatus = data >> 2 & 0x03 ;
@@ -422,17 +419,17 @@ static void get_status(void)
422419 if ( battery_charge_level <= LOW_BATTERY_THRESHOLD )
423420 {
424421 upsdebugx ( 1 , "Battery Charge Status: LOW" );
425- snprintfcat ( status_buf , ST_MAX_VALUE_LEN , "LB " );
422+ status_set ( "LB" );
426423 }
427424 else if ( battery_charge_level > HIGH_BATTERY_THRESHOLD )
428425 {
429426 upsdebugx ( 1 , "Battery Charge Status: HIGH" );
430- snprintfcat ( status_buf , ST_MAX_VALUE_LEN , "HB " );
427+ status_set ( "HB" );
431428 }
432429 }
433430 else if ( batteryStatus == BATT_NOT_PRESENT )
434431 {
435- snprintfcat ( status_buf , ST_MAX_VALUE_LEN , "RB " );
432+ status_set ( "RB" );
436433 }
437434
438435 if ( batteryStatus <= BATT_NOT_PRESENT &&
@@ -451,10 +448,10 @@ static void get_status(void)
451448 battery_power = 0 ;
452449 upsdebugx ( 1 , "On USB power [%d:%d:%d]" , usb_power , gpio_power , battery_power );
453450
454- snprintfcat ( status_buf , sizeof ( status_buf ), "OL" );
451+ status_set ( "OL" );
455452 if ( batteryStatus == BATT_CHARGING_FROM_5V )
456453 {
457- snprintfcat ( status_buf , sizeof ( status_buf ), " CHRG" );
454+ status_set ( " CHRG" );
458455 upsdebugx ( 1 , "Battery Charger Status: charging" );
459456 dstate_setinfo ( "battery.charger.status" , "%s" , "charging" );
460457 }
@@ -463,7 +460,6 @@ static void get_status(void)
463460 upsdebugx ( 1 , "Battery Charger Status: resting" );
464461 dstate_setinfo ( "battery.charger.status" , "%s" , "resting" );
465462 }
466- status_set ( status_buf );
467463 }
468464 else if ( powerInput5vIo == POWER_NOT_PRESENT &&
469465 ( powerInput != POWER_NOT_PRESENT &&
@@ -478,17 +474,15 @@ static void get_status(void)
478474 battery_power = 0 ;
479475 upsdebugx ( 1 , "On 5V_GPIO power [%d:%d:%d]" , usb_power , gpio_power , battery_power );
480476
481- snprintfcat ( status_buf , sizeof ( status_buf ), "OL" );
477+ status_set ( "OL" );
482478 if ( batteryStatus == BATT_CHARGING_FROM_IN )
483479 {
484- snprintfcat ( status_buf , sizeof (status_buf ), " CHRG" );
485- status_set ( status_buf );
480+ status_set ("CHRG" );
486481 upsdebugx ( 1 , "Battery Charger Status: charging" );
487482 dstate_setinfo ( "battery.charger.status" , "%s" , "charging" );
488483 }
489484 else if ( batteryStatus == BATT_NORMAL )
490485 {
491- status_set ( status_buf );
492486 upsdebugx ( 1 , "Battery Charger Status: resting" );
493487 dstate_setinfo ( "battery.charger.status" , "%s" , "resting" );
494488 }
@@ -505,17 +499,15 @@ static void get_status(void)
505499 battery_power = 0 ;
506500 upsdebugx ( 1 , "On USB and 5V_GPIO power [%d:%d:%d]" , usb_power , gpio_power , battery_power );
507501
508- snprintfcat ( status_buf , sizeof ( status_buf ), "OL" );
502+ status_set ( "OL" );
509503 if ( batteryStatus == BATT_CHARGING_FROM_IN )
510504 {
511- snprintfcat ( status_buf , sizeof (status_buf ), " CHRG" );
512- status_set ( status_buf );
505+ status_set ("CHRG" );
513506 upsdebugx ( 1 , "Battery Charger Status: charging" );
514507 dstate_setinfo ("battery.charger.status" , "%s" , "charging" );
515508 }
516509 else if ( batteryStatus == BATT_NORMAL )
517510 {
518- status_set ( status_buf );
519511 upsdebugx ( 1 , "Battery Charger Status: resting" );
520512 dstate_setinfo ( "battery.charger.status" , "%s" , "resting" );
521513 }
@@ -531,8 +523,8 @@ static void get_status(void)
531523 battery_power = 1 ;
532524 upsdebugx ( 1 , "On Battery power [%d:%d:%d]" , usb_power , gpio_power , battery_power );
533525
534- snprintfcat ( status_buf , sizeof ( status_buf ), "OB DISCHRG" );
535- status_set ( status_buf );
526+ status_set ( "OB" );
527+ status_set ("DISCHRG" );
536528 }
537529 }
538530}
0 commit comments