diff --git a/README.md b/README.md index 948b186..8cde7cf 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ Control messages: - `/control/reboot` Reboot the camera - `/control/ptz [up|down|left|right|in|out]` (amount) Control the PTZ movements, amount defaults to 32.0 +- `/control/preset [id]` Move to PTZ preset `id` - `/control/pir [on|off]` Status Messages: diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 91fde9f..98da733 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -30,6 +30,7 @@ pub(crate) enum Messages { PIROff, PIRQuery, Ptz(Direction), + Preset(i8), } #[derive(Debug, Copy, Clone)] @@ -449,6 +450,14 @@ impl<'a> MessageHandler<'a> { } } } + Messages::Preset(id) => { + if let Err(e) = self.camera.set_ptz_preset(id, None).await { + error = Some(format!("Failed to send PTZ preset: {:?}", e)); + "FAIL".to_string() + } else { + "OK".to_string() + } + } _ => "UNKNOWN COMMAND".to_string(), }; if let Some(replier) = replier { diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 15e4ab0..4216674 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -14,6 +14,7 @@ /// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection /// - `/control/reboot` Reboot the camera /// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0 +/// - `/control/preset` [id] Move the camera to a known preset /// /// Status Messages: /// @@ -325,6 +326,21 @@ async fn handle_mqtt_message( error!("No PTZ Direction given. Please add up/down/left/right/in/out"); } } + MqttReplyRef { + topic: "control/preset", + message, + } => { + if let Ok(id) = message.parse::() { + reply = Some( + event_cam_sender + .send_message_with_reply(Messages::Preset(id)) + .await + .with_context(|| "Failed to send PTZ preset")?, + ); + } else { + error!("PTZ preset was not a valid number"); + } + } MqttReplyRef { topic: "control/pir", message: "on",