Friday, September 10, 2021

Release of pbarwin.cpp With Showing Wear Level

I talked before about how the source for pbarwin.cpp was too long to dump out.

Well, that problem has been solved. I just released it on my website instead.

The last time I wrote about pbarwin.cpp, I talked about how I fixed the indicator mechanism as well as incorporated a run-time/charge-time estimator. This time, I added one final bit of information that I had been mulling about for a bit: an indication of the wear and tear of the batteries involved.

The idea here is that from the BATTERY_INFORMATION structure, one can use DesignedCapacity and compare it to FullChargedCapacity to determine the associated wear-and-tear from the difference between them. Since they are returned by the same API call per enumerated battery anyway, there is no added cost to obtain the information. The problem then reduced to how to present that information.

My initial idea was to provide a numerical output per battery to show the proportion of the full battery was available for use, modified by the existing gauge. So a battery with a full charge (i.e. 100%) with the FullChargedCapacity being 80% of the DesignedCapacity will be shown as [%%%]x0.8 in the output. The larger capacity gauge remained unchanged and showed the percentage that would be equivalent to what Windows reports.

But I didn't like it. It gave good information, but it was using up too much horizontal space for too little information. It also didn't translate well from a visualisation perspective because I was mixing a graphical gauge against a numerical one to make sense.

And so I went back to the metaphorical drawing board and rethought things a little.

I settled upon the idea of adjusting the gauge itself to show all the different capacities. The idea is that the whole gauge would use DesignedCapacity (since DesignedCapacity ought to be the largest value that the battery can be in), then FullChargedCapacity is a fraction of DesignedCapacity to form an ``inner'' gauge, followed by using Capacity from BATTERY_STATUS structure to fill up the gauge.

That was the easy part.

The difficult part was how to figure out what to pad the decreased gauge bar with. My original concept was to just drop the right gauge end character `]'. But it looked bad. I mean, [%%%%%%%%]]] just looks wrong. I didn't want to use the character for the ``empty'' part of the gauge (`-'), and played around with other characters before settling on `:'. I liked how it looked. I also adjusted the per-battery miniature battery to span 5 spaces instead of 3, so that the wear level can go at 20% levels instead of the much larger 33%.

Anyway, here's how it looks like now:
As I mentioned earlier, I released the source on my website, and also included a convenience package which included the Cygwin DLLs. I had tried to recompile it for Windows using Visual Studio, but I immediately ran into yet another Windows fuckery---windows.h redefines max() using a pre-processor macro.

🤦‍♂️

The fix, mercifully, was simple. Shove the line #define NOMINMAX before including windows.h. This means that the magic incantation needed is now:
#define NOMINMAX
#include <windows.h>
#include <winbase.h>
#include <Setupapi.h>

#define INITGUID
#include <guiddef.h>
#include <devguid.h>
#include <BatClass.h>
I also had to resolve a linker issue, but the details on how to do so can be seen in my website.

What was funny was that the ``native'' compilation of pbarwin.cpp did lead to a smaller file (about 19 kiB compared to the 190+ kiB one from Cygwin), but it ran about an order of magnitude slower in comparison (about 110+ ms versus the 40 ms).

And so, I think I might have run out of things to update pbarwin.cpp. I mean, I could start taking into account other factors like CriticalBias, DefaultAlert1, and DefaultAlert2. But they aren't as useful, really.

------

In other news, I've started reading After the Absolute: The Inner Teachings of Richard Rose by David Gold, and Bart Marshall as well. It's too early to tell if it will be a thought-provoking read yet, but early indicators are good.

That's about it for now. Till the next update.

No comments: