Partial polling implementation
This commit is contained in:
parent
b71c74e7f1
commit
30ab14f278
@ -5,11 +5,11 @@
|
|||||||
"sdk" : "org.gnome.Sdk",
|
"sdk" : "org.gnome.Sdk",
|
||||||
"command" : "lumos",
|
"command" : "lumos",
|
||||||
"finish-args" : [
|
"finish-args" : [
|
||||||
"--share=network",
|
|
||||||
"--share=ipc",
|
"--share=ipc",
|
||||||
"--socket=fallback-x11",
|
"--socket=fallback-x11",
|
||||||
"--device=dri",
|
"--device=dri",
|
||||||
"--socket=wayland"
|
"--socket=wayland",
|
||||||
|
"--system-talk-name=net.hadess.SensorProxy"
|
||||||
],
|
],
|
||||||
"cleanup" : [
|
"cleanup" : [
|
||||||
"/include",
|
"/include",
|
||||||
|
@ -30,6 +30,7 @@ lumos_sources = [
|
|||||||
'__init__.py',
|
'__init__.py',
|
||||||
'main.py',
|
'main.py',
|
||||||
'window.py',
|
'window.py',
|
||||||
|
'sensors_polling_timer.py',
|
||||||
'widgets/widgets_loader.py',
|
'widgets/widgets_loader.py',
|
||||||
'widgets/time_priority_page.py',
|
'widgets/time_priority_page.py',
|
||||||
'widgets/aperture_priority_page.py',
|
'widgets/aperture_priority_page.py',
|
||||||
|
43
src/sensors_polling_timer.py
Normal file
43
src/sensors_polling_timer.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from gi.repository import Gio, GLib
|
||||||
|
from threading import Timer
|
||||||
|
|
||||||
|
# window.py
|
||||||
|
#
|
||||||
|
# Copyright 2024 Daniele Verducci
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
|
# A timer for polling the light sensor via DBus.
|
||||||
|
# Checks the sensor at a specific interval and runs a callback only when an update is detected.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# Instantiate it, then call run(interval_in_seconds, callback_function)
|
||||||
|
# To stop it, call cancel()
|
||||||
|
class SensorsPollingTimer(Timer):
|
||||||
|
def run(self):
|
||||||
|
# Setup
|
||||||
|
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||||
|
self.proxy = Gio.DBusProxy.new_sync(bus,Gio.DBusProxyFlags.NONE,None,'net.hadess.SensorProxy','/net/hadess/SensorProxy','org.freedesktop.DBus.Properties', None)
|
||||||
|
self.oldValue = None
|
||||||
|
|
||||||
|
# Loop
|
||||||
|
while not self.finished.wait(self.interval):
|
||||||
|
value = self.proxy.Get('(ss)', 'net.hadess.SensorProxy', 'LightLevel')
|
||||||
|
if (self.oldValue != value):
|
||||||
|
self.oldValue = value
|
||||||
|
self.function(value) # Invoke callback
|
||||||
|
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
from gi.repository import Adw
|
from gi.repository import Adw
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
from .sensors_polling_timer import SensorsPollingTimer
|
||||||
|
|
||||||
@Gtk.Template(resource_path='/eu/ichibi/Lumos/window.ui')
|
@Gtk.Template(resource_path='/eu/ichibi/Lumos/window.ui')
|
||||||
class LumosWindow(Adw.ApplicationWindow):
|
class LumosWindow(Adw.ApplicationWindow):
|
||||||
@ -28,3 +29,11 @@ class LumosWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
# Start polling sensors
|
||||||
|
self.sensorsPollingTimer = SensorsPollingTimer(1, self.onSensorRead)
|
||||||
|
self.sensorsPollingTimer.run()
|
||||||
|
|
||||||
|
def onSensorRead(self, value):
|
||||||
|
# Called when the light value changed
|
||||||
|
print("Read {} lux".format(value))
|
||||||
|
Loading…
Reference in New Issue
Block a user