Battery percentage incorrect?

DId recent changes to sound_library maybe do something to the calculation for say SAY_WHOLE or something?
100% battery (4.15 volts) shows and speaks voltage correctly,
but percentage is spoken as 20% while showing the correct 100%.

Volts first:

          sound_library_.SayNumber(battery_monitor.battery(), SAY_DECIMAL);
          sound_library_.SayVolts();
          PVLOG_NORMAL << "Battery Voltage: " << battery_monitor.battery() << "\n";

01:01:36.722 β†’ Battery Voltage: 4.15
01:01:37.889 β†’ unit = 0 vol = 0.50, Playing ProffieOS_Voicepack_Skoll/common/mnum/mnum4.wav
01:01:37.924 β†’ channels: 1 rate: 44100 bits: 16
01:01:38.389 β†’ Playing mpoint.wav, channels: 1 rate: 44100 bits: 16
01:01:38.852 β†’ unit = 0 vol = 0.50, Playing ProffieOS_Voicepack_Skoll/common/mnum/mnum1.wav
01:01:38.889 β†’ channels: 1 rate: 44100 bits: 16
01:01:39.314 β†’ unit = 0 vol = 0.50, Playing ProffieOS_Voicepack_Skoll/common/mnum/mnum4.wav
01:01:39.347 β†’ channels: 1 rate: 44100 bits: 16
01:01:39.770 β†’ Playing mvolts.wav, channels: 1 rate: 44100 bits: 16

But then percentage is:

          sound_library_.SayNumber(battery_monitor.battery_percent(), SAY_WHOLE);
          sound_library_.SayPercent();
          PVLOG_NORMAL << "Battery Percentage: " <<battery_monitor.battery_percent() << "%\n";

01:01:41.460 β†’ Battery Percentage: 100.00%
01:01:41.460 β†’ Playing battlevl.wav, channels: 1 rate: 44100 bits: 16
01:01:41.800 β†’ EVENT: Power-Released#3 millis=1636476
01:01:41.800 β†’ EVENT: Power-Released millis=1636476
01:01:42.638 β†’ unit = 0 vol = 0.50, Playing ProffieOS_Voicepack_Skoll/common/mnum/mnum20.wav
01:01:42.673 β†’ channels: 1 rate: 44100 bits: 16
01:01:43.327 β†’ Playing mpercent.wav, channels: 1 rate: 44100 bits: 16

For reference, I just put this fresh battery in because percentage was saying 8% on the one I had in (while volts was reported as 3.52V)

I think I found the typo.

    int thousands = number / 1000;
    if (thousands) {
      SayWhole(thousands);
      Say1000();
      number %= 1000;
    }
    int hundreds = number / 1000;
    if (hundreds) {
      SayWhole(hundreds);
      Say100();
      number %= 100;
    }

If my β€œrecent”, you mean April, then yes, I re-coded SayWhole()/SayNumber(), and possibly screwed them up.

Does it work better if you change / 1000 to / 100 ?

yes. was just submitting PR. Unless you just want to handle it

PR sounds perfect :slight_smile:

1 Like