From 70d3788dd66c86ff91cd725af71b5d7f4846ee35 Mon Sep 17 00:00:00 2001 From: Stephen Horvath Date: Tue, 23 Sep 2025 12:54:51 +1000 Subject: [PATCH] Add sensors to Hardware/Sensors page --- yafi/hardware.py | 29 +++++++++++++------- yafi/main.py | 2 +- yafi/ui/hardware.ui | 64 +++++++++++++++++++++++++++++++++++++------- yafi/ui/yafi.cmb | 2 +- yafi/yafi.gresource | Bin 27388 -> 28436 bytes 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/yafi/hardware.py b/yafi/hardware.py index fc25f2e..2e8f49a 100644 --- a/yafi/hardware.py +++ b/yafi/hardware.py @@ -27,17 +27,24 @@ import cros_ec_python.exceptions as ec_exceptions class HardwarePage(Gtk.Box): __gtype_name__ = 'HardwarePage' + hw_als = Gtk.Template.Child() + hw_als_label = Gtk.Template.Child() + hw_chassis = 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_sw = Gtk.Template.Child() hw_priv_mic = Gtk.Template.Child() hw_priv_mic_sw = Gtk.Template.Child() - - hw_fp_pwr = Gtk.Template.Child() - hw_fp_pwr_en = Gtk.Template.Child() - hw_fp_pwr_dis = Gtk.Template.Child() + hw_lid_open = Gtk.Template.Child() + hw_lid_open_sw = Gtk.Template.Child() + hw_pwr_btn = Gtk.Template.Child() + hw_pwr_btn_sw = Gtk.Template.Child() def __init__(self, **kwargs): super().__init__(**kwargs) @@ -66,7 +73,13 @@ class HardwarePage(Gtk.Box): GLib.timeout_add_seconds(1, self._update_hardware, 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 if not ec_commands.framework_laptop.EC_CMD_CHASSIS_INTRUSION in app.no_support: try: @@ -82,8 +95,6 @@ class HardwarePage(Gtk.Box): self.hw_chassis.set_subtitle( "Currently " + ("Open" if ec_chassis_open else "Closed") ) - - success = True except ec_exceptions.ECError as e: if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND: 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_mic_sw.set_active(ec_privacy["microphone"]) - - success = True except ec_exceptions.ECError as e: if e.ec_status == ec_exceptions.EcStatus.EC_RES_INVALID_COMMAND: app.no_support.append( @@ -116,4 +125,4 @@ class HardwarePage(Gtk.Box): else: raise e - return app.current_page == 4 and success + return app.current_page == 4 diff --git a/yafi/main.py b/yafi/main.py index 91ca9cb..2a78dba 100644 --- a/yafi/main.py +++ b/yafi/main.py @@ -105,7 +105,7 @@ class YafiApplication(Adw.Application): ("LEDs", LedsPage()), ("Battery", BatteryPage()), ("Battery Limiter", BatteryLimiterPage()), - ("Hardware", HardwarePage()), + ("Sensors", HardwarePage()), ("About", None), ) diff --git a/yafi/ui/hardware.ui b/yafi/ui/hardware.ui index 3511854..d4c9da6 100644 --- a/yafi/ui/hardware.ui +++ b/yafi/ui/hardware.ui @@ -2,7 +2,7 @@ - + @@ -15,7 +15,15 @@ False - Hardware Status + Sensors + + + + + Ambient Light Sensor + + + @@ -26,6 +34,30 @@ + + + Fingerprint + False + + + end + True + 5 + center + + + Enable + + + + + Disable + + + + + + Use Privacy Switch @@ -65,23 +97,35 @@ - - Fingerprint - False + + Lid Open end True - 5 center - - Enable + + True + False + + + + + + + Power Button Pressed + + + end + True + center - - Disable + + True + False diff --git a/yafi/ui/yafi.cmb b/yafi/ui/yafi.cmb index 8ed583e..31ef059 100644 --- a/yafi/ui/yafi.cmb +++ b/yafi/ui/yafi.cmb @@ -6,6 +6,6 @@ - + diff --git a/yafi/yafi.gresource b/yafi/yafi.gresource index 5fceb63af93e56b14a3ea9c4a5afe9b0c393bd45..7e4aff9cebed1e5c589dc9f4af99ec480d5cce05 100644 GIT binary patch delta 540 zcmex!m2t{F#tBR6!)+KCinqU#B%IbOsP#*~-N59|%BfMxb~OkS+jX zmL|PCcA$C?o13AGp#ex|x-l?Z3w1id2^0sh*?{T`fOH8ETPXZ32Z@8&%s}x9AUy$y zEgLK9Ygm91APz`k3Xq-w#H;UEU1SD|gV?M<@dZG71rXQlH~zo_6bG?6fZ`i~^bR2Q zIe*&^Cv(1H+z_EnnDx;vhCBQ2ieu&EU_#aQ1tY9!NcdKhWhM4IDth z%^?g7^BtSkf+Rp}E|5V$+Bk)QL0`}%j0-3ZV#@)=BY?C>{^om(lXRG_^G@!PESdaF zPmet~HLp0osCcuC{vk#fXYxZ^7q*P@_{5yz$%6ipB96I9nW=dt3O^3ZZ?cKuj?L#xC7C80xTDLybN~=v*~-N59|%BfMxb~Ikd6Ri zmL|PCcA$C?o13AGAp=MUIx#R@3w1id2^0sh*?{UJfOHHHTPXZ32Z@8&%s}x3AYB2( zmW>tlH7r005C(c=a8ti_AcA5StY!-T|a10CCNJ;}1MQaS)pWC_V#7F92en z^SAv#4g#^+feu;$q;GjKFziX$@`Vj34q|fx)jt8!FM#;$_b5G(`WId{5Dg!Ig0lk{ z80I@Rtp!Pd*jylkfV6Z11B1SxOBfeW9K@CbiaP-5KUtgaF;3E9JTSS@rgZW%Jv|PO z#G;h)#G=&6I<|_NZS)s1^20