Skip to content

Commit 72865fa

Browse files
committed
Merge branch 'dongle-mode'
2 parents 5ec0f63 + cc6376e commit 72865fa

File tree

5 files changed

+59
-30
lines changed

5 files changed

+59
-30
lines changed

contrib/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@
4040
# BLE advertising
4141
advertise = false
4242

43+
# Dongle mode
44+
dongle_mode = false
45+
4346
# BLE device name (how your bluetooth device is visible)
4447
# by default it is WirelessAADongle-CPUSERIAL
48+
# for dongle mode you need to set it to: AndroidAuto-xxxxx
4549
btalias = ""
4650

4751
# Auto-connect to phone and initiate connection

src/bluetooth.rs

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub async fn get_cpu_serial_number_suffix() -> Result<String> {
7070

7171
async fn power_up_and_wait_for_connection(
7272
advertise: bool,
73+
dongle_mode: bool,
7374
btalias: Option<String>,
7475
connect: Option<Address>,
7576
keepalive: bool,
@@ -133,36 +134,39 @@ async fn power_up_and_wait_for_connection(
133134
let mut handle_aa = session.register_profile(profile).await?;
134135
info!("{} 📱 AA Wireless Profile: registered", NAME);
135136

136-
// Headset profile
137-
let profile = Profile {
138-
uuid: HSP_HS_UUID,
139-
name: Some("HSP HS".to_string()),
140-
require_authentication: Some(false),
141-
require_authorization: Some(false),
142-
..Default::default()
143-
};
144-
let handle_hsp = match session.register_profile(profile).await {
145-
Ok(handle_hsp) => {
146-
info!("{} 🎧 Headset Profile (HSP): registered", NAME);
147-
Some(handle_hsp)
148-
}
149-
Err(e) => {
150-
warn!(
151-
"{} 🎧 Headset Profile (HSP) registering error: {}, ignoring",
152-
NAME, e
153-
);
154-
None
137+
let mut handle_hsp = None;
138+
if dongle_mode {
139+
// Headset profile
140+
let profile = Profile {
141+
uuid: HSP_HS_UUID,
142+
name: Some("HSP HS".to_string()),
143+
require_authentication: Some(false),
144+
require_authorization: Some(false),
145+
..Default::default()
146+
};
147+
match session.register_profile(profile).await {
148+
Ok(handle) => {
149+
info!("{} 🎧 Headset Profile (HSP): registered", NAME);
150+
handle_hsp = Some(handle);
151+
}
152+
Err(e) => {
153+
warn!(
154+
"{} 🎧 Headset Profile (HSP) registering error: {}, ignoring",
155+
NAME, e
156+
);
157+
}
155158
}
156-
};
159+
}
157160

158161
info!("{} ⏳ Waiting for phone to connect via bluetooth...", NAME);
159162

160163
// try to connect to saved devices or provided one via command line
161-
let connect_task: Option<JoinHandle<Result<()>>> = match connect {
162-
Some(address) => {
164+
let mut connect_task: Option<JoinHandle<Result<()>>> = None;
165+
if dongle_mode {
166+
if let Some(address) = connect {
163167
let adapter_cloned = adapter.clone();
164168

165-
Some(tokio::spawn(async move {
169+
connect_task = Some(tokio::spawn(async move {
166170
let addresses = if address == Address::any() {
167171
info!("{} 🥏 Enumerating known bluetooth devices...", NAME);
168172
adapter_cloned.device_addresses().await?
@@ -196,10 +200,9 @@ async fn power_up_and_wait_for_connection(
196200
}
197201
sleep(Duration::from_secs(1)).await;
198202
}
199-
}))
203+
}));
200204
}
201-
None => None,
202-
};
205+
}
203206

204207
// handling connection to headset profile in own task
205208
let task_hsp = {
@@ -367,6 +370,7 @@ pub async fn bluetooth_stop(state: BluetoothState) -> Result<()> {
367370

368371
pub async fn bluetooth_setup_connection(
369372
advertise: bool,
373+
dongle_mode: bool,
370374
btalias: Option<String>,
371375
connect: Option<Address>,
372376
wifi_config: WifiConfig,
@@ -379,9 +383,15 @@ pub async fn bluetooth_setup_connection(
379383
let mut stage = 1;
380384
let mut started;
381385

382-
let (state, mut stream) =
383-
power_up_and_wait_for_connection(advertise, btalias, connect, keepalive, bt_timeout)
384-
.await?;
386+
let (state, mut stream) = power_up_and_wait_for_connection(
387+
advertise,
388+
dongle_mode,
389+
btalias,
390+
connect,
391+
keepalive,
392+
bt_timeout,
393+
)
394+
.await?;
385395

386396
info!("{} 📲 Sending parameters via bluetooth to phone...", NAME);
387397
let mut start_req = WifiStartRequest::new();

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ fn webserver_default_bind() -> Option<String> {
105105
#[serde(default)]
106106
pub struct AppConfig {
107107
pub advertise: bool,
108+
pub dongle_mode: bool,
108109
pub debug: bool,
109110
pub hexdump_level: HexdumpLevel,
110111
pub disable_console_debug: bool,
@@ -151,6 +152,7 @@ impl Default for AppConfig {
151152
fn default() -> Self {
152153
Self {
153154
advertise: false,
155+
dongle_mode: false,
154156
debug: false,
155157
hexdump_level: HexdumpLevel::Disabled,
156158
disable_console_debug: false,
@@ -233,6 +235,7 @@ impl AppConfig {
233235
});
234236

235237
doc["advertise"] = value(self.advertise);
238+
doc["dongle_mode"] = value(self.dongle_mode);
236239
doc["debug"] = value(self.debug);
237240
doc["hexdump_level"] = value(format!("{:?}", self.hexdump_level));
238241
doc["disable_console_debug"] = value(self.disable_console_debug);

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ async fn tokio_main(
226226
loop {
227227
match bluetooth_setup_connection(
228228
config.read().await.advertise,
229+
config.read().await.dongle_mode,
229230
config.read().await.btalias.clone(),
230231
config.read().await.connect,
231232
wifi_conf.clone(),

static/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,22 @@ <h3>🛸 aa-proxy-rs</h3>
167167
>
168168
</td>
169169
</tr>
170+
<tr>
171+
<td><label for="dongle_mode">dongle_mode</label></td>
172+
<td>
173+
<input type="checkbox" role="switch" id="dongle_mode" /><br /><small
174+
>Dongle mode</small
175+
>
176+
</td>
177+
</tr>
170178
<tr>
171179
<td><label for="btalias">btalias</label></td>
172180
<td>
173181
<input type="text" id="btalias" /><br /><small
174182
>BLE device name (how your bluetooth device is visible)<br />by
175-
default it is <code>WirelessAADongle-CPUSERIAL</code></small
183+
default it is <code>WirelessAADongle-CPUSERIAL</code><br />
184+
for dongle mode you need to set it to:
185+
<code>AndroidAuto-xxxxx</code></small
176186
>
177187
</td>
178188
</tr>
@@ -364,6 +374,7 @@ <h3>🛸 aa-proxy-rs</h3>
364374
const config = {};
365375
const ids = [
366376
"advertise",
377+
"dongle_mode",
367378
"debug",
368379
"hexdump_level",
369380
"disable_console_debug",

0 commit comments

Comments
 (0)