-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update dependencies, improve bluetooth reliability, fix warnings #4
base: main
Are you sure you want to change the base?
Conversation
Thanks! I'll try this out soon to see whether it still works with my printer as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. This mostly still works fine for me, just one weird behaviour situation I need your feedback on!
let write_type = if chunks.len() > 1 { | ||
WriteType::WithoutResponse | ||
} else { | ||
WriteType::WithResponse | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for my device (GB02
), this WriteType does not seem to work. When I execute a flush
operation, which is only one message, thus triggering WithResponse
, I get this error:
Starting scan...
Connected to GB02
Discovering services...
Found 9 characteristics
Scan complete
thread 'main' panicked at C:\Users\micro\Documents\dev\catprint-rs\src\device.rs:100:18:
called `Result::unwrap()` on an `Err` value: Other("Error { code: HRESULT(0x80650003), message: \"Das Attribut kann nicht geschrieben werden.\" }")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
(Sorry for the German Windows error)
If I restore the previous way of always sending WithoutResponse
, it works flawlessly.
Is sending in the WithResponse
mode required for your printer? If yes, please add a flag similar to the supports_compression
flag based on the device name.
println!("Discovering services..."); | ||
peripheral.discover_services().await?; | ||
|
||
let supports_compression = name != "MX10"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let supports_compression = name != "MX10"; | |
let supports_compression = match name { | |
"MX10" => false, | |
_ => true, | |
}; |
While more verbose, I intentionally used a match here to be able to easily add more devices in the future.
} else { | ||
break; | ||
} | ||
let chunks = self.tx_buffer.chunks(20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution! I always forget about the Vec-convenience methods. Just one small suggestion to avoid magic numbers.
let chunks = self.tx_buffer.chunks(20); | |
const MTU_SIZE: usize = 20; | |
let chunks = self.tx_buffer.chunks(MTU_SIZE); |
Hello,
I updated the dependencies for this tool, and while doing so I refactored some parts of the bluetooth code, for my printer (the 8€ aliexpress square X6h-xxxx), it's more reliable this way