wacom: disconnect when we have finished retrieving the data
There is no point keeping the connection alive just to drain the battery.
This commit is contained in:
parent
dde2ad4b46
commit
f88a5b2222
|
@ -77,10 +77,11 @@ org.freedesktop.tuhi1.Device
|
|||
interactivity (e.g. the user may need to press the sync button).
|
||||
|
||||
When the device connects, the daemon downloads all drawings from the
|
||||
device. If successfull, the drawings are deleted from the device. The
|
||||
data is held by the daemon in non-persistent storage until the daemon
|
||||
is stopped or we run out of memory, whichever happens earlier. Use
|
||||
GetJSONData() to retrieve the data from the daemon.
|
||||
device and disconnects from the device. If successfull, the drawings
|
||||
are deleted from the device. The data is held by the daemon in
|
||||
non-persistent storage until the daemon is stopped or we run out of
|
||||
memory, whichever happens earlier. Use GetJSONData() to retrieve the
|
||||
data from the daemon.
|
||||
|
||||
When drawings become available from the device, the DrawingsAvailable
|
||||
property updates to the number of available drawings.
|
||||
|
|
4
tuhi.py
4
tuhi.py
|
@ -78,6 +78,7 @@ class TuhiDevice(GObject.Object):
|
|||
self._tuhi_dbus_device = tuhi_dbus_device
|
||||
self._wacom_device = WacomDevice(bluez_device)
|
||||
self._wacom_device.connect('drawing', self._on_drawing_received)
|
||||
self._wacom_device.connect('done', self._on_fetching_finished, bluez_device)
|
||||
self.drawings = []
|
||||
|
||||
bluez_device.connect('connected', self._on_bluez_device_connected)
|
||||
|
@ -123,6 +124,9 @@ class TuhiDevice(GObject.Object):
|
|||
|
||||
self._tuhi_dbus_device.add_drawing(d)
|
||||
|
||||
def _on_fetching_finished(self, device, bluez_device):
|
||||
bluez_device.disconnect_device()
|
||||
|
||||
|
||||
class Tuhi(GObject.Object):
|
||||
__gsignals__ = {
|
||||
|
|
18
tuhi/ble.py
18
tuhi/ble.py
|
@ -202,6 +202,24 @@ class BlueZDevice(GObject.Object):
|
|||
if isinstance(result, Exception):
|
||||
logger.error('Connection failed: {}'.format(result))
|
||||
|
||||
def disconnect_device(self):
|
||||
"""
|
||||
Disconnect the bluetooth device via bluez. This function is
|
||||
asynchronous and returns immediately.
|
||||
"""
|
||||
i = self.obj.get_interface(ORG_BLUEZ_DEVICE1)
|
||||
if not i.get_cached_property('Connected').get_boolean():
|
||||
logger.info('{}: Device is already disconnected'.format(self.address))
|
||||
self.emit('disconnected')
|
||||
return
|
||||
|
||||
logger.info('{}: Disconnecting'.format(self.address))
|
||||
i.Disconnect(result_handler=self._on_disconnect_result)
|
||||
|
||||
def _on_disconnect_result(self, obj, result, user_data):
|
||||
if isinstance(result, Exception):
|
||||
logger.error('Disconnection failed: {}'.format(result))
|
||||
|
||||
def _on_properties_changed(self, obj, properties, invalidated_properties):
|
||||
properties = properties.unpack()
|
||||
|
||||
|
|
|
@ -121,6 +121,8 @@ class WacomDevice(GObject.Object):
|
|||
__gsignals__ = {
|
||||
"drawing":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
|
||||
"done":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
}
|
||||
|
||||
def __init__(self, device):
|
||||
|
@ -570,7 +572,10 @@ class WacomDevice(GObject.Object):
|
|||
|
||||
def run(self):
|
||||
logger.debug('{}: starting'.format(self.device.address))
|
||||
try:
|
||||
self.retrieve_data()
|
||||
finally:
|
||||
self.emit("done")
|
||||
|
||||
def start(self):
|
||||
self.thread = threading.Thread(target=self.run)
|
||||
|
|
Loading…
Reference in New Issue