Skip to content

Commit f3b74cc

Browse files
committed
Rework advanced LEDs
1 parent 335a088 commit f3b74cc

4 files changed

Lines changed: 43 additions & 98 deletions

File tree

yafi/leds.py

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
class LedsPage(Gtk.Box):
2828
__gtype_name__ = 'LedsPage'
2929

30+
first_run = True
31+
3032
led_pwr = Gtk.Template.Child()
3133
led_pwr_scale = Gtk.Template.Child()
3234

@@ -35,17 +37,12 @@ class LedsPage(Gtk.Box):
3537

3638
led_advanced = Gtk.Template.Child()
3739

38-
led_pwr_colour = Gtk.Template.Child()
39-
40-
led_chg_colour = Gtk.Template.Child()
41-
4240
def __init__(self, **kwargs):
4341
super().__init__(**kwargs)
4442

4543
def setup(self, app):
4644
# Power LED
4745
try:
48-
4946
def handle_led_pwr(scale):
5047
value = int(abs(scale.get_value() - 2))
5148
ec_commands.framework_laptop.set_fp_led_level(app.cros_ec, value)
@@ -84,31 +81,35 @@ def handle_led_kbd(scale):
8481
self.led_kbd.set_visible(False)
8582

8683
# Advanced options
87-
if ec_commands.general.get_cmd_versions(
88-
app.cros_ec, ec_commands.leds.EC_CMD_LED_CONTROL
84+
if (
85+
ec_commands.general.get_cmd_versions(
86+
app.cros_ec, ec_commands.leds.EC_CMD_LED_CONTROL
87+
)
88+
and self.first_run
8989
):
9090

91-
# Advanced: Power LED
92-
led_pwr_colour_strings = self.led_pwr_colour.get_model()
93-
9491
all_colours = ["Red", "Green", "Blue", "Yellow", "White", "Amber"]
95-
96-
def add_colours(strings, led_id):
97-
# Auto and Off should already be present
98-
if strings.get_n_items() <= 2:
99-
supported_colours = ec_commands.leds.led_control_get_max_values(
92+
led_names = {
93+
ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED: "Battery LED",
94+
ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED: "Power LED",
95+
ec_commands.leds.EcLedId.EC_LED_ID_ADAPTER_LED: "Adapter LED",
96+
ec_commands.leds.EcLedId.EC_LED_ID_LEFT_LED: "Left LED",
97+
ec_commands.leds.EcLedId.EC_LED_ID_RIGHT_LED: "Right LED",
98+
ec_commands.leds.EcLedId.EC_LED_ID_RECOVERY_HW_REINIT_LED: "Recovery LED",
99+
ec_commands.leds.EcLedId.EC_LED_ID_SYSRQ_DEBUG_LED: "SysRq LED",
100+
}
101+
leds = {}
102+
for i in range(ec_commands.leds.EcLedId.EC_LED_ID_COUNT.value):
103+
try:
104+
led_id = ec_commands.leds.EcLedId(i)
105+
leds[led_id] = ec_commands.leds.led_control_get_max_values(
100106
app.cros_ec, led_id
101107
)
102-
for i, colour in enumerate(all_colours):
103-
if supported_colours[i]:
104-
strings.append(colour)
105-
106-
try:
107-
add_colours(
108-
led_pwr_colour_strings, ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED
109-
)
110-
except ec_exceptions.ECError as e:
111-
self.led_pwr_colour.set_sensitive(False)
108+
except ec_exceptions.ECError as e:
109+
if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_PARAM:
110+
continue
111+
else:
112+
raise e
112113

113114
def handle_led_colour(combobox, led_id):
114115
colour = combobox.get_selected() - 2
@@ -132,30 +133,20 @@ def handle_led_colour(combobox, led_id):
132133
100,
133134
ec_commands.leds.EcLedColors(colour_idx),
134135
)
136+
for led_id, supported_colours in leds.items():
137+
if any(supported_colours):
138+
combo = Adw.ComboRow(title=led_names[led_id])
139+
model = Gtk.StringList.new(["Auto", "Off"])
140+
for i, colour in enumerate(all_colours):
141+
if supported_colours[i]:
142+
model.append(colour)
143+
combo.set_model(model)
144+
combo.connect(
145+
"notify::selected",
146+
lambda combobox, _, led_id=led_id: handle_led_colour(
147+
combobox, led_id
148+
),
149+
)
150+
self.led_advanced.add_row(combo)
135151

136-
self.led_pwr_colour.connect(
137-
"notify::selected",
138-
lambda combo, _: handle_led_colour(
139-
combo, ec_commands.leds.EcLedId.EC_LED_ID_POWER_LED
140-
),
141-
)
142-
143-
# Advanced: Charging LED
144-
led_chg_colour_strings = self.led_chg_colour.get_model()
145-
146-
try:
147-
add_colours(
148-
led_chg_colour_strings,
149-
ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED,
150-
)
151-
except ec_exceptions.ECError as e:
152-
self.led_chg_colour.set_sensitive(False)
153-
154-
self.led_chg_colour.connect(
155-
"notify::selected",
156-
lambda combo, _: handle_led_colour(
157-
combo, ec_commands.leds.EcLedId.EC_LED_ID_BATTERY_LED
158-
),
159-
)
160-
else:
161-
self.led_advanced.set_visible(False)
152+
self.first_run = False

yafi/ui/leds.ui

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,6 @@
6969
<property name="selectable">False</property>
7070
<property name="subtitle">These options break normal functionality</property>
7171
<property name="title">Advanced Options</property>
72-
<child>
73-
<object class="AdwPreferencesGroup">
74-
<property name="description">When using these options, the power LED may not turn off with the computer.</property>
75-
<property name="margin-bottom">5</property>
76-
<property name="margin-end">5</property>
77-
<property name="margin-start">5</property>
78-
<property name="margin-top">5</property>
79-
<property name="title">Power Button LED</property>
80-
<child>
81-
<object class="AdwComboRow" id="led_pwr_colour">
82-
<property name="model">
83-
<object class="GtkStringList">
84-
<items>
85-
<item>Auto</item>
86-
<item>Off</item>
87-
</items>
88-
</object>
89-
</property>
90-
<property name="title">Colour</property>
91-
</object>
92-
</child>
93-
</object>
94-
</child>
95-
<child>
96-
<object class="AdwPreferencesGroup">
97-
<property name="description">When using these options, the charging indicator will no longer indicate charging.</property>
98-
<property name="margin-bottom">5</property>
99-
<property name="margin-end">5</property>
100-
<property name="margin-start">5</property>
101-
<property name="margin-top">5</property>
102-
<property name="title">Charging Indicators</property>
103-
<child>
104-
<object class="AdwComboRow" id="led_chg_colour">
105-
<property name="model">
106-
<object class="GtkStringList">
107-
<items>
108-
<item>Auto</item>
109-
<item>Off</item>
110-
</items>
111-
</object>
112-
</property>
113-
<property name="title">Colour</property>
114-
</object>
115-
</child>
116-
</object>
117-
</child>
11872
</object>
11973
</child>
12074
<style>

yafi/ui/yafi.cmb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<cambalache-project version="0.96.0" target_tk="gtk-4.0">
55
<ui template-class="YafiWindow" filename="yafi.ui" sha256="9d1b2f030e4a816eb0b1aa53ae1d80c5b50a2f4646e32c7a64803eb6f6ed3947"/>
66
<ui template-class="ThermalsPage" filename="thermals.ui" sha256="e301e65649005315ff60d250b60a47f6250ad6feb27db104051fcf0143cde173"/>
7-
<ui template-class="LedsPage" filename="leds.ui" sha256="0350d22d570de039d63602ba40925f17fff6680fd5909d2ebf19600f351eb0f2"/>
7+
<ui template-class="LedsPage" filename="leds.ui" sha256="abc3ee759974a5c92feb48cc258dbe7271d0402facf71fd5e779f2bb1a277e16"/>
88
<ui template-class="BatteryLimiterPage" filename="battery-limiter.ui" sha256="b5d41b19cb1fb7ca5b4bcfae43244e54111f5e8d8c51d95448d6a92b5185d2c4"/>
99
<ui template-class="HardwarePage" filename="hardware.ui" sha256="f4deec4e38e683fde97656802dbfb2a638ab46a0e36af5c9a37f277f49e2aabb"/>
1010
<ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/>

yafi/yafi.gresource

745 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)