62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use config::Config;
|
|
use rppal::pwm::Channel;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
#[derive(StructOpt)]
|
|
pub struct Args {
|
|
pub config_file: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum ChannelConfig {
|
|
Pwm0,
|
|
Pwm1,
|
|
}
|
|
|
|
impl From<ChannelConfig> for Channel {
|
|
fn from(value: ChannelConfig) -> Self {
|
|
match value {
|
|
ChannelConfig::Pwm0 => Channel::Pwm0,
|
|
ChannelConfig::Pwm1 => Channel::Pwm1,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PWMStep {
|
|
pub pulse_us: u64,
|
|
pub delay_ms: u64,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PWMConfig {
|
|
pub pwm_channel: ChannelConfig,
|
|
pub period_ms: u64,
|
|
pub pulse_min_us: u64,
|
|
pub pulse_max_us: u64,
|
|
pub steps: Vec<PWMStep>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct RollBotConfig {
|
|
pub server_addr: String,
|
|
|
|
pub pwm_config: PWMConfig,
|
|
}
|
|
|
|
impl RollBotConfig {
|
|
pub fn new(config: PathBuf) -> Self {
|
|
let daemon_config = Config::builder()
|
|
.add_source(config::File::new(
|
|
config.to_str().unwrap(),
|
|
config::FileFormat::Toml,
|
|
))
|
|
.build()
|
|
.unwrap();
|
|
|
|
daemon_config.try_deserialize().unwrap()
|
|
}
|
|
}
|