Now when there's a violation of the USB PD power rules, an icon appears
to alert the user to their charger's noncompliance. The icon has a
tooltip explaining its meaning.
Assuming the power supply follows the Power Rules, it's a lot more
informative to show its PDP than the number of PDOs it advertises. This
is the first step towards implementing the new design for showing the
Source_Capabilities.
It's a simple GtkMessageDialog with the text returned by the
`get_source_cap` command. Nothing fancy, but it works great.
Great, that is, except for the bug I found in the Python library. Off
to go fix that!
To add support for the new features in firmware 1.1.0, I decided to
split the Sink screen into two sections: Configuration and Power
Delivery. The Configuration section contains all the things the Sink
screen had before, with some layout changes (notably the Save button is
part of the Configuration section, not in the HeaderBar). The Power
Delivery section has the new features: an Output switch, which works
perfectly, and a currently half-baked Source Capabilities list item
which will eventually open a window to show the capabilities, but for
now just prints them.
Since SinkConfig is a kind of tuple now, it's immutable. This means
everything that changes it has to create a new one, so the "clean"
configuration object doesn't need to be a whole copy of the original
one. This commit makes it just another pointer to the same object.
Before, we showed the contents of tmpcfg when the device had no
configuration. This caused some problems when the device was erased,
then opened in the GUI: the contents of tmpcfg were still displayed
despite the device having no configuration, which was confusing. Now
empty configuration is shown in this case.
When a device is selected from the list, its configuration is loaded
into the tmpcfg buffer. When this failed due to there being no
configuration in the device, the ensuing exception prevented the device
from being configured by the GUI.
Now we explicitly silence the KeyError when loading configuration. The
tmpcfg is still valid, so it can be read and manipulated just as always.
Since I was clever enough to implement equality testing for SinkConfig,
the Save button's visibility can now be checked with a single comparison
of two SinkConfig objects. Wonderful!
Now instead of editing configuration on the device, we keep a SinkConfig
locally and manipulate it there. Much less error-prone, and things can
still get even better than they are now.
There was a bug where a device could end up being programmed with 0
current if the device was disconnected and reconnected while editing its
configuration. I thought of several solutions for this, but concluded
that the right one would really be to go ahead with my original plan to
kick the user out of the configuration screen when the device was
unplugged. As usual, the implementation could be better, but it works.
Previously, we updated the Save button before sending the commands.
This meant that if the command failed, the save button was still updated
before the error dialog appeared, which was a bit odd. Now that's
fixed.
Before now, if an error occurred when sending a command, it passed
silently. This is a Bad Thing™, so it's been fixed. Now if there's an
error, an error dialog appears with some information about what
happened. If the error occurred on the Sink page, the program goes back
to the device list after the error dialog is closed.
Before now, the Save button appeared when the voltage and current
widgets changed their value. If they were then changed back to the
original values, the Save button was still visible, allowing unnecessary
wear on the flash. (the sarcastic horror!)
Now, the Save button is only shown when the voltage and current are not
both at their saved values. A minor tweak, but we're closer to the
original design now.
Previously, the SelectListStore directly modified the GUI in its
update_items method, which was really just poor form.
This has been corrected by creating a new SelectList to encapsulate all
the GUI elements from the select-stack downward. This handles showing
the select-none or select-frame elements as appropriate, as well as
adding the list item separators. It's much nicer than the old way, if I
do say so myself.
Previously, we refreshed the list by completely erasing it and building
a new one. While simple, it caused some obnoxious visual glitches, and
I could imagine some more serious problems it might have caused as well.
Now we remove only the devices that don't exist any more, and add only
those that we don't already know about. Much better for the user
interface, but O(n^2). Oh well, I doubt anyone will have enough PD
Buddies connected at once for that to matter much.
Previously, the device list only loaded once on startup. This was poor
behaviour, as devices can be attached and detached at any time.
Now the attached devices are polled once per second, and the list is
updated accordingly. The code behind it is a bit messy because the
list model interacts directly with parts of the GUI, but it works
pretty well nevertheless. There's no mechanism to kick us out of the
configuration screen if the device we're configuring is detached, but
this can be addressed later. For now, I'm reasonably happy with this
new feature.
It's by no means wonderful internally, but to a large extent it works.
The list functionality is still untested, since I won't be able to have
two PDB Sinks connected to my computer at once until tomorrow. But for
now, a neat little GUI.