use crate::{Transmission, ProtocolProperties};
#[derive(Default)]
pub struct TransmissionBuilder {
sequence: String,
pulse_length: u16,
repeats: u8,
protocol: ProtocolProperties,
}
impl TransmissionBuilder {
pub fn new() -> TransmissionBuilder {
TransmissionBuilder {
sequence: String::from(""),
pulse_length: 0,
repeats: 0,
protocol: ProtocolProperties::default()
}
}
pub fn sequence(mut self, seq: &str) -> TransmissionBuilder {
self.sequence = String::from(seq);
self
}
pub fn pulse_length(mut self, pl: u16) -> TransmissionBuilder {
self.pulse_length = pl;
self
}
pub fn repeats(mut self, rep: u8) -> TransmissionBuilder {
self.repeats = rep;
self
}
pub fn protocol(mut self, pr: ProtocolProperties) -> TransmissionBuilder {
self.protocol = pr;
self
}
pub fn build(&self) -> Transmission {
Transmission {
sequence: self.sequence.clone(),
pulse_length: self.pulse_length,
repeats: self.repeats,
protocol: self.protocol
}
}
}
#[derive(Default)]
pub struct ProtocolBuilder {
short: u8,
long: u8,
sync_bit: u8,
sync_gap: u8,
}
impl ProtocolBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn short(mut self, short: u8) -> Self {
self.short = short;
self
}
pub fn long(mut self, long: u8) -> Self {
self.long = long;
self
}
pub fn sync_bit(mut self, sync_bit: u8) -> Self {
self.sync_bit = sync_bit;
self
}
pub fn sync_gap(mut self, sync_gap: u8) -> Self {
self.sync_gap = sync_gap;
self
}
pub fn build(&self) -> ProtocolProperties {
ProtocolProperties {
short: self.short,
long: self.long,
sync_bit: self.sync_bit,
sync_gap: self.sync_gap
}
}
}