Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kezii
Copy link
Contributor

@Kezii Kezii commented Aug 20, 2024

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

@jhbruhn
Copy link
Owner

jhbruhn commented Aug 21, 2024

Thanks! I'll try this out soon to see whether it still works with my printer as well.

Copy link
Owner

@jhbruhn jhbruhn left a 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!

Comment on lines +90 to +94
let write_type = if chunks.len() > 1 {
WriteType::WithoutResponse
} else {
WriteType::WithResponse
};
Copy link
Owner

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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Owner

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.

Suggested change
let chunks = self.tx_buffer.chunks(20);
const MTU_SIZE: usize = 20;
let chunks = self.tx_buffer.chunks(MTU_SIZE);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants