summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-08-27 21:51:09 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-08-27 21:51:09 +0200
commit70ce1b1638193837ce94a247a57a637b8f0b6d7d (patch)
tree1e3d5fb209f70f9fec3c03426452b41507df2d01
parent5ceff05581964a3ba677a0dfde07e314646bb6bd (diff)
downloadflicbtn-70ce1b1638193837ce94a247a57a637b8f0b6d7d.tar.gz
flicbtn-70ce1b1638193837ce94a247a57a637b8f0b6d7d.tar.xz
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/commands/stream_mapper.rs136
1 files changed, 50 insertions, 86 deletions
diff --git a/src/commands/stream_mapper.rs b/src/commands/stream_mapper.rs
index 4b13bc8..a54fd6a 100644
--- a/src/commands/stream_mapper.rs
+++ b/src/commands/stream_mapper.rs
@@ -22,17 +22,11 @@ impl CommandToByteMapper {
self.write_u8(command.opcode());
match command {
Command::GetInfo => {},
- Command::CreateScanner {
- scan_id,
- } => {
-
- self.write_u32(scan_id);
+ Command::CreateScanner { scan_id, } => {
+ self.write_u32(scan_id);
},
- Command::RemoveScanner {
- scan_id,
- } => {
-
- self.write_u32(scan_id);
+ Command::RemoveScanner { scan_id, } => {
+ self.write_u32(scan_id);
},
Command::CreateConnectionChannel {
conn_id,
@@ -40,81 +34,51 @@ impl CommandToByteMapper {
latency_mode,
auto_disconnect_time,
} => {
-
- self.write_u32(conn_id);
- self.write_bdaddr(&bd_addr[..]);
- if let Ok(latency_mode) = latency_mode.try_into() {
- self.write_u8(latency_mode);
- }
- self.write_i16(auto_disconnect_time);
+ self.write_u32(conn_id);
+ self.write_bdaddr(&bd_addr[..]);
+ if let Ok(latency_mode) = latency_mode.try_into() {
+ self.write_u8(latency_mode);
+ }
+ self.write_i16(auto_disconnect_time);
},
- Command::RemoveConnectionChannel {
- conn_id,
- } => {
-
- self.write_u32(conn_id);
+ Command::RemoveConnectionChannel { conn_id } => {
+ self.write_u32(conn_id);
},
- Command::ForceDisconnect {
- bd_addr,
- } => {
-
- self.write_bdaddr(&bd_addr[..]);
+ Command::ForceDisconnect { bd_addr } => {
+ self.write_bdaddr(&bd_addr[..]);
},
Command::ChangeModeParameters {
conn_id,
latency_mode,
auto_disconnect_time,
} => {
-
- self.write_u32(conn_id);
- if let Ok(latency_mode) = latency_mode.try_into() {
- self.write_u8(latency_mode);
- }
- self.write_i16(auto_disconnect_time);
+ self.write_u32(conn_id);
+ if let Ok(latency_mode) = latency_mode.try_into() {
+ self.write_u8(latency_mode);
+ }
+ self.write_i16(auto_disconnect_time);
},
- Command::Ping {
- ping_id,
- } => {
-
- self.write_u32(ping_id);
+ Command::Ping { ping_id } => {
+ self.write_u32(ping_id);
},
- Command::GetButtonInfo {
- bd_addr,
- } => {
-
- self.write_bdaddr(&bd_addr[..]);
+ Command::GetButtonInfo { bd_addr } => {
+ self.write_bdaddr(&bd_addr[..]);
},
- Command::CreateScanWizard {
- scan_wizard_id,
- } => {
-
- self.write_u32(scan_wizard_id);
+ Command::CreateScanWizard { scan_wizard_id } => {
+ self.write_u32(scan_wizard_id);
},
- Command::CancelScanWizard {
- scan_wizard_id,
- } => {
-
- self.write_u32(scan_wizard_id);
+ Command::CancelScanWizard { scan_wizard_id } => {
+ self.write_u32(scan_wizard_id);
},
- Command::DeleteButton {
- bd_addr,
- } => {
-
- self.write_bdaddr(&bd_addr[..]);
+ Command::DeleteButton { bd_addr } => {
+ self.write_bdaddr(&bd_addr[..]);
},
- Command::CreateBatteryStatusListener {
- listener_id,
- bd_addr,
- } => {
-
- self.write_u32(listener_id);
- self.write_bdaddr(&bd_addr[..]);
+ Command::CreateBatteryStatusListener { listener_id, bd_addr } => {
+ self.write_u32(listener_id);
+ self.write_bdaddr(&bd_addr[..]);
},
- Command::RemoveBatteryStatusListener {
- listener_id,
- } => {
-
- self.write_u32(listener_id);
+ Command::RemoveBatteryStatusListener { listener_id } => {
+ self.write_u32(listener_id);
},
}
@@ -136,16 +100,16 @@ impl CommandToByteMapper {
let mut buf = vec![value].into_iter().collect();
self.buffer.append(&mut buf);
}
-/*
- fn write_bool(&mut self, value: bool) {
- if value {
- self.write_u8(1);
- }
- else {
- self.write_u8(0);
- }
- }
-*/
+ /*
+ fn write_bool(&mut self, value: bool) {
+ if value {
+ self.write_u8(1);
+ }
+ else {
+ self.write_u8(0);
+ }
+ }
+ */
fn write_u16(&mut self, value: u16) {
self.write_u8(value as u8);
self.write_u8((value >> 8) as u8);
@@ -158,12 +122,12 @@ impl CommandToByteMapper {
self.write_u16(value as u16);
self.write_u16((value >> 16) as u16);
}
-/*
- fn write_i32(&mut self, value: i32) {
- self.write_i16(value as i16);
- self.write_i16((value >> 16) as i16);
- }
-*/
+ /*
+ fn write_i32(&mut self, value: i32) {
+ self.write_i16(value as i16);
+ self.write_i16((value >> 16) as i16);
+ }
+ */
fn write_bdaddr(&mut self, str: &str) {
let re = Regex::new(r"([0-9a-z]{2}:){5}[0-9a-z]{2}").unwrap();
if re.is_match(str) {