Merge branch feat/tally into main

This commit is contained in:
2025-06-10 12:01:20 +01:00
parent f0ee6a0444
commit 65ffc9e809
47 changed files with 2309 additions and 1360 deletions
+3
View File
@@ -7,6 +7,9 @@ edition = "2021"
[dependencies]
atem-connection-rs = { path = "../atem-connection-rs" }
clap = { version = "4.4.18", features = ["derive"] }
color-eyre = "0.5.11"
env_logger = "0.9.0"
log = "0.4.14"
tokio = "1.14.0"
tokio-util = "0.7.10"
+56 -31
View File
@@ -1,44 +1,69 @@
use std::time::Duration;
use atem_connection_rs::{
atem_lib::atem_socket::AtemSocket,
commands::{
command_base::{BasicWritableCommand, SerializableCommand},
mix_effects::ProgramInput,
},
use std::{
net::{Ipv4Addr, SocketAddrV4},
str::FromStr,
sync::Arc,
time::Duration,
};
use atem_connection_rs::{
atem::Atem,
atem_lib::atem_socket::{AtemSocket, AtemSocketMessage},
commands::mix_effects::program_input::ProgramInput,
};
use clap::Parser;
use color_eyre::Report;
use tokio::time::sleep;
use tokio::{select, time::sleep};
use tokio_util::sync::CancellationToken;
/// ATEM Rust Library Test App
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// IP of the ATEM to connect to
#[arg(short, long)]
ip: String,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
setup_logging().unwrap();
let switch_to_source_1 = ProgramInput::new(0, 1);
let switch_to_source_2 = ProgramInput::new(0, 2);
let (socket_message_tx, socket_message_rx) =
tokio::sync::mpsc::channel::<AtemSocketMessage>(10);
let (atem_event_tx, atem_event_rx) = tokio::sync::mpsc::unbounded_channel();
let cancel = CancellationToken::new();
let mut atem = AtemSocket::new();
atem.connect("127.0.0.1".to_string(), 9910).await.ok();
let mut atem_socket = AtemSocket::new(socket_message_rx, atem_event_tx);
let mut tracking_id = 0;
loop {
sleep(Duration::from_millis(5000)).await;
atem.send_command(
&switch_to_source_1.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
switch_to_source_1.get_raw_name(),
tracking_id,
)
.await;
tracking_id += 1;
sleep(Duration::from_millis(5000)).await;
atem.send_command(
&switch_to_source_2.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
switch_to_source_2.get_raw_name(),
tracking_id,
)
.await;
tracking_id += 1;
let atem = Arc::new(Atem::new(atem_socket, socket_message_tx));
let atem_thread = atem.clone();
let atem_run = atem_thread.run(atem_event_rx, cancel);
let switch_loop = tokio::spawn(async move {
let address = Ipv4Addr::from_str(&args.ip).unwrap();
let socket = SocketAddrV4::new(address, 9910);
atem.connect(socket.into()).await;
loop {
sleep(Duration::from_millis(5000)).await;
log::info!("Switch to source 1");
atem.send_commands(vec![Box::new(ProgramInput::new(0, 1))])
.await;
log::info!("Switched to source 1");
sleep(Duration::from_millis(5000)).await;
log::info!("Switch to source 2");
atem.send_commands(vec![Box::new(ProgramInput::new(0, 2))])
.await;
log::info!("Switched to source 2");
}
});
select! {
_ = atem_run => {},
_ = switch_loop => {}
}
}