Rework advanced LEDs

This commit is contained in:
Stephen Horvath
2025-09-21 22:30:24 +10:00
parent 335a0881b3
commit f3b74ccc02
4 changed files with 43 additions and 98 deletions

View File

@@ -27,6 +27,8 @@ import cros_ec_python.exceptions as ec_exceptions
class LedsPage(Gtk.Box): class LedsPage(Gtk.Box):
__gtype_name__ = 'LedsPage' __gtype_name__ = 'LedsPage'
first_run = True
led_pwr = Gtk.Template.Child() led_pwr = Gtk.Template.Child()
led_pwr_scale = Gtk.Template.Child() led_pwr_scale = Gtk.Template.Child()
@@ -35,17 +37,12 @@ class LedsPage(Gtk.Box):
led_advanced = Gtk.Template.Child() led_advanced = Gtk.Template.Child()
led_pwr_colour = Gtk.Template.Child()
led_chg_colour = Gtk.Template.Child()
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
def setup(self, app): def setup(self, app):
# Power LED # Power LED
try: try:
def handle_led_pwr(scale): def handle_led_pwr(scale):
value = int(abs(scale.get_value() - 2)) value = int(abs(scale.get_value() - 2))
ec_commands.framework_laptop.set_fp_led_level(app.cros_ec, value) ec_commands.framework_laptop.set_fp_led_level(app.cros_ec, value)
@@ -84,31 +81,35 @@ class LedsPage(Gtk.Box):
self.led_kbd.set_visible(False) self.led_kbd.set_visible(False)
# Advanced options # Advanced options
if ec_commands.general.get_cmd_versions( if (
ec_commands.general.get_cmd_versions(
app.cros_ec, ec_commands.leds.EC_CMD_LED_CONTROL app.cros_ec, ec_commands.leds.EC_CMD_LED_CONTROL
)
and self.first_run
): ):
# Advanced: Power LED
led_pwr_colour_strings = self.led_pwr_colour.get_model()
all_colours = ["Red", "Green", "Blue", "Yellow", "White", "Amber"] all_colours = ["Red", "Green", "Blue", "Yellow", "White", "Amber"]
led_names = {
def add_colours(strings, led_id): ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED: "Battery LED",
# Auto and Off should already be present ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED: "Power LED",
if strings.get_n_items() <= 2: ec_commands.leds.EcLedId.EC_LED_ID_ADAPTER_LED: "Adapter LED",
supported_colours = ec_commands.leds.led_control_get_max_values( ec_commands.leds.EcLedId.EC_LED_ID_LEFT_LED: "Left LED",
ec_commands.leds.EcLedId.EC_LED_ID_RIGHT_LED: "Right LED",
ec_commands.leds.EcLedId.EC_LED_ID_RECOVERY_HW_REINIT_LED: "Recovery LED",
ec_commands.leds.EcLedId.EC_LED_ID_SYSRQ_DEBUG_LED: "SysRq LED",
}
leds = {}
for i in range(ec_commands.leds.EcLedId.EC_LED_ID_COUNT.value):
try:
led_id = ec_commands.leds.EcLedId(i)
leds[led_id] = ec_commands.leds.led_control_get_max_values(
app.cros_ec, led_id app.cros_ec, led_id
) )
for i, colour in enumerate(all_colours):
if supported_colours[i]:
strings.append(colour)
try:
add_colours(
led_pwr_colour_strings, ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED
)
except ec_exceptions.ECError as e: except ec_exceptions.ECError as e:
self.led_pwr_colour.set_sensitive(False) if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_PARAM:
continue
else:
raise e
def handle_led_colour(combobox, led_id): def handle_led_colour(combobox, led_id):
colour = combobox.get_selected() - 2 colour = combobox.get_selected() - 2
@@ -132,30 +133,20 @@ class LedsPage(Gtk.Box):
100, 100,
ec_commands.leds.EcLedColors(colour_idx), ec_commands.leds.EcLedColors(colour_idx),
) )
for led_id, supported_colours in leds.items():
self.led_pwr_colour.connect( if any(supported_colours):
combo = Adw.ComboRow(title=led_names[led_id])
model = Gtk.StringList.new(["Auto", "Off"])
for i, colour in enumerate(all_colours):
if supported_colours[i]:
model.append(colour)
combo.set_model(model)
combo.connect(
"notify::selected", "notify::selected",
lambda combo, _: handle_led_colour( lambda combobox, _, led_id=led_id: handle_led_colour(
combo, ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED combobox, led_id
), ),
) )
self.led_advanced.add_row(combo)
# Advanced: Charging LED self.first_run = False
led_chg_colour_strings = self.led_chg_colour.get_model()
try:
add_colours(
led_chg_colour_strings,
ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED,
)
except ec_exceptions.ECError as e:
self.led_chg_colour.set_sensitive(False)
self.led_chg_colour.connect(
"notify::selected",
lambda combo, _: handle_led_colour(
combo, ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED
),
)
else:
self.led_advanced.set_visible(False)

