Skip to content

Commit 70d3788

Browse files
committed
Add sensors to Hardware/Sensors page
1 parent f3b74cc commit 70d3788

5 files changed

Lines changed: 75 additions & 22 deletions

File tree

yafi/hardware.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@
2727
class HardwarePage(Gtk.Box):
2828
__gtype_name__ = 'HardwarePage'
2929

30+
hw_als = Gtk.Template.Child()
31+
hw_als_label = Gtk.Template.Child()
32+
3033
hw_chassis = Gtk.Template.Child()
3134
hw_chassis_label = Gtk.Template.Child()
3235

36+
hw_fp_pwr = Gtk.Template.Child()
37+
hw_fp_pwr_en = Gtk.Template.Child()
38+
hw_fp_pwr_dis = Gtk.Template.Child()
39+
3340
hw_priv_cam = Gtk.Template.Child()
3441
hw_priv_cam_sw = Gtk.Template.Child()
3542
hw_priv_mic = Gtk.Template.Child()
3643
hw_priv_mic_sw = Gtk.Template.Child()
37-
38-
hw_fp_pwr = Gtk.Template.Child()
39-
hw_fp_pwr_en = Gtk.Template.Child()
40-
hw_fp_pwr_dis = Gtk.Template.Child()
44+
hw_lid_open = Gtk.Template.Child()
45+
hw_lid_open_sw = Gtk.Template.Child()
46+
hw_pwr_btn = Gtk.Template.Child()
47+
hw_pwr_btn_sw = Gtk.Template.Child()
4148

4249
def __init__(self, **kwargs):
4350
super().__init__(**kwargs)
@@ -66,7 +73,13 @@ def setup(self, app):
6673
GLib.timeout_add_seconds(1, self._update_hardware, app)
6774

6875
def _update_hardware(self, app):
69-
success = False
76+
# Memmap (ALS and Lid Open)
77+
als = ec_commands.memmap.get_als(app.cros_ec)
78+
self.hw_als_label.set_label(f"{als[0]} lux" if als[0] != 65535 else "MAX")
79+
switches = ec_commands.memmap.get_switches(app.cros_ec)
80+
self.hw_lid_open_sw.set_active(switches["lid_open"])
81+
self.hw_pwr_btn_sw.set_active(switches["power_button_pressed"])
82+
7083
# Chassis
7184
if not ec_commands.framework_laptop.EC_CMD_CHASSIS_INTRUSION in app.no_support:
7285
try:
@@ -82,8 +95,6 @@ def _update_hardware(self, app):
8295
self.hw_chassis.set_subtitle(
8396
"Currently " + ("Open" if ec_chassis_open else "Closed")
8497
)
85-
86-
success = True
8798
except ec_exceptions.ECError as e:
8899
if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND:
89100
app.no_support.append(
@@ -104,8 +115,6 @@ def _update_hardware(self, app):
104115
)
105116
self.hw_priv_cam_sw.set_active(ec_privacy["camera"])
106117
self.hw_priv_mic_sw.set_active(ec_privacy["microphone"])
107-
108-
success = True
109118
except ec_exceptions.ECError as e:
110119
if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND:
111120
app.no_support.append(
@@ -116,4 +125,4 @@ def _update_hardware(self, app):
116125
else:
117126
raise e
118127

119-
return app.current_page == 4 and success
128+
return app.current_page == 4

yafi/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def do_activate(self):
105105
("LEDs", LedsPage()),
106106
("Battery", BatteryPage()),
107107
("Battery Limiter", BatteryLimiterPage()),
108-
("Hardware", HardwarePage()),
108+
("Sensors", HardwarePage()),
109109
("About", None),
110110
)
111111

yafi/ui/hardware.ui

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Created with Cambalache 0.96.1 -->
33
<interface>
44
<!-- interface-name hardware.ui -->
5-
<!-- interface-description The Hardware page for YAFI -->
5+
<!-- interface-description The Sensors page for YAFI -->
66
<!-- interface-copyright Steve-Tech -->
77
<requires lib="gtk" version="4.0"/>
88
<requires lib="libadwaita" version="1.0"/>
@@ -15,7 +15,15 @@
1515
<child>
1616
<object class="AdwActionRow">
1717
<property name="selectable">False</property>
18-
<property name="title">Hardware Status</property>
18+
<property name="title">Sensors</property>
19+
</object>
20+
</child>
21+
<child>
22+
<object class="AdwActionRow" id="hw_als">
23+
<property name="title">Ambient Light Sensor</property>
24+
<child>
25+
<object class="GtkLabel" id="hw_als_label"/>
26+
</child>
1927
</object>
2028
</child>
2129
<child>
@@ -26,6 +34,30 @@
2634
</child>
2735
</object>
2836
</child>
37+
<child>
38+
<object class="AdwActionRow" id="hw_fp_pwr">
39+
<property name="title">Fingerprint</property>
40+
<property name="visible">False</property>
41+
<child>
42+
<object class="GtkBox">
43+
<property name="halign">end</property>
44+
<property name="homogeneous">True</property>
45+
<property name="spacing">5</property>
46+
<property name="valign">center</property>
47+
<child>
48+
<object class="GtkButton" id="hw_fp_pwr_en">
49+
<property name="label">Enable</property>
50+
</object>
51+
</child>
52+
<child>
53+
<object class="GtkButton" id="hw_fp_pwr_dis">
54+
<property name="label">Disable</property>
55+
</object>
56+
</child>
57+
</object>
58+
</child>
59+
</object>
60+
</child>
2961
<child>
3062
<object class="AdwActionRow" id="hw_priv_cam">
3163
<property name="subtitle">Use Privacy Switch</property>
@@ -65,23 +97,35 @@
6597
</object>
6698
</child>
6799
<child>
68-
<object class="AdwActionRow" id="hw_fp_pwr">
69-
<property name="title">Fingerprint</property>
70-
<property name="visible">False</property>
100+
<object class="AdwActionRow" id="hw_lid_open">
101+
<property name="title">Lid Open</property>
71102
<child>
72103
<object class="GtkBox">
73104
<property name="halign">end</property>
74105
<property name="homogeneous">True</property>
75-
<property name="spacing">5</property>
76106
<property name="valign">center</property>
77107
<child>
78-
<object class="GtkButton" id="hw_fp_pwr_en">
79-
<property name="label">Enable</property>
108+
<object class="GtkSwitch" id="hw_lid_open_sw">
109+
<property name="active">True</property>
110+
<property name="sensitive">False</property>
80111
</object>
81112
</child>
113+
</object>
114+
</child>
115+
</object>
116+
</child>
117+
<child>
118+
<object class="AdwActionRow" id="hw_pwr_btn">
119+
<property name="title">Power Button Pressed</property>
120+
<child>
121+
<object class="GtkBox">
122+
<property name="halign">end</property>
123+
<property name="homogeneous">True</property>
124+
<property name="valign">center</property>
82125
<child>
83-
<object class="GtkButton" id="hw_fp_pwr_dis">
84-
<property name="label">Disable</property>
126+
<object class="GtkSwitch" id="hw_pwr_btn_sw">
127+
<property name="active">True</property>
128+
<property name="sensitive">False</property>
85129
</object>
86130
</child>
87131
</object>

yafi/ui/yafi.cmb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<ui template-class="ThermalsPage" filename="thermals.ui" sha256="e301e65649005315ff60d250b60a47f6250ad6feb27db104051fcf0143cde173"/>
77
<ui template-class="LedsPage" filename="leds.ui" sha256="abc3ee759974a5c92feb48cc258dbe7271d0402facf71fd5e779f2bb1a277e16"/>
88
<ui template-class="BatteryLimiterPage" filename="battery-limiter.ui" sha256="b5d41b19cb1fb7ca5b4bcfae43244e54111f5e8d8c51d95448d6a92b5185d2c4"/>
9-
<ui template-class="HardwarePage" filename="hardware.ui" sha256="f4deec4e38e683fde97656802dbfb2a638ab46a0e36af5c9a37f277f49e2aabb"/>
9+
<ui template-class="HardwarePage" filename="hardware.ui" sha256="37ea282198d9f60435f80e4adf8256cd2249e590dcad4b63af634d828673f1bf"/>
1010
<ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/>
1111
</cambalache-project>

yafi/yafi.gresource

1.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)