diff --git a/aa_wireless_dongle/package/aawg/src/aawgd.cpp b/aa_wireless_dongle/package/aawg/src/aawgd.cpp index de38b6f..acaca76 100644 --- a/aa_wireless_dongle/package/aawg/src/aawgd.cpp +++ b/aa_wireless_dongle/package/aawg/src/aawgd.cpp @@ -9,22 +9,16 @@ int main(void) { Logger::instance()->info("AA Wireless Dongle\n"); + Logger::instance()->info("Connection Strategy: %d\n", Config::instance()->getConnectionStrategy()); // Global init std::optional ueventThread = UeventMonitor::instance().start(); UsbManager::instance().init(); BluetoothHandler::instance().init(); - ConnectionStrategy connectionStrategy = Config::instance()->getConnectionStrategy(); - if (connectionStrategy == ConnectionStrategy::DONGLE_MODE) { - BluetoothHandler::instance().powerOn(); - } - while (true) { - Logger::instance()->info("Connection Strategy: %d\n", connectionStrategy); - // Per connection setup and processing - if (connectionStrategy == ConnectionStrategy::USB_FIRST) { + if (Config::instance()->getConnectionStrategy() == ConnectionStrategy::USB_FIRST) { Logger::instance()->info("Waiting for the accessory to connect first\n"); UsbManager::instance().enableDefaultAndWaitForAccessory(); } @@ -36,22 +30,14 @@ int main(void) { return 1; } - if (connectionStrategy != ConnectionStrategy::DONGLE_MODE) { - BluetoothHandler::instance().powerOn(); - } - - BluetoothHandler::instance().connectDevice(); + BluetoothHandler::instance().connect(); proxyThread->join(); - + BluetoothHandler::instance().powerOff(); UsbManager::instance().disableGadget(); - if (connectionStrategy != ConnectionStrategy::DONGLE_MODE) { - BluetoothHandler::instance().powerOff(); - - // sleep for a couple of seconds before retrying - sleep(2); - } + // sleep for a couple of seconds before retrying + sleep(2); } ueventThread->join(); diff --git a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp index 218c890..63acd45 100644 --- a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp @@ -172,10 +172,6 @@ void BluetoothHandler::stopAdvertising() { } void BluetoothHandler::connectDevice() { - if (!m_adapter) { - return; - } - DBus::ManagedObjects objects = getBluezObjects(); std::vector device_paths; @@ -240,13 +236,14 @@ void BluetoothHandler::init() { } } -void BluetoothHandler::powerOn() { +void BluetoothHandler::connect() { if (!m_adapter) { return; } setPower(true); setPairable(true); + connectDevice(); } void BluetoothHandler::powerOff() { diff --git a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.h b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.h index 6c49d83..4669319 100644 --- a/aa_wireless_dongle/package/aawg/src/bluetoothHandler.h +++ b/aa_wireless_dongle/package/aawg/src/bluetoothHandler.h @@ -12,8 +12,7 @@ class BluetoothHandler { static BluetoothHandler& instance(); void init(); - void connectDevice(); - void powerOn(); + void connect(); void powerOff(); private: @@ -27,6 +26,7 @@ class BluetoothHandler { void setPower(bool on); void setPairable(bool pairable); void exportProfiles(); + void connectDevice(); void startAdvertising(); void stopAdvertising();