View File

@@ -69,52 +69,6 @@
<property name="selectable">False</property> <property name="selectable">False</property>
<property name="subtitle">These options break normal functionality</property> <property name="subtitle">These options break normal functionality</property>
<property name="title">Advanced Options</property> <property name="title">Advanced Options</property>
<child>
<object class="AdwPreferencesGroup">
<property name="description">When using these options, the power LED may not turn off with the computer.</property>
<property name="margin-bottom">5</property>
<property name="margin-end">5</property>
<property name="margin-start">5</property>
<property name="margin-top">5</property>
<property name="title">Power Button LED</property>
<child>
<object class="AdwComboRow" id="led_pwr_colour">
<property name="model">
<object class="GtkStringList">
<items>
<item>Auto</item>
<item>Off</item>
</items>
</object>
</property>
<property name="title">Colour</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="description">When using these options, the charging indicator will no longer indicate charging.</property>
<property name="margin-bottom">5</property>
<property name="margin-end">5</property>
<property name="margin-start">5</property>
<property name="margin-top">5</property>
<property name="title">Charging Indicators</property>
<child>
<object class="AdwComboRow" id="led_chg_colour">
<property name="model">
<object class="GtkStringList">
<items>
<item>Auto</item>
<item>Off</item>
</items>
</object>
</property>
<property name="title">Colour</property>
</object>
</child>
</object>
</child>
</object> </object>
</child> </child>
<style> <style>

View File

@@ -4,7 +4,7 @@
<cambalache-project version="0.96.0" target_tk="gtk-4.0"> <cambalache-project version="0.96.0" target_tk="gtk-4.0">
<ui template-class="YafiWindow" filename="yafi.ui" sha256="9d1b2f030e4a816eb0b1aa53ae1d80c5b50a2f4646e32c7a64803eb6f6ed3947"/> <ui template-class="YafiWindow" filename="yafi.ui" sha256="9d1b2f030e4a816eb0b1aa53ae1d80c5b50a2f4646e32c7a64803eb6f6ed3947"/>
<ui template-class="ThermalsPage" filename="thermals.ui" sha256="e301e65649005315ff60d250b60a47f6250ad6feb27db104051fcf0143cde173"/> <ui template-class="ThermalsPage" filename="thermals.ui" sha256="e301e65649005315ff60d250b60a47f6250ad6feb27db104051fcf0143cde173"/>
<ui template-class="LedsPage" filename="leds.ui" sha256="0350d22d570de039d63602ba40925f17fff6680fd5909d2ebf19600f351eb0f2"/> <ui template-class="LedsPage" filename="leds.ui" sha256="abc3ee759974a5c92feb48cc258dbe7271d0402facf71fd5e779f2bb1a277e16"/>
<ui template-class="BatteryLimiterPage" filename="battery-limiter.ui" sha256="b5d41b19cb1fb7ca5b4bcfae43244e54111f5e8d8c51d95448d6a92b5185d2c4"/> <ui template-class="BatteryLimiterPage" filename="battery-limiter.ui" sha256="b5d41b19cb1fb7ca5b4bcfae43244e54111f5e8d8c51d95448d6a92b5185d2c4"/>
<ui template-class="HardwarePage" filename="hardware.ui" sha256="f4deec4e38e683fde97656802dbfb2a638ab46a0e36af5c9a37f277f49e2aabb"/> <ui template-class="HardwarePage" filename="hardware.ui" sha256="f4deec4e38e683fde97656802dbfb2a638ab46a0e36af5c9a37f277f49e2aabb"/>
<ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/> <ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/>

Binary file not shown.