vazhnov / sunxi-axp209

Shell script to read the AXP209 power IC registers
MIT License
0 stars 0 forks source link

./axp209.sh: line 225: [: 4.1932: integer expression expected #1

Open vazhnov opened 3 years ago

vazhnov commented 3 years ago

SBC Olimex A20-OLinuXino-LIME2, Debian 10 Buster, Bash 5.0:

 $ sudo bash ./axp209.sh   
Temperature:    43.7°C
ACIN:   4.9946V   406.125mA
VBUS:   0V
4.1932
./axp209.sh: line 226: [: 4.1932: integer expression expected

Here is the code, which gave an error when VBAT = 4.1932:

  if [ $VBAT -gt 0 ];then

After ugly workaround:

 $ sudo bash ./axp209.sh
Temperature:    43.3°C
ACIN:   5.0150V   388.125mA
VBUS:   0V
VBAT:   4.1932V  Charging at 269.0mA
Vout:   4.9322V
vazhnov commented 3 years ago

I probably should use some advice from https://stackoverflow.com/questions/8654051/how-to-compare-two-floating-point-numbers-in-bash

vazhnov commented 3 years ago

Similar error when the battery is not connected, and VBUS_C = -:

 $ sudo bash ./axp209.sh -a
              ACIN: 1   Avail: 1
              VBUS: 0   Avail: 0
             VHOLD: 0 (Whether VBUS is above 4.4V before being used)
  Shutdown voltage: 2.9V
VBUS current limit: 900mA
Boot source is ACIN/VBUS
Battery connected: 0
No Battery connected
Temperature:    39.2°C
Battery: -%
ACIN:   5.0490V   276.000mA
VBUS:   -V./axp209.sh: line 225: [: -: integer expression expected

./axp209.sh: line 231: [: -: integer expression expected

Here is the code:

if [ $VBUS_C -gt 0 ];then
vazhnov commented 3 years ago

https://github.com/vazhnov/sunxi-axp209/commit/9355e0ce14ee7b55d801d4930971e0891947e18f — replaced -gt to !=. So now logic should work when variable is 0 or any digit (integer or not), but logic probably broke when variable is -.

Result without battery:

 % sudo bash ./axp209.sh -a
              ACIN: 1   Avail: 1
              VBUS: 0   Avail: 0
             VHOLD: 0 (Whether VBUS is above 4.4V before being used)
  Charge direction: 0   (0:Battery discharging; 1:The battery is charging)
  Shutdown voltage: 2.9V
VBUS current limit: 900mA
Boot source is ACIN/VBUS
Battery connected: 0
No Battery connected
Temperature:    39.2°C
Battery: -%
ACIN:   5.0456V   280.125mA
VBUS:   -V   -mA
VBAT:   -V  Discharging at mA
Vout:   4.9616V

Result with a charging battery:

 % sudo bash ./axp209.sh -a
              ACIN: 1   Avail: 1
              VBUS: 0   Avail: 0
             VHOLD: 0 (Whether VBUS is above 4.4V before being used)
  Charge direction: 1   (0:Battery discharging; 1:The battery is charging)
  Shutdown voltage: 2.9V
VBUS current limit: 900mA
Boot source is ACIN/VBUS
Battery charging
Battery connected: 1
Temperature:    42.3°C
Battery: 92%
ACIN:   4.9453V   554.250mA
VBUS:   -V   -mA
VBAT:   4.2031V  Charging at 594.0mA
Vout:   4.8538V

Result with a discharging battery:

 % sudo bash ./axp209.sh -a
              ACIN: 0   Avail: 0
              VBUS: 0   Avail: 0
             VHOLD: 0 (Whether VBUS is above 4.4V before being used)
  Charge direction: 0   (0:Battery discharging; 1:The battery is charging)
  Shutdown voltage: 2.9V
VBUS current limit: 900mA
Boot source is ACIN/VBUS
Battery connected: 1
Temperature:    39.3°C
Battery: 100%
ACIN:   -V   -mA
VBUS:   -V   -mA
VBAT:   4.0997V  Discharging at 227.0mA
Vout:   4.0628V

(here exit code is 1).