source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
[[package]]
name = "bit_field"
version = "0.10.2"
name = "mqttdeck"
version = "0.1.0"
dependencies = [
+ "base64",
"clap",
"elgato-streamdeck",
"hidapi",
edition = "2021"
[dependencies]
+base64 = "0.22.1"
clap = { version = "4.0.32", features = ["derive"] }
elgato-streamdeck = { version = "0.5.0", features = ["async"] }
hidapi = { version = "2.6.3", default-features = false, features = ["linux-static-hidraw"] }
//
// Copyright 2023 Jonathan McDowell <noodles@earth.li>
+use base64::prelude::*;
use clap::Parser;
use elgato_streamdeck::{list_devices, new_hidapi, AsyncStreamDeck, StreamDeckInput};
use image::{DynamicImage, ImageBuffer, RgbImage};
.unwrap();
send_command_response(&cli, &resp_topic, "OK").await;
}
+ Some("set-image") => {
+ if command["button"].is_null() {
+ send_command_response(&cli, &resp_topic, "no button supplied").await;
+ continue;
+ }
+ if command["image"].is_null() {
+ send_command_response(&cli, &resp_topic, "no image supplied").await;
+ continue;
+ }
+
+ let image = match BASE64_STANDARD.decode(command["image"].as_str().unwrap()) {
+ Ok(image) => image,
+ Err(e) => {
+ send_command_response(&cli, &resp_topic, e.to_string().as_str()).await;
+ continue;
+ }
+ };
+
+ let img = match image::load_from_memory(&image) {
+ Ok(img) => img.rotate180(),
+ Err(e) => {
+ send_command_response(&cli, &resp_topic, e.to_string().as_str()).await;
+ continue;
+ }
+ };
+
+ match deck.set_button_image(
+ command["button"].as_u8().unwrap(),
+ img,
+ )
+ .await {
+ Ok(_) => send_command_response(&cli, &resp_topic, "OK").await,
+ Err(e) => send_command_response(&cli, &resp_topic, e.to_string().as_str()).await,
+ }
+
+
+ },
_ => send_command_response(&cli, &resp_topic, "Unknown action").await,
}
} else {