Add sensors to Hardware/Sensors page

This commit is contained in:
Stephen Horvath
2025-09-23 12:54:51 +10:00
parent f3b74ccc02
commit 70d3788dd6
5 changed files with 75 additions and 22 deletions

View File

@@ -27,17 +27,24 @@ import cros_ec_python.exceptions as ec_exceptions
class HardwarePage(Gtk.Box): class HardwarePage(Gtk.Box):
__gtype_name__ = 'HardwarePage' __gtype_name__ = 'HardwarePage'
hw_als = Gtk.Template.Child()
hw_als_label = Gtk.Template.Child()
hw_chassis = Gtk.Template.Child() hw_chassis = Gtk.Template.Child()
hw_chassis_label = Gtk.Template.Child() hw_chassis_label = Gtk.Template.Child()
hw_fp_pwr = Gtk.Template.Child()
hw_fp_pwr_en = Gtk.Template.Child()
hw_fp_pwr_dis = Gtk.Template.Child()
hw_priv_cam = Gtk.Template.Child() hw_priv_cam = Gtk.Template.Child()
hw_priv_cam_sw = Gtk.Template.Child() hw_priv_cam_sw = Gtk.Template.Child()
hw_priv_mic = Gtk.Template.Child() hw_priv_mic = Gtk.Template.Child()
hw_priv_mic_sw = Gtk.Template.Child() hw_priv_mic_sw = Gtk.Template.Child()
hw_lid_open = Gtk.Template.Child()
hw_fp_pwr = Gtk.Template.Child() hw_lid_open_sw = Gtk.Template.Child()
hw_fp_pwr_en = Gtk.Template.Child() hw_pwr_btn = Gtk.Template.Child()
hw_fp_pwr_dis = Gtk.Template.Child() hw_pwr_btn_sw = Gtk.Template.Child()
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
@@ -66,7 +73,13 @@ class HardwarePage(Gtk.Box):
GLib.timeout_add_seconds(1, self._update_hardware, app) GLib.timeout_add_seconds(1, self._update_hardware, app)
def _update_hardware(self, app): def _update_hardware(self, app):
success = False # Memmap (ALS and Lid Open)
als = ec_commands.memmap.get_als(app.cros_ec)
self.hw_als_label.set_label(f"{als[0]} lux" if als[0] != 65535 else "MAX")
switches = ec_commands.memmap.get_switches(app.cros_ec)
self.hw_lid_open_sw.set_active(switches["lid_open"])
self.hw_pwr_btn_sw.set_active(switches["power_button_pressed"])
# Chassis # Chassis
if not ec_commands.framework_laptop.EC_CMD_CHASSIS_INTRUSION in app.no_support: if not ec_commands.framework_laptop.EC_CMD_CHASSIS_INTRUSION in app.no_support:
try: try:
@@ -82,8 +95,6 @@ class HardwarePage(Gtk.Box):
self.hw_chassis.set_subtitle( self.hw_chassis.set_subtitle(
"Currently " + ("Open" if ec_chassis_open else "Closed") "Currently " + ("Open" if ec_chassis_open else "Closed")
) )
success = True
except ec_exceptions.ECError as e: except ec_exceptions.ECError as e:
if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND: if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND:
app.no_support.append( app.no_support.append(
@@ -104,8 +115,6 @@ class HardwarePage(Gtk.Box):
) )
self.hw_priv_cam_sw.set_active(ec_privacy["camera"]) self.hw_priv_cam_sw.set_active(ec_privacy["camera"])
self.hw_priv_mic_sw.set_active(ec_privacy["microphone"]) self.hw_priv_mic_sw.set_active(ec_privacy["microphone"])
success = True
except ec_exceptions.ECError as e: except ec_exceptions.ECError as e:
if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND: if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND:
app.no_support.append( app.no_support.append(
@@ -116,4 +125,4 @@ class HardwarePage(Gtk.Box):
else: else:
raise e raise e
return app.current_page == 4 and success return app.current_page == 4

View File

@@ -105,7 +105,7 @@ class YafiApplication(Adw.Application):
("LEDs", LedsPage()), ("LEDs", LedsPage()),
("Battery", BatteryPage()), ("Battery", BatteryPage()),
("Battery Limiter", BatteryLimiterPage()), ("Battery Limiter", BatteryLimiterPage()),
("Hardware", HardwarePage()), ("Sensors", HardwarePage()),
("About", None), ("About", None),
) )

View File

@@ -2,7 +2,7 @@
<!-- Created with Cambalache 0.96.1 --> <!-- Created with Cambalache 0.96.1 -->
<interface> <interface>
<!-- interface-name hardware.ui --> <!-- interface-name hardware.ui -->
<!-- interface-description The Hardware page for YAFI --> <!-- interface-description The Sensors page for YAFI -->
<!-- interface-copyright Steve-Tech --> <!-- interface-copyright Steve-Tech -->
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/> <requires lib="libadwaita" version="1.0"/>
@@ -15,7 +15,15 @@
<child> <child>
<object class="AdwActionRow"> <object class="AdwActionRow">
<property name="selectable">False</property> <property name="selectable">False</property>
<property name="title">Hardware Status</property> <property name="title">Sensors</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="hw_als">
<property name="title">Ambient Light Sensor</property>
<child>
<object class="GtkLabel" id="hw_als_label"/>
</child>
</object> </object>
</child> </child>
<child> <child>
@@ -26,6 +34,30 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="AdwActionRow" id="hw_fp_pwr">
<property name="title">Fingerprint</property>
<property name="visible">False</property>
<child>
<object class="GtkBox">
<property name="halign">end</property>
<property name="homogeneous">True</property>
<property name="spacing">5</property>
<property name="valign">center</property>
<child>
<object class="GtkButton" id="hw_fp_pwr_en">
<property name="label">Enable</property>
</object>
</child>
<child>
<object class="GtkButton" id="hw_fp_pwr_dis">
<property name="label">Disable</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child> <child>
<object class="AdwActionRow" id="hw_priv_cam"> <object class="AdwActionRow" id="hw_priv_cam">
<property name="subtitle">Use Privacy Switch</property> <property name="subtitle">Use Privacy Switch</property>
@@ -65,23 +97,35 @@
</object> </object>
</child> </child>
<child> <child>
<object class="AdwActionRow" id="hw_fp_pwr"> <object class="AdwActionRow" id="hw_lid_open">
<property name="title">Fingerprint</property> <property name="title">Lid Open</property>
<property name="visible">False</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="halign">end</property> <property name="halign">end</property>
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
<property name="spacing">5</property>
<property name="valign">center</property> <property name="valign">center</property>
<child> <child>
<object class="GtkButton" id="hw_fp_pwr_en"> <object class="GtkSwitch" id="hw_lid_open_sw">
<property name="label">Enable</property> <property name="active">True</property>
<property name="sensitive">False</property>
</object> </object>
</child> </child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow" id="hw_pwr_btn">
<property name="title">Power Button Pressed</property>
<child>
<object class="GtkBox">
<property name="halign">end</property>
<property name="homogeneous">True</property>
<property name="valign">center</property>
<child> <child>
<object class="GtkButton" id="hw_fp_pwr_dis"> <object class="GtkSwitch" id="hw_pwr_btn_sw">
<property name="label">Disable</property> <property name="active">True</property>
<property name="sensitive">False</property>
</object> </object>
</child> </child>
</object> </object>

View File

@@ -6,6 +6,6 @@
<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="abc3ee759974a5c92feb48cc258dbe7271d0402facf71fd5e779f2bb1a277e16"/> <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="37ea282198d9f60435f80e4adf8256cd2249e590dcad4b63af634d828673f1bf"/>
<ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/> <ui template-class="BatteryPage" filename="battery.ui" sha256="d495280cb543a26cdee1c2939e5af980d8d3878c326e360eeab4f05195cdbdc9"/>
</cambalache-project> </cambalache-project>

Binary file not shown.