pub fn create_present_and_init(
        i2c_bus: &'static BusManagerStd<I2c>,
        io_expander: &'static [HiveIoExpander; 8],
    ) -> Vec<Mutex<Self>> {
        let i2c: ShareableI2c = i2c_bus.acquire_i2c();
        let detected_tss = Self::detect_connected_tss(i2c);

        let mut created = vec![];

        for detected_addr in detected_tss.iter().filter_map(|tss| tss.as_ref()) {
            let tss = Self {
                inner: RefCell::new(Shield::new(
                    &io_expander[(*detected_addr - PCA9535_BASE_ADDR) as usize],
                )),
                position: *detected_addr - PCA9535_BASE_ADDR,
                targets: None,
            };

            created.push(Mutex::new(tss));
        }

        let mut i = 0;
        while i < created.len() {
            let tss = created[i].lock().unwrap();
            let mut inner = tss.inner.borrow_mut();
            match inner.init_pins() {
                Ok(_) => i += 1,
                Err(err) => {
                    if let Some(source) = err.source() {
                        log::warn!(
                            "Failed to initialize TSS at position {}: {}\nCaused by:\n{}",
                            tss.position,
                            err,
                            source
                        );
                    } else {
                        log::warn!(
                            "Failed to initialize TSS at position {}: {}",
                            tss.position,
                            err
                        );
                    }
                    drop(inner);
                    drop(tss); // unlock mutex

                    created.remove(i);
                }
            }
        }

        created
    }
/// Creates and returns all tss which are connected and successfully initialized
Creates and returns all tss which are connected and successfully initialized
Creates and returns all tss which are connected and successfully initialized
pub fn create_present_and_init(
        i2c_bus: &'static BusManagerStd<I2c>,
        io_expander: &'static [HiveIoExpander; 8],
    ) -> Vec<Mutex<Self>> {
        let i2c: ShareableI2c = i2c_bus.acquire_i2c();
        let detected_tss = Self::detect_connected_tss(i2c);
        let mut created = vec![];
        for detected_addr in detected_tss.iter().filter_map(|tss| tss.as_ref()) {
            let tss = Self {
                inner: RefCell::new(Shield::new(
                    &io_expander[(*detected_addr - PCA9535_BASE_ADDR) as usize],
                )),
                position: *detected_addr - PCA9535_BASE_ADDR,
                targets: None,
            };
            created.push(Mutex::new(tss));
        }
        let mut i = 0;
        while i < created.len() {
            let tss = created[i].lock().unwrap();
            let mut inner = tss.inner.borrow_mut();
            match inner.init_pins() {
                Ok(_) => i += 1,
                Err(err) => {
                    if let Some(source) = err.source() {
                        log::warn!(
                            "Failed to initialize TSS at position {}: {}\nCaused by:\n{}",
                            tss.position,
                            err,
                            source
                        );
                    } else {
                        log::warn!(
                            "Failed to initialize TSS at position {}: {}",
                            tss.position,
                            err
                        );
                    }
                    drop(inner);
                    drop(tss); // unlock mutex
                    created.remove(i);
                }
            }
        }
        created
    }
pub fn create_present_and_init ( i2c_bus : & ' static BusManagerStd < I2c > , io_expander : & ' static [ HiveIoExpander ; 8 ] , ) -> Vec < Mutex < Self > > { let i2c : ShareableI2c = i2c_bus . acquire_i2c ( ) ; let detected_tss = Self :: detect_connected_tss ( i2c ) ; let mut created = vec ! [ ] ; for detected_addr in detected_tss . iter ( ) . filter_map ( | tss | tss . as_ref ( ) ) { let tss = Self { inner : RefCell :: new ( Shield :: new ( & io_expander [ ( * detected_addr - PCA9535_BASE_ADDR ) as usize ] , ) ) , position : * detected_addr - PCA9535_BASE_ADDR , targets : None , } ; created . push ( Mutex :: new ( tss ) ) ; } let mut i = 0 ; while i < created . len ( ) { let tss = created [ i ] . lock ( ) . unwrap ( ) ; let mut inner = tss . inner . borrow_mut ( ) ; match inner . init_pins ( ) { Ok ( _ ) => i += 1 , Err ( err ) => { if let Some ( source ) = err . source ( ) { log :: warn ! ( " \n \n " tss position err source ) ; } else { log :: warn ! ( " " tss position err ) ; } drop ( inner ) ; drop ( tss ) ; // unlock mutex created . remove ( i ) ; } } } created }
Creates and returns all tss which are connected and successfully initialized
Creates and returns all tss which are connected and successfully initialized
i2c_bus
&'static BusManagerStd<I2c>
io_expander
&'static [HiveIoExpander; 8]