fn command(
        &self,
        command_num: usize,
        data: usize,
        _: usize,
        appid: ProcessId,
    ) -> CommandReturn {
        let pins = self.pins;
        match command_num {
            // return button count
            0 => CommandReturn::success_u32(pins.len() as u32),

            // enable interrupts for a button
            1 => {
                if data < pins.len() {
                    self.apps
                        .enter(appid, |cntr, _| {
                            cntr.subscribe_map |= 1 << data;
                            let _ = pins[data]
                                .0
                                .enable_interrupts(gpio::InterruptEdge::EitherEdge);
                            CommandReturn::success()
                        })
                        .unwrap_or_else(|err| CommandReturn::failure(err.into()))
                } else {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                }
            }

            // disable interrupts for a button
            2 => {
                if data >= pins.len() {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                } else {
                    let res = self
                        .apps
                        .enter(appid, |cntr, _| {
                            cntr.subscribe_map &= !(1 << data);
                            CommandReturn::success()
                        })
                        .unwrap_or_else(|err| CommandReturn::failure(err.into()));

                    // are any processes waiting for this button?
                    let interrupt_count = Cell::new(0);
                    self.apps.each(|_, cntr, _| {
                        if cntr.subscribe_map & (1 << data) != 0 {
                            interrupt_count.set(interrupt_count.get() + 1);
                        }
                    });

                    // if not, disable the interrupt
                    if interrupt_count.get() == 0 {
                        self.pins[data].0.disable_interrupts();
                    }

                    res
                }
            }

            // read input
            3 => {
                if data >= pins.len() {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                } else {
                    let button_state = self.get_button_state(data as u32);
                    debug!("AAAAAAAAAAAAAAAAAA\n");
                    CommandReturn::success_u32(button_state as u32)
                }
            }

            // default
            _ => CommandReturn::failure(ErrorCode::NOSUPPORT),
        }
    }
/// Configure interrupts and read state for buttons.
///
/// `data` is the index of the button in the button array as passed to
/// `Button::new()`.
///
/// All commands greater than zero return `INVAL` if an invalid button
/// number is passed in.
///
/// ### `command_num`
///
/// - `0`: Driver check and get number of buttons on the board.
/// - `1`: Enable interrupts for a given button. This will enable both press
///   and depress events.
/// - `2`: Disable interrupts for a button. No affect or reliance on
///   registered callback.
/// - `3`: Read the current state of the button.
Configure interrupts and read state for buttons.
`data` is the index of the button in the button array as passed to
`Button::new()`.

All commands greater than zero return `INVAL` if an invalid button
number is passed in.
Configure interrupts and read state for buttons . ` data ` is the index of the button in the button array as passed to ` Button :: new () ` . All commands greater than zero return ` INVAL ` if an invalid button number is passed in .
fn command(
        &self,
        command_num: usize,
        data: usize,
        _: usize,
        appid: ProcessId,
    ) -> CommandReturn {
        let pins = self.pins;
        match command_num {
            // return button count
            0 => CommandReturn::success_u32(pins.len() as u32),
            // enable interrupts for a button
            1 => {
                if data < pins.len() {
                    self.apps
                        .enter(appid, |cntr, _| {
                            cntr.subscribe_map |= 1 << data;
                            let _ = pins[data]
                                .0
                                .enable_interrupts(gpio::InterruptEdge::EitherEdge);
                            CommandReturn::success()
                        })
                        .unwrap_or_else(|err| CommandReturn::failure(err.into()))
                } else {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                }
            }
            // disable interrupts for a button
            2 => {
                if data >= pins.len() {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                } else {
                    let res = self
                        .apps
                        .enter(appid, |cntr, _| {
                            cntr.subscribe_map &= !(1 << data);
                            CommandReturn::success()
                        })
                        .unwrap_or_else(|err| CommandReturn::failure(err.into()));
                    // are any processes waiting for this button?
                    let interrupt_count = Cell::new(0);
                    self.apps.each(|_, cntr, _| {
                        if cntr.subscribe_map & (1 << data) != 0 {
                            interrupt_count.set(interrupt_count.get() + 1);
                        }
                    });
                    // if not, disable the interrupt
                    if interrupt_count.get() == 0 {
                        self.pins[data].0.disable_interrupts();
                    }
                    res
                }
            }
            // read input
            3 => {
                if data >= pins.len() {
                    CommandReturn::failure(ErrorCode::INVAL) /* impossible button */
                } else {
                    let button_state = self.get_button_state(data as u32);
                    debug!("AAAAAAAAAAAAAAAAAA\n");
                    CommandReturn::success_u32(button_state as u32)
                }
            }
            // default
            _ => CommandReturn::failure(ErrorCode::NOSUPPORT),
        }
    }
fn command ( & self , command_num : usize , data : usize , _ : usize , appid : ProcessId , ) -> CommandReturn { let pins = self . pins ; match command_num { // return button count 0 => CommandReturn :: success_u32 ( pins . len ( ) as u32 ) , // enable interrupts for a button 1 => { if data < pins . len ( ) { self . apps . enter ( appid , | cntr , _ | { cntr . subscribe_map |= 1 << data ; let _ = pins [ data ] . 0 . enable_interrupts ( gpio :: InterruptEdge :: EitherEdge ) ; CommandReturn :: success ( ) } ) . unwrap_or_else ( | err | CommandReturn :: failure ( err . into ( ) ) ) } else { CommandReturn :: failure ( ErrorCode :: INVAL ) /* impossible button */ } } // disable interrupts for a button 2 => { if data >= pins . len ( ) { CommandReturn :: failure ( ErrorCode :: INVAL ) /* impossible button */ } else { let res = self . apps . enter ( appid , | cntr , _ | { cntr . subscribe_map &= ! ( 1 << data ) ; CommandReturn :: success ( ) } ) . unwrap_or_else ( | err | CommandReturn :: failure ( err . into ( ) ) ) ; // are any processes waiting for this button? let interrupt_count = Cell :: new ( 0 ) ; self . apps . each ( | _ , cntr , _ | { if cntr . subscribe_map & ( 1 << data ) != 0 { interrupt_count . set ( interrupt_count . get ( ) + 1 ) ; } } ) ; // if not, disable the interrupt if interrupt_count . get ( ) == 0 { self . pins [ data ] . 0 . disable_interrupts ( ) ; } res } } // read input 3 => { if data >= pins . len ( ) { CommandReturn :: failure ( ErrorCode :: INVAL ) /* impossible button */ } else { let button_state = self . get_button_state ( data as u32 ) ; debug ! ( " \n " ) ; CommandReturn :: success_u32 ( button_state as u32 ) } } // default _ => CommandReturn :: failure ( ErrorCode :: NOSUPPORT ) , } }
Configure interrupts and read state for buttons.
Configure interrupts and read state for buttons .
&self
command_num
usize
data
usize
appid
ProcessId
&self
command_num
usize
data
usize
appid
ProcessId
`command_num`
`0`: Driver check and get number of buttons on the board.
`1`: Enable interrupts for a given button. This will enable both press
and depress events.
`2`: Disable interrupts for a button. No affect or reliance on
registered callback.
`3`: Read the current state of the button.
` 0 ` : Driver check and get number of buttons on the board . ` 1 ` : Enable interrupts for a given button . This will enable both press and depress events . ` 2 ` : Disable interrupts for a button . No affect or reliance on registered callback . ` 3 ` : Read the current state of the button .