refactor: make examples into proper Cargo examples

This commit is contained in:
nekename committed 2025-05-28 14:24:24 +01:00
1 parent 03cd301ab9
commit 6fcef74f02
7 files changed
+14 -29

No files matched your search

+3
View File
@@ -25,6 +25,9 @@ async = [
"tokio/time"
]
[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
@@ -1,3 +1,6 @@
#[cfg(not(feature = "async"))]
compile_error!("The `async` feature must be enabled to compile this example.");
use std::time::Duration;
use image::open;
@@ -23,17 +26,17 @@ async fn main() {
device.clear_all_button_images().await.unwrap();
// Use image-rs to load an image
let image = open("no-place-like-localhost.jpg").unwrap();
let image = open("examples/no-place-like-localhost.jpg").unwrap();
let alternative = image.grayscale().brighten(-50);
println!("Key count: {}", kind.key_count());
// Write it to the device
for i in 0..kind.key_count() as u8 {
for i in 0..kind.key_count() {
device.set_button_image(i, image.clone()).await.unwrap();
}
println!("Touch point count: {}", kind.touchpoint_count());
for i in 0..kind.touchpoint_count() as u8 {
for i in 0..kind.touchpoint_count() {
device.set_touchpoint_color(i, 255, 255, 255).await.unwrap();
}
@@ -72,7 +75,7 @@ async fn main() {
previous = index;
index += 1;
if index >= kind.key_count() as u8 {
if index >= kind.key_count() {
index = 0;
}
}
-12
View File
@@ -1,12 +0,0 @@
[package]
name = "async"
edition = "2021"
[dependencies]
image = { version = "0.25.1", default-features = false, features = [
"bmp",
"jpeg",
] }
tokio = { version = "1", optional = false, features = ["full"] }
async-recursion = { version = "1.0.2", optional = false }
elgato-streamdeck = { path = "../../", features = ["async"] }
@@ -22,16 +22,16 @@ fn main() {
device.set_brightness(50).unwrap();
device.clear_all_button_images().unwrap();
// Use image-rs to load an image
let image = open("no-place-like-localhost.jpg").unwrap();
let image = open("examples/no-place-like-localhost.jpg").unwrap();
println!("Key count: {}", kind.key_count());
// Write it to the device
for i in 0..kind.key_count() as u8 {
for i in 0..kind.key_count() {
device.set_button_image(i, image.clone()).unwrap();
}
println!("Touch point count: {}", kind.touchpoint_count());
for i in 0..kind.touchpoint_count() as u8 {
for i in 0..kind.touchpoint_count() {
device.set_touchpoint_color(i, 255, 255, 255).unwrap();
}
@@ -53,6 +53,7 @@ fn main() {
// Flush
device.flush().unwrap();
#[allow(clippy::arc_with_non_send_sync)]
let device = Arc::new(device);
{
let reader = device.get_reader();
-10
View File
@@ -1,10 +0,0 @@
[package]
name = "simple"
edition = "2021"
[dependencies]
image = { version = "0.25.1", default-features = false, features = [
"bmp",
"jpeg",
] }
elgato-streamdeck = { path = "../../" }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB