83 lines
2.6 KiB
Rust
83 lines
2.6 KiB
Rust
//! All functions executed directly from main
|
|
//!
|
|
//! Contains all functionnalities the CLI expects
|
|
|
|
use std::{
|
|
process::exit,
|
|
sync::{Arc, Mutex},
|
|
};
|
|
|
|
use crate::{
|
|
cli::{self, CreateArgs},
|
|
midi::{self, cleanup, connect_loop_with_callback, create_output_interface},
|
|
projector::{self, new_default_projector_of_type, GenericProjector},
|
|
RustyMidiError,
|
|
};
|
|
|
|
/// Execute all config creation action
|
|
pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> {
|
|
create_args.create.into_iter().for_each(|vp| {
|
|
let _ = new_default_projector_of_type(&vp)
|
|
.inspect_err(|e| println!("Couldn't save the projector {:?} {}", vp, e));
|
|
});
|
|
Ok(())
|
|
}
|
|
|
|
// TODO: Upgrade
|
|
/// Launch the program as a cli
|
|
pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> {
|
|
println!("{:?}", cliargs);
|
|
// TODO: Cleanup all the following
|
|
if cliargs.midi_interface.is_none() {
|
|
midi::print_midi_interfaces();
|
|
exit(1);
|
|
}
|
|
|
|
println!("{:?}", cliargs);
|
|
let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new(
|
|
"127.0.0.1:8080",
|
|
"admin1",
|
|
"panasonic",
|
|
)));
|
|
let proj1 = Arc::clone(&proj);
|
|
let proj2 = Arc::clone(&proj);
|
|
|
|
// proj.lock().unwrap().shutter_on().unwrap();
|
|
// proj.lock().unwrap().shutter_off().unwrap();
|
|
// proj.lock().unwrap().get_osd().unwrap();
|
|
|
|
let mut output_interface = create_output_interface(
|
|
cliargs.midi_interface.unwrap(),
|
|
"Rusty MIDI Commander Output",
|
|
);
|
|
cleanup(&mut output_interface.lock().unwrap());
|
|
connect_loop_with_callback(
|
|
cliargs.midi_interface.unwrap(),
|
|
"Rusty MIDI Commander Input",
|
|
&mut output_interface,
|
|
vec![
|
|
(
|
|
3,
|
|
Box::new(move || match proj1.lock().unwrap().shutter_off() {
|
|
Ok(_) => println!("Receiving SHUTTER OFF message"),
|
|
Err(_e) => {
|
|
println!("Error receiving SHUTTER OFF message");
|
|
"Error".to_string();
|
|
}
|
|
}),
|
|
),
|
|
(
|
|
4,
|
|
Box::new(move || match proj2.lock().unwrap().shutter_on() {
|
|
Ok(_) => println!("Receiving SHUTTER ON message"),
|
|
Err(_e) => {
|
|
println!("Error receiving SHUTTER ON message");
|
|
"Error".to_string();
|
|
} // proj2.lock().unwrap().unwrap_or((|| {})());
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
Ok(())
|
|
}
|