From 10c1884357b773c9c2907e51ed5ba0471a003aa7 Mon Sep 17 00:00:00 2001 From: Alex Robinson Date: Tue, 2 Mar 2021 15:29:27 -0600 Subject: [PATCH] Properly wait until sync is over before disconnecting from infinitime --- src/bluetooth.py | 23 +++++++++--------- src/hex_time.py | 62 ------------------------------------------------ src/main.py | 1 - src/meson.build | 1 - src/window.py | 7 +++++- 5 files changed, 18 insertions(+), 76 deletions(-) delete mode 100644 src/hex_time.py diff --git a/src/bluetooth.py b/src/bluetooth.py index 76093a1..e35063e 100644 --- a/src/bluetooth.py +++ b/src/bluetooth.py @@ -104,16 +104,17 @@ def disconnect_succeeded(self): super().disconnect_succeeded() print("[%s] Disconnected" % (self.mac_address)) + def characteristic_write_value_succeeded(self, characteristic): + self.disconnect() + def services_resolved(self): super().services_resolved() - - print("[%s] Resolved services" % (self.mac_address)) - for service in self.services: - print("[%s] Service [%s]" % (self.mac_address, service.uuid)) - for characteristic in service.characteristics: - if characteristic.uuid == "00002a2b-0000-1000-8000-00805f9b34fb": - print("Current Time") - value = get_current_time() - characteristic.write_value(value) - print("[%s] Characteristic [%s]" % (self.mac_address, characteristic.uuid)) - + serv = next( + s for s in self.services + if s.uuid == "00001805-0000-1000-8000-00805f9b34fb") + char = next( + c for c in serv.characteristics + if c.uuid == "00002a2b-0000-1000-8000-00805f9b34fb") + + char.write_value(get_current_time()) + diff --git a/src/hex_time.py b/src/hex_time.py deleted file mode 100644 index 0a5a070..0000000 --- a/src/hex_time.py +++ /dev/null @@ -1,62 +0,0 @@ -import datetime - -def get_current_time(): - now = datetime.datetime.now() - year_strip_0x = hex(now.year)[2:] - lsb_raw = year_strip_0x[1:] - if (len(lsb_raw) <= 1): - hex_year_a = "0" + lsb_raw - else: - hex_year_a = lsb_raw - split_by_lsb_raw = year_strip_0x.split(lsb_raw) - msb_raw = split_by_lsb_raw[0] - if (len(msb_raw) <= 1): - hex_year_b = "0" + msb_raw - else: - hex_year_b = msb_raw - - month_strip_0x = hex(now.month)[2:] - if (len(month_strip_0x) <=1 ): - hex_month = "0" + month_strip_0x - else: - hex_month = month_strip_0x - - day_strip_0x = hex(now.day)[2:] - if (len(day_strip_0x) <= 1): - hex_day = "0" + day_strip_0x - else: - hex_day = day_strip_0x - - hour_strip_0x = hex(now.hour)[2:] - if (len(hour_strip_0x) <= 1): - hex_hour = "0" + hour_strip_0x - else: - hex_hour = hour_strip_0x - - minute_strip_0x = hex(now.minute)[2:] - if (len(minute_strip_0x) <= 1): - hex_minute = "0" + minute_strip_0x - else: - hex_minute = minute_strip_0x - - second_strip_0x = hex(now.second)[2:] - if (len(second_strip_0x) <= 1): - hex_second = "0" + second_strip_0x - else: - hex_second = second_strip_0x - - weekday_strip_0x = hex(now.weekday() + 1)[2:] - if (len(weekday_strip_0x) <= 1): - hex_weekday = "0" + weekday_strip_0x - else: - hex_weekday = weekday_strip_0x - - hexasecond = hex(int((now.microsecond * 256) / 1000000)) - hexasecond_strip_0x = hexasecond[2:] - if (len(hexasecond_strip_0x) <= 1): - hex_fractions = "0" + hexasecond_strip_0x - else: - hex_fractions = hexasecond_strip_0x - hex_answer = hex_year_a + " " + hex_year_b + " " + hex_month + " " + hex_day + " " + hex_hour + " " + hex_minute + " " + hex_second + " " + hex_weekday + " " + hex_fractions - print(hex_answer) - return bytearray.fromhex(hex_answer) diff --git a/src/main.py b/src/main.py index 25e70f2..c6c6c1f 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,6 @@ def do_activate(self): win = SigloWindow(application=self) win.present() self.manager.scan_for_infinitime() - win.done_scanning(self.manager) def do_window_removed(self, window): diff --git a/src/meson.build b/src/meson.build index 371e9d2..cf66ef0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -30,7 +30,6 @@ siglo_sources = [ 'main.py', 'window.py', 'bluetooth.py', - 'hex_time.py', ] install_data(siglo_sources, install_dir: moduledir) diff --git a/src/window.py b/src/window.py index 43b0419..3f0c5f3 100644 --- a/src/window.py +++ b/src/window.py @@ -10,6 +10,7 @@ class SigloWindow(Gtk.ApplicationWindow): bbox_scan_fail = Gtk.Template.Child() bbox_scan_pass = Gtk.Template.Child() bt_spinner = Gtk.Template.Child() + sync_time_button = Gtk.Template.Child() def __init__(self, **kwargs): self.manager = None @@ -43,4 +44,8 @@ def sync_time_button_clicked(self, widget): print("Sync Time button clicked...") device = InfiniTimeDevice(manager=self.manager, mac_address=self.manager.get_mac_address()) device.connect() - self.info_scan_pass.set_text("InfiniTime Syncing! You may now close Siglo.") + self.info_scan_pass.set_text("InfiniTime Syncing... Success!") + self.bbox_scan_pass.set_visible(False) + self.sync_time_button.set_visible(False) + +