+ 'static, sysloop: EspSystemEventLoop,) -> Result>> { let mut auth_method = AuthMethod::WPA2Personal; if ssid.is_empty() { bail!("Missing WiFi name") } if pass.is_empty() { auth_method = AuthMethod::WPAWPA2Personal; info!("Wifi password is empty"); } let mut esp_wifi = EspWifi::new(modem, sysloop.clone(), None)?; let mut wifi = BlockingWifi::wrap(&mut esp_wifi, sysloop)?; wifi.set_configuration(&Configuration::Client(ClientConfiguration::default()))?; info!("Starting wifi..."); wifi.start()?; info!("Scanning..."); let ap_infos = wifi.scan()?; let ours = ap_infos.into_iter().find(|a| a.ssid == ssid); let channel = if let Some(ours) = ours { info!( "Found configured access point {} on channel {}", ssid, ours.channel ); Some(ours.channel) } else { info!( "Configured access point {} not found during scanning, will go with unknown channel", ssid ); None }; wifi.set_configuration(&Configuration::Mixed( ClientConfiguration { ssid: ssid.into(), password: pass.into(), channel, auth_method, ..Default::default() }, AccessPointConfiguration { ssid: "aptest".into(), channel: channel.unwrap_or(1), ..Default::default() }, ))?; info!("Connecting wifi..."); wifi.connect()?; info!("Waiting for DHCP lease..."); wifi.wait_netif_up()?; let ip_info = wifi.wifi().sta_netif().get_ip_info()?; info!("Wifi DHCP info: {:?}", ip_info); Ok(Box::new(esp_wifi))}
ir.rsCode: Select all
impl<'d> IrPwm<'d> { pub fn new( _timer: impl Peripheral
+ 'd, _channel: impl Peripheral
+ 'd, pin: impl Peripheral
+ 'd, ) -> Result { let timer_driver = LedcTimerDriver::new(_timer, &TimerConfig::default().frequency(38.kHz().into()))?; let mut driver = LedcDriver::new(_channel, timer_driver, pin)?; let max_duty = driver.get_max_duty(); driver.set_duty(max_duty / 3)?; driver.disable(); Ok(Self { driver }) } pub fn send(&mut self, data_code: u128) { let bytes = data_code.to_be_bytes(); let temp: String = bytes.iter().map(|byte| format!("{:08b}", byte)).collect(); let (data_code1, data_code2) = (&temp[0..35], &temp[35..67]); println!("{}, {}", data_code1, data_code2); self.driver.enable(); Delay::delay_us(K_GREE_HDR_MARK.try_into().unwrap()); // thread::sleep(Duration::from_micros(K_GREE_HDR_MARK)); self.no_send_ir(K_GREE_HDR_SPACE); for i in data_code1.bytes() { if i == b'0' { self.send_ir_zero(); } else { self.send_ir_one(); } } self.send_ir_zero(); self.no_send_ir(K_GREE_MSG_SPACE); for i in data_code2.bytes() { if i == b'0' { self.send_ir_zero(); } else { self.send_ir_one(); } } self.send_ir_zero(); } fn no_send_ir(&mut self, t: u64) { self.driver.disable(); Delay::delay_us(t.try_into().unwrap()); // thread::sleep(Duration::from_micros(t)); } fn send_ir(&mut self, e_t: u64, d_t: u64) { self.driver.enable(); Delay::delay_us(e_t.try_into().unwrap()); // thread::sleep(Duration::from_micros(e_t)); self.driver.disable(); Delay::delay_us(d_t.try_into().unwrap()); // thread::sleep(Duration::from_micros(d_t)); } // 发送二进制数据 1 fn send_ir_one(&mut self) { self.send_ir(K_GREE_BIT_MARK, K_GREE_ONE_SPACE); } // 发送二进制数据 0 fn send_ir_zero(&mut self) { self.send_ir(K_GREE_BIT_MARK, K_GREE_ZERO_SPACE); }}
举报
更多回帖