//! Template project for Rust on ESP32 (`no_std`) based on [`esp-hal`](https://github.com/esp-rs/esp-hal)
//!
//! Useful resources:
//! - [The Rust on ESP Book](https://docs.esp-rs.org/book/)
//! - [Embedded Rust (no_std) on Espressif](https://docs.esp-rs.org/no_std-training/)
//! - [Matrix channel](https://matrix.to/#/#esp-rs:matrix.org)

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{delay::Delay, prelude::*, gpio::*};
use log::info;
use one_wire_bus::OneWire;

#[entry]
fn main() -> ! {
    let peripherals = esp_hal::init({
        let mut config = esp_hal::Config::default();
        config.cpu_clock = CpuClock::max();
        config
    });

    esp_println::logger::init_logger_from_env();

    let mut delay = Delay::new();
    let mut one_wire_pin = Flex::new(peripherals.GPIO14);
    let mut one_wire_bus = OneWire::new(one_wire_pin).unwrap();

    loop {

    let devices = one_wire_bus.device_search(None, false, &mut delay);

    for device_address in devices {
        info!("Found device: {:?}", device_address);
    }
        info!("Hello world!");
        delay.delay(5.secs());
    }
}