Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
e14d9ed75f |
|
|
@ -25,5 +25,3 @@ tarpaulin-report.html
|
||||||
test/
|
test/
|
||||||
.ignore
|
.ignore
|
||||||
*.json
|
*.json
|
||||||
config/
|
|
||||||
vp/
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ enum-map = { version = "2.7.3", features = ["serde"] }
|
||||||
colog = "1.3.0"
|
colog = "1.3.0"
|
||||||
env_logger = "0.11.5"
|
env_logger = "0.11.5"
|
||||||
log = { version = "0.4.22", features = ["serde", "std", "release_max_level_debug", "max_level_debug"] }
|
log = { version = "0.4.22", features = ["serde", "std", "release_max_level_debug", "max_level_debug"] }
|
||||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
|
||||||
mockall = "0.13.1"
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rusty_midicommander"
|
name = "rusty_midicommander"
|
||||||
|
|
|
||||||
20
src/cli.rs
20
src/cli.rs
|
|
@ -48,22 +48,25 @@ pub struct CLIArgs {
|
||||||
/// Create a config file from all the given arguments
|
/// Create a config file from all the given arguments
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub save: Option<String>,
|
pub save: Option<String>,
|
||||||
|
//
|
||||||
/// Connect to a VP
|
// /// Connect to a VP
|
||||||
pub vp: Vec<VPType>,
|
// pub vp: Option<Vec<VPType>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// All arguments for creating a VP configuration
|
/// All arguments for creating a VP configuration
|
||||||
#[derive(Debug, Parser, Serialize, Deserialize)]
|
#[derive(Debug, Parser, Serialize, Deserialize)]
|
||||||
pub struct CreateArgs {
|
pub struct CreateArgs {
|
||||||
/// Create a projector config file of a specific type
|
/// Create a projector config file of a specific type
|
||||||
pub create: VPType,
|
#[command(subcommand)]
|
||||||
|
pub create: Option<VPType>,
|
||||||
/// The name to save it under
|
|
||||||
#[arg(short, long)]
|
|
||||||
pub name: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl From<OsStr> for VPType {
|
||||||
|
// fn from(value: OsStr) -> Self {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/// Get a parsed Args from the Cli, this function will also perform the basic (save/load) and printing needed
|
/// Get a parsed Args from the Cli, this function will also perform the basic (save/load) and printing needed
|
||||||
pub fn get_arguments_from_cli() -> Result<RMCArgs, RustyMidiError> {
|
pub fn get_arguments_from_cli() -> Result<RMCArgs, RustyMidiError> {
|
||||||
log::debug!("Loading CLI arguments");
|
log::debug!("Loading CLI arguments");
|
||||||
|
|
@ -134,7 +137,6 @@ impl RMCArgs {
|
||||||
midi_interface: _,
|
midi_interface: _,
|
||||||
config: _,
|
config: _,
|
||||||
save: Some(save_path),
|
save: Some(save_path),
|
||||||
vp: _,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
} = &self
|
} = &self
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,10 @@
|
||||||
//! Contains all functionnalities the CLI expects
|
//! Contains all functionnalities the CLI expects
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::create_dir,
|
|
||||||
process::exit,
|
process::exit,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use rand::{rngs::SmallRng, Rng, SeedableRng};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{self, CreateArgs},
|
cli::{self, CreateArgs},
|
||||||
midi::{self, cleanup, connect_loop_with_callback, create_output_interface},
|
midi::{self, cleanup, connect_loop_with_callback, create_output_interface},
|
||||||
|
|
@ -19,28 +16,24 @@ use crate::{
|
||||||
|
|
||||||
/// Execute all config creation action
|
/// Execute all config creation action
|
||||||
pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> {
|
pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> {
|
||||||
let mut small_rng = SmallRng::from_entropy();
|
create_args.create.into_iter().for_each(|vp| {
|
||||||
let _ = create_dir("vp");
|
let _ = new_default_projector_of_type(&vp)
|
||||||
let vp = create_args.create;
|
|
||||||
let name = create_args.name.unwrap_or(format!(
|
|
||||||
"vp/{:?}_new_{}.json",
|
|
||||||
vp,
|
|
||||||
small_rng.gen_range(255..2048),
|
|
||||||
));
|
|
||||||
let _ = new_default_projector_of_type(&vp, &name)
|
|
||||||
.inspect_err(|e| println!("Couldn't save the projector {:?} {}", vp, e));
|
.inspect_err(|e| println!("Couldn't save the projector {:?} {}", vp, e));
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Upgrade
|
// TODO: Upgrade
|
||||||
/// Launch the program as a cli
|
/// Launch the program as a cli
|
||||||
pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> {
|
pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> {
|
||||||
|
println!("{:?}", cliargs);
|
||||||
// TODO: Cleanup all the following
|
// TODO: Cleanup all the following
|
||||||
if cliargs.midi_interface.is_none() {
|
if cliargs.midi_interface.is_none() {
|
||||||
midi::print_midi_interfaces();
|
midi::print_midi_interfaces();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{:?}", cliargs);
|
||||||
let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new(
|
let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new(
|
||||||
"127.0.0.1:8080",
|
"127.0.0.1:8080",
|
||||||
"admin1",
|
"admin1",
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,24 @@
|
||||||
pub mod panasonic;
|
pub mod panasonic;
|
||||||
pub mod proj_traits;
|
pub mod proj_traits;
|
||||||
|
|
||||||
use clap::ValueEnum;
|
use clap::Parser;
|
||||||
use panasonic::PanasonicProjector;
|
use panasonic::PanasonicProjector;
|
||||||
pub use proj_traits::{AdvancedCommands, GenericProjector};
|
pub use proj_traits::{AdvancedCommands, GenericProjector};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Enumerate all the VP types
|
/// Enumerate all the VP types
|
||||||
#[derive(ValueEnum, Serialize, Deserialize, Clone, Debug)]
|
#[derive(Parser, Serialize, Deserialize, Clone, Debug)]
|
||||||
pub enum VPType {
|
pub enum VPType {
|
||||||
/// A panasonic VideoProjector
|
|
||||||
Panasonic,
|
Panasonic,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new empty projector of the given type
|
/// Create a new empty projector of the given type
|
||||||
///
|
///
|
||||||
/// While inelegant, this is the most straightforward way of having a generic projector
|
/// While inelegant, this is the most straightforward way of having a generic projector
|
||||||
pub fn new_default_projector_of_type(
|
pub fn new_default_projector_of_type(vptype: &VPType) -> Result<(), crate::RustyMidiError> {
|
||||||
vptype: &VPType,
|
|
||||||
name: &str,
|
|
||||||
) -> Result<(), crate::RustyMidiError> {
|
|
||||||
match vptype {
|
match vptype {
|
||||||
VPType::Panasonic => PanasonicProjector::default().create_default_config_file(name),
|
VPType::Panasonic => {
|
||||||
|
PanasonicProjector::default().create_default_config_file("new_panasonic.json")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue