Skip to content

Commit

Permalink
make ble manager use config class
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robinson committed Apr 19, 2021
1 parent 720cb1f commit 5ebf19c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/bluetooth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import gatt
import datetime
import struct
from gi.repository import GObject, Gio, GLib
from gi.repository import GObject, Gio
from .config import config


def get_current_time():
Expand All @@ -25,14 +26,14 @@ def get_current_time():


class InfiniTimeManager(gatt.DeviceManager):
def __init__(self, mode):
def __init__(self):
cmd = "btmgmt info"
btmgmt_proc = Gio.Subprocess.new(
cmd.split(),
Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE,
)
_, stdout, stderr = btmgmt_proc.communicate_utf8()
self.mode = mode
self.conf = config()
self.device_set = set()
self.adapter_name = stdout.splitlines()[1].split(":")[0]
self.alias = None
Expand All @@ -56,11 +57,10 @@ def device_discovered(self, device):
if device.alias() in ("InfiniTime", "Pinetime-JF", "PineTime"):
self.scan_result = True
self.alias = device.alias()
if self.mode == "singleton":
if self.conf.get_property("mode") == "singleton":
self.mac_address = device.mac_address
self.stop()

if self.mode == "multi":
if self.conf.get_property("mode") == "multi":
self.device_set.add(device.mac_address)

def scan_for_infinitime(self):
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class config:
config_dir = home_dir + "/.config/siglo"
config_file = config_dir + "/siglo.ini"

def __init__(self):
def load_defaults(self):
if not Path(self.config_dir).is_dir():
Path.mkdir(Path(self.config_dir))
# if config file is not valid, load defaults
Expand Down
3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Application(Gtk.Application):
def __init__(self):
self.manager = None
self.conf = config()
self.conf.load_defaults()
super().__init__(
application_id="org.gnome.siglo", flags=Gio.ApplicationFlags.FLAGS_NONE
)
Expand All @@ -27,7 +28,7 @@ def do_activate(self):
deploy_type=self.conf.get_property("deploy_type"),
)
win.present()
self.manager = InfiniTimeManager(self.conf.get_property("mode"))
self.manager = InfiniTimeManager()
info_prefix = "[INFO ] Done Scanning"
try:
self.manager.scan_for_infinitime()
Expand Down
5 changes: 2 additions & 3 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def multi_listbox_row_selected(self, list_box, row):
+ "\nMac Address: "
+ self.manager.get_mac_address()
)
print("deploy type!", self.deploy_type)
self.scan_pass_box.set_visible(True)
self.ota_picked_box.set_visible(True)
if self.deploy_type == "manual":
Expand Down Expand Up @@ -180,9 +179,9 @@ def rescan_button_clicked(self, widget):
self.manager.scan_for_infinitime()
except gatt.errors.NotReady:
info_prefix = "[WARN ] Bluetooth is disabled"
if self.manager.mode == "singleton":
if self.mode == "singleton":
self.done_scanning_singleton(self.manager, info_prefix)
if self.manager.mode == "multi":
if self.mode == "multi":
self.done_scanning_multi(self.manager, info_prefix)

@Gtk.Template.Callback()
Expand Down

0 comments on commit 5ebf19c

Please sign in to comment.