use crate::{bus::Bus, led_state::LedState};
use stm32f0xx_hal::{delay::Delay, prelude::*};

pub struct DisplayController;

impl DisplayController {

    #[cfg(not(debug_assertions))]
    pub fn run_boot_sequence(bus: &mut Bus, delay: &mut Delay) {
        let mut boot_sequence_index = 0;
        while let Some(led_state) = LedState::boot_sequence(boot_sequence_index) {
            for _ in 0..20 {
                for i in 0_u8..6_u8 {
                    let ic_3_value = led_state.ic_3_value(i as _);
                    bus.output(10, 1_u8 << i);
                    bus.output(3, ic_3_value);
                    delay.delay_us(1000u16);
                    bus.output(3, 0xFF);
                    bus.output(11, 4_u8 << i);
                }
            }
            boot_sequence_index += 1;
        }
    }

    pub fn display_led_state(i: u8, bus: &mut Bus, led_state: &LedState, delay: &mut Delay) {
        let ic_3_value = led_state.ic_3_value(i as _);

        bus.output(10, 1_u8 << i);
        bus.output(3, ic_3_value);
        delay.delay_us(20u16);
        bus.output(3, 0xFF);
    }

}