#[derive(Default, Clone)]
pub struct LedState {
    pub switch_1: bool,
    pub switch_2: bool,
    pub switches: bool,
    pub select: bool,
    pub number: bool,
    pub value_1: bool,
    pub value_2: bool,
    pub direct_select: bool,
    pub midi_function: bool,
    pub midi_chan: bool,
    pub config: bool,
    pub expression_1: bool,
    pub expression_2: bool,
    pub buttons: [bool; 10],
    pub digit_0: SevenSegmentDisplay,
    pub digit_1: SevenSegmentDisplay,
    pub digit_2: SevenSegmentDisplay,
}

#[derive(Default, Clone)]
pub struct SevenSegmentDisplay {
    pub a: bool,
    pub b: bool,
    pub c: bool,
    pub d: bool,
    pub e: bool,
    pub f: bool,
    pub g: bool,
    pub dp: bool,
}

impl LedState {

    #[cfg(not(debug_assertions))]
    pub fn boot_sequence(i: usize) -> Option<LedState> {
        let mut led_state = LedState::default();
        match i {
            0 => led_state.switch_1 = true,
            1 => led_state.switch_2 = true,
            2 => led_state.switches = true,
            3 => led_state.select = true,
            4 => led_state.number = true,
            5 => led_state.value_1 = true,
            6 => led_state.value_2 = true,
            7 => led_state.direct_select = true,
            8 => led_state.midi_function = true,
            9 => led_state.midi_chan = true,
            10 => led_state.config = true,
            11 => led_state.digit_0.a = true,
            12 => led_state.digit_0.b = true,
            13 => led_state.digit_0.c = true,
            14 => led_state.digit_0.g = true,
            15 => led_state.digit_0.dp = true,
            16 => led_state.digit_1.a = true,
            17 => led_state.digit_1.b = true,
            18 => led_state.digit_1.c = true,
            19 => led_state.digit_1.d = true,
            20 => led_state.digit_1.e = true,
            21 => led_state.digit_1.f = true,
            22 => led_state.digit_1.g = true,
            23 => led_state.digit_1.dp = true,
            24 => led_state.digit_2.a = true,
            25 => led_state.digit_2.b = true,
            26 => led_state.digit_2.c = true,
            27 => led_state.digit_2.d = true,
            28 => led_state.digit_2.e = true,
            29 => led_state.digit_2.f = true,
            30 => led_state.digit_2.g = true,
            31 => led_state.digit_2.dp = true,
            32 => led_state.expression_1 = true,
            33 => led_state.expression_2 = true,
            34 => led_state.buttons[0] = true,
            35 => led_state.buttons[1] = true,
            36 => led_state.buttons[2] = true,
            37 => led_state.buttons[3] = true,
            38 => led_state.buttons[4] = true,
            39 => led_state.buttons[5] = true,
            40 => led_state.buttons[6] = true,
            41 => led_state.buttons[7] = true,
            42 => led_state.buttons[8] = true,
            43 => led_state.buttons[9] = true,
            _ => return None,
        }
        Some(led_state)
    }

    pub fn ic_3_value(&self, index: usize) -> u8 {
        let bits = match index {
            0 => {
                [
                    self.digit_2.dp,
                    self.digit_2.g,
                    self.digit_2.f,
                    self.digit_2.e,
                    self.digit_2.d,
                    self.digit_2.c,
                    self.digit_2.b,
                    self.digit_2.a,
                ]
            }
            1 => {
                [
                    self.digit_1.dp,
                    self.digit_1.g,
                    self.digit_1.f,
                    self.digit_1.e,
                    self.digit_1.d,
                    self.digit_1.c,
                    self.digit_1.b,
                    self.digit_1.a,
                ]
            }
            2 => {
                [
                    self.digit_0.dp,
                    self.digit_0.g,
                    self.digit_0.f,
                    self.digit_0.e,
                    self.digit_0.d,
                    self.digit_0.c,
                    self.digit_0.b,
                    self.digit_0.a,
                ]
            }
            3 => {
                [
                    self.midi_function,
                    self.midi_chan,
                    self.expression_2,
                    self.expression_1,
                    self.switch_1,
                    self.switch_2,
                    self.buttons[4],
                    self.buttons[3],
                ]
            }
            4 => {
                [
                    self.buttons[2],
                    self.buttons[1],
                    self.buttons[0],
                    self.buttons[9],
                    self.buttons[8],
                    self.buttons[7],
                    self.buttons[6],
                    self.buttons[5],
                ]
            }
            5 => {
                [
                    self.direct_select,
                    self.value_2,
                    self.value_1,
                    self.number,
                    self.select,
                    self.switches,
                    self.config,
                    false,
                ]
            }
            _ => return 0xFF,
        };
        let mut value = 0;
        for (i, bit) in bits.iter().enumerate() {
            if !*bit {
                value |= 1 << i;
            }
        }
        value
    }
}