diff --git a/src/agent_gsm.py b/src/agent_gsm.py index 46ad42a..be6f01a 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -472,6 +472,12 @@ if __name__ == '__main__': bt_ctl = Bluetoothctl() bt_ctl.connect(CONFIG.BT_MAC) utils.log(f' Done.') + else: + utils.log_error(f'No BT MAC specified, cannot connect. Exiting.') + raise SystemExit(EXIT_ERROR) + + # Init BT modem + bt_call_controller.init() # Logging settings utils.verbose_logging = CONFIG.Verbose diff --git a/src/bt_call_controller.py b/src/bt_call_controller.py index 3b5cddb..7ac22b4 100644 --- a/src/bt_call_controller.py +++ b/src/bt_call_controller.py @@ -42,13 +42,18 @@ class CallState(bt_phone.Observer): # Listen to call changes -CALL_STATE_EVENT = CallState() -PHONE = bt_phone.Phone() -PHONE.addObserver(CALL_STATE_EVENT) +CALL_STATE_EVENT = None +PHONE = None # virtualmic module PA_MODULE_IDX = -1 +def init(): + global CALL_STATE_EVENT, PHONE + CALL_STATE_EVENT = CallState() + PHONE = bt_phone.Phone() + PHONE.addObserver(CALL_STATE_EVENT) + # Set volume 0..100% def set_headset_spk_volume(vol: float): diff --git a/src/bt_phone.py b/src/bt_phone.py index aae3260..706b611 100644 --- a/src/bt_phone.py +++ b/src/bt_phone.py @@ -59,7 +59,7 @@ class Phone(Observable): model_serial = properties['Serial'] modem_online = properties['Online'] - utils.log(f'Found modem: {path} name: {modem_name} serial: {model_serial} online: {modem_online}') + # utils.log(f'Found modem: {path} name: {modem_name} serial: {model_serial} online: {modem_online}') if modem_online == 1: return path @@ -114,11 +114,11 @@ class Phone(Observable): self.modem = self.wait_for_online_modem(timeout_seconds=10) # 10 seconds timeout if self.modem is None: - utils.log_error(f'No BT modem found. Please reconnect the phone.') + utils.log_error(f' No BT modem found. Please reconnect the phone.') raise RuntimeError('No BT modem found.') # Log about found modem - utils.log(f'BT modem found. Modem: {self.modem}') + utils.log(f' BT modem found. Modem: {self.modem}') # Get access to ofono API self.org_ofono_obj = self.bus.get_object('org.ofono', self.modem)