#[cfg(feature = "tui")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    use std::thread;
    use std::time::Duration;

    use kcan::protocols::robstride::RobStrideFeedback;
    use kcan::{
        ActuatorConfig, ActuatorFeedback, ActuatorProtocol, ActuatorSnapshot, MotorFeedback,
        MotorModel, RobStrideModel, TuiDashboard,
    };
    use scrin::{Terminal, TerminalOptions};

    let dashboard = TuiDashboard::new(vec![
        ActuatorSnapshot {
            config: ActuatorConfig {
                id: 3,
                label: Some("left-knee".to_owned()),
                protocol: ActuatorProtocol::CubeMars(MotorModel::Ak60_6),
            },
            feedback: Some(ActuatorFeedback::CubeMars(MotorFeedback {
                reported_motor_id: Some(3),
                position_degrees: 12.5,
                speed_erpm: 800,
                current_amps: 1.2,
                temperature_celsius: 34,
                error_code: 0,
            })),
        },
        ActuatorSnapshot {
            config: ActuatorConfig {
                id: 4,
                label: Some("right-knee".to_owned()),
                protocol: ActuatorProtocol::CubeMars(MotorModel::Ak80_6),
            },
            feedback: Some(ActuatorFeedback::CubeMars(MotorFeedback {
                reported_motor_id: Some(4),
                position_degrees: -3.0,
                speed_erpm: -120,
                current_amps: 0.6,
                temperature_celsius: 32,
                error_code: 0,
            })),
        },
        ActuatorSnapshot {
            config: ActuatorConfig {
                id: 5,
                label: Some("left-ankle".to_owned()),
                protocol: ActuatorProtocol::CubeMars(MotorModel::Ak90_9),
            },
            feedback: Some(ActuatorFeedback::CubeMars(MotorFeedback {
                reported_motor_id: Some(5),
                position_degrees: 1.5,
                speed_erpm: 50,
                current_amps: 0.4,
                temperature_celsius: 31,
                error_code: 0,
            })),
        },
        ActuatorSnapshot {
            config: ActuatorConfig {
                id: 6,
                label: Some("right-hip".to_owned()),
                protocol: ActuatorProtocol::RobStride(RobStrideModel::Rs01),
            },
            feedback: Some(ActuatorFeedback::RobStride(RobStrideFeedback {
                position_rad: 0.25,
                velocity_rad_s: 0.1,
                torque_nm: 1.1,
                mode: Some(1),
                error_code: Some(0),
            })),
        },
    ]);

    let mut terminal = Terminal::init_with(TerminalOptions::new())?;
    terminal.draw(|frame| dashboard.render_frame(frame))?;
    thread::sleep(Duration::from_secs(3));
    terminal.restore()?;
    Ok(())
}

#[cfg(not(feature = "tui"))]
fn main() {
    eprintln!("enable the `tui` feature to run this example");
}
