@@ -64,9 +64,9 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
6464 ffStrbufInit (& result -> manufacturer );
6565 ffStrbufInit (& result -> modelName );
6666 ffStrbufInit (& result -> technology );
67- ffStrbufInit (& result -> status );
6867 ffStrbufInit (& result -> serial );
6968 ffStrbufInit (& result -> manufactureDate );
69+ result -> status = FF_BATTERY_STATUS_NONE ;
7070 result -> capacity = ffStrbufToDouble (& tmpBuffer , 0 );
7171 result -> cycleCount = 0 ;
7272 result -> temperature = FF_BATTERY_TEMP_UNSET ;
@@ -88,21 +88,23 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
8888 ffStrbufTrimRightSpace (& result -> technology );
8989 }
9090
91- if (ffReadFileBufferRelative (dfd , "status" , & result -> status )) {
92- ffStrbufTrimRightSpace (& result -> status );
91+ if (ffReadFileBufferRelative (dfd , "status" , & tmpBuffer )) {
92+ ffStrbufTrimRightSpace (& tmpBuffer );
9393 }
9494
9595 // Unknown, Charging, Discharging, Not charging, Full
9696
97- if (ffStrbufEqualS (& result -> status , "Discharging" )) {
98- if (ffReadFileBufferRelative (dfd , "time_to_empty_now" , & tmpBuffer )) {
99- result -> timeRemaining = (int32_t ) ffStrbufToSInt (& tmpBuffer , 0 );
97+ if (ffStrbufEqualS (& tmpBuffer , "Discharging" )) {
98+ result -> status |= FF_BATTERY_STATUS_DISCHARGING ;
99+ FF_STRBUF_AUTO_DESTROY now = ffStrbufCreate ();
100+ if (ffReadFileBufferRelative (dfd , "time_to_empty_now" , & now )) {
101+ result -> timeRemaining = (int32_t ) ffStrbufToSInt (& now , 0 );
100102 } else {
101- if (ffReadFileBufferRelative (dfd , "charge_now" , & tmpBuffer )) {
102- int64_t chargeNow = ffStrbufToSInt (& tmpBuffer , 0 );
103+ if (ffReadFileBufferRelative (dfd , "charge_now" , & now )) {
104+ int64_t chargeNow = ffStrbufToSInt (& now , 0 );
103105 if (chargeNow > 0 ) {
104- if (ffReadFileBufferRelative (dfd , "current_now" , & tmpBuffer )) {
105- int64_t currentNow = ffStrbufToSInt (& tmpBuffer , INT64_MIN );
106+ if (ffReadFileBufferRelative (dfd , "current_now" , & now )) {
107+ int64_t currentNow = ffStrbufToSInt (& now , INT64_MIN );
106108 if (currentNow < 0 ) {
107109 currentNow = - currentNow ;
108110 }
@@ -113,19 +115,16 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
113115 }
114116 }
115117 }
116- } else if (ffStrbufEqualS (& result -> status , "Not charging" ) ||
117- ffStrbufEqualS (& result -> status , "Full" )) {
118- ffStrbufClear (& result -> status );
118+ } else if (ffStrbufEqualS (& tmpBuffer , "Charging" )) {
119+ result -> status |= FF_BATTERY_STATUS_CHARGING ;
120+ } else if (ffStrbufEqualS (& tmpBuffer , "Unknown" )) {
121+ result -> status |= FF_BATTERY_STATUS_UNKNOWN ;
119122 }
120123
121124 if (ffReadFileBufferRelative (dfd , "capacity_level" , & tmpBuffer )) {
122125 ffStrbufTrimRightSpace (& tmpBuffer );
123126 if (ffStrbufEqualS (& tmpBuffer , "Critical" )) {
124- if (result -> status .length ) {
125- ffStrbufAppendS (& result -> status , ", Critical" );
126- } else {
127- ffStrbufSetStatic (& result -> status , "Critical" );
128- }
127+ result -> status |= FF_BATTERY_STATUS_CRITICAL ;
129128 }
130129 }
131130
@@ -164,8 +163,8 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
164163 }
165164 }
166165
167- FF_DEBUG ("Battery \"%s\": Capacity: %.2f%%, Status: \"%s \", Time Remaining: %d seconds, Temperature: %.1f°C, Cycle Count: %u" ,
168- id , result -> capacity , result -> status . chars , result -> timeRemaining , result -> temperature , result -> cycleCount );
166+ FF_DEBUG ("Battery \"%s\": Capacity: %.2f%%, Status: \"%x \", Time Remaining: %d seconds, Temperature: %.1f°C, Cycle Count: %u" ,
167+ id , result -> capacity , result -> status , result -> timeRemaining , result -> temperature , result -> cycleCount );
169168 return true;
170169}
171170
@@ -191,11 +190,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
191190
192191 if (acConnected ) {
193192 FF_LIST_FOR_EACH (FFBatteryResult , batt , * results ) {
194- if (batt -> status .length ) {
195- ffStrbufAppendS (& batt -> status , ", AC Connected" );
196- } else {
197- ffStrbufSetStatic (& batt -> status , "AC Connected" );
198- }
193+ batt -> status |= FF_BATTERY_STATUS_AC_CONNECTED ;
199194 }
200195 }
201196
0 commit comments