!LdaNPfUfvefOLewEIM:matrix.org

esp-rs

754 Members
Using Rust on the ESP series microcontrollers. https://github.com/esp-rs | https://matrix.to/#/#esp-rs-community-meetins:matrix.org | https://esp-rs.github.io/book/overview.html79 Servers

Load older messages


SenderMessageTime
22 Jan 2022
@jessebraham:matrix.orgjessebraham

I think it's fine, really it just comes down to preferences at this point. For example, I would personally lay this out a bit differently, but it's functionally the same. I'd do something like this (not saying this is "more" correct, just my preference):

fn light_state_get_handler<T>(
    _request: &mut EspHttpRequest,
    mutex: &Arc<Mutex<T>>,
) -> Result<ResponseData>
where
    T: StatefulOutputPin,
{
    if let Ok(led) = mutex.lock() {
        let response = if led.is_set_high().unwrap() {
            ResponseData::new(299).body(r#"<h1>light ist off</h1>"#.into())
        else {
            ResponseData::new(298).body(r#"<h1>light is on</h1>"#.into()),
        };

        Ok(response)
    } else {
        Ok(ResponseData::new(500))
    }
}
17:32:36
@jessebraham:matrix.orgjessebraham *

I think it's fine, really it just comes down to preferences at this point. For example, I would personally lay this out a bit differently, but it's functionally the same. I'd do something like this (not saying this is "more" correct, just my preference):

fn light_state_get_handler<T>(
    _request: &mut EspHttpRequest,
    mutex: &Arc<Mutex<T>>,
) -> Result<ResponseData>
where
    T: StatefulOutputPin,
{
    if let Ok(led) = mutex.lock() {
        let response = if led.is_set_high().unwrap() {
            ResponseData::new(299).body(r#"<h1>light ist off</h1>"#.into())
        else {
            ResponseData::new(298).body(r#"<h1>light is on</h1>"#.into())
        };

        Ok(response)
    } else {
        Ok(ResponseData::new(500))
    }
}
17:33:46
@3ster:matrix.org3ster
In reply to @jessebraham:matrix.org

I think it's fine, really it just comes down to preferences at this point. For example, I would personally lay this out a bit differently, but it's functionally the same. I'd do something like this (not saying this is "more" correct, just my preference):

fn light_state_get_handler<T>(
    _request: &mut EspHttpRequest,
    mutex: &Arc<Mutex<T>>,
) -> Result<ResponseData>
where
    T: StatefulOutputPin,
{
    if let Ok(led) = mutex.lock() {
        let response = if led.is_set_high().unwrap() {
            ResponseData::new(299).body(r#"<h1>light ist off</h1>"#.into())
        else {
            ResponseData::new(298).body(r#"<h1>light is on</h1>"#.into())
        };

        Ok(response)
    } else {
        Ok(ResponseData::new(500))
    }
}
thats whay more readable, thx! Did not know that I can write it like that :)
PS: how do you make the Matrix syntax highlighting?
22:44:00
@3ster:matrix.org3ster
In reply to @jessebraham:matrix.org

I think it's fine, really it just comes down to preferences at this point. For example, I would personally lay this out a bit differently, but it's functionally the same. I'd do something like this (not saying this is "more" correct, just my preference):

fn light_state_get_handler<T>(
    _request: &mut EspHttpRequest,
    mutex: &Arc<Mutex<T>>,
) -> Result<ResponseData>
where
    T: StatefulOutputPin,
{
    if let Ok(led) = mutex.lock() {
        let response = if led.is_set_high().unwrap() {
            ResponseData::new(299).body(r#"<h1>light ist off</h1>"#.into())
        else {
            ResponseData::new(298).body(r#"<h1>light is on</h1>"#.into())
        };

        Ok(response)
    } else {
        Ok(ResponseData::new(500))
    }
}
* that's way more readable, thx! Did not know that I can write it like that :)
PS: how do you make the Matrix syntax highlighting?
22:44:31
23 Jan 2022
@sirhcel:matrix.orgsirhcel 3ster: you can enable syntax highlighting when starting a code block with three backticks immediately followed by the language, for example for rust: [BACKTICK][BACKTICK][BACKTICK]rust where [BACKTICK] stands for an actual backtick. 01:05:10
@sirhcel:matrix.orgsirhcel Does anyone know how to check the code examples in rustdoc comments? For "desktop" code (host == target) cargo test --doc does the trick. But i'm failing to convince cargo or rustdoc to do this. 01:09:13
@sirhcel:matrix.orgsirhcel * Does anyone know how to check the code examples in rustdoc comments? For "desktop" code (host == target) cargo test --doc does the trick. But i'm failing to convince cargo or rustdoc to do this for esp-idf-hal 01:09:29
@9names:matrix.org9names hmm, on CI for cortex-m we do cargo test --doc --target x86_64-unknown-linux-gnu , but I don't know if that will work for esp-idf-hal 05:37:42
@spookeee:matrix.orgspookeee joined the room.08:14:59
@sirhcel:matrix.orgsirhcel

This way does not work out for esp-idf-hal due to platformio which fails to build for the host target.

$ cargo test --doc --target aarch64-apple-darwin
   Compiling esp-idf-sys v0.30.1
error: failed to run custom build command for `esp-idf-sys v0.30.1`
[...]
  Error: Cannot derive default PIO platform, MCU and frameworks for target 'aarch64-apple-darwin'
10:48:59
@sirhcel:matrix.orgsirhcel

And when attempting this for the actual target following the CI build command lines, this does not seem to tackle the example in which i deliberately put an error:

$ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo test --doc --target riscv32imc-esp-espidf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
    Finished test [unoptimized + debuginfo] target(s) in 0.05s

10:53:16
@sirhcel:matrix.orgsirhcel *

And when attempting this for the actual target following the CI build command lines, this does not seem to tackle the example in which i deliberately put an error:

$ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo test --doc --target riscv32imc-esp-espidf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
    Finished test [unoptimized + debuginfo] target(s) in 0.05s```
10:53:28
@sirhcel:matrix.orgsirhcel *

And when attempting this for the actual target following the CI build command lines, this does not seem to tackle the example in which i deliberately put an error:

$ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo test --doc --target riscv32imc-esp-espidf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
    Finished test [unoptimized + debuginfo] target(s) in 0.05s
10:53:36
@happysalada:matrix.org@happysalada:matrix.org left the room.15:16:28
@arodera:matrix.orgarodera joined the room.15:51:48
@sirhcel:matrix.orgsirhcel I gave up on checking the doc example with cargo test and cargo doc and i'm trying a standalone example. If i ignore some Results, this works fine. But i'm struggling go propagate errors from main unsing the question mark operator like in rust-esp32-std-demo's main. 23:15:34
@sirhcel:matrix.orgsirhcel Which return type is used there? Inspecting this with vs code directs me to anyhow::Result. But actually using this type gives me an error at link time shown in this gist and i am clueless. ivmarkov, did i pick the wrong return type? This looks like a big bang to me but i don't understand its cause. 23:29:50
24 Jan 2022
@ivmarkov:matrix.orgivmarkov sirhcel: your link error has nothing to do with your error propagation patches. You are missing a call to esp-idf-sys as shown here: https://github.com/esp-rs/esp-idf-template/blob/master/cargo/src/main.rs#L12 05:29:25
@ivmarkov:matrix.orgivmarkov* sirhcel: your link error has nothing to do with your error propagation troubles. You are missing a call to esp-idf-sys as shown here: https://github.com/esp-rs/esp-idf-template/blob/master/cargo/src/main.rs#L1205:29:50
@jamont:matrix.orgjamont joined the room.08:59:37
@sirhcel:matrix.orgsirhcel Thank you very much ivmarkov! This fixed my build. 10:18:58
@sirhcel:matrix.orgsirhcel

My next attempt is to add the example which now successfully builds in rust-esp32-std-demo to esp-idf-hal under examples/. I managed to bring ldproxy in place by using the [target.X] sections from .cargo/config.toml in esp-idf-hal as well. But it seems that it is desperately missing the argument --ldproxy-linker:

esp-idf-hal $ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo build --example ledc-simple --target riscv32imc-esp-esp
idf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
10:36:01
@sirhcel:matrix.orgsirhcel *

My next attempt is to add the example which now successfully builds in rust-esp32-std-demo to esp-idf-hal under examples/. I managed to bring ldproxy in place by using the [target.X] sections from .cargo/config.toml in esp-idf-hal as well. But it seems that it is desperately missing the argument --ldproxy-linker:

esp-idf-hal $ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo build --example ledc-simple --target riscv32imc-esp-esp
idf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
   Compiling esp-idf-hal v0.32.4 (/Users/christian/Entwicklung/rust/moisture-control/esp-idf-hal)
10:36:13
@sirhcel:matrix.orgsirhcel *

My next attempt is to add the example which now successfully builds in rust-esp32-std-demo to esp-idf-hal under examples/.

I managed to bring ldproxy in place by using the [target.X] sections from .cargo/config.toml in esp-idf-hal as well. But it seems that it is desperately missing the argument --ldproxy-linker:

esp-idf-hal $ export ESP_IDF_SDKCONFIG_DEFAULTS=$(pwd)/.github/configs/sdkconfig.defaults; cargo build --example ledc-simple --target riscv32imc-esp-esp
idf -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
   Compiling esp-idf-hal v0.32.4 (/[...]/esp-idf-hal)
error: linking with `ldproxy` failed: exit status: 101
[...]
  = note: Running ldproxy
          thread 'main' panicked at 'Cannot locate argument '--ldproxy-linker <linker>'', /[...]/.cargo/registry/src/github.com-1ecc6299db9ec823/ldproxy-0.3.0/src/main.rs:44:13

I don't see how this argument is injected by rust-esp32-std-demo at a first glance. Is this the right approach at all? What is the fairy dust needed here?

10:42:16
@simon0356:matrix.orgsimon0356Hi folks14:52:15
@simon0356:matrix.orgsimon0356I push a simple example of code using an ESP32 and waveshare Epaper 4.2" with rust14:52:51
@simon0356:matrix.orgsimon0356https://github.com/simon0356/rust-esp32-waveshare-4_214:52:52
@simon0356:matrix.orgsimon0356I made this to learn Rust using an ESP32, i will maybe try to implement in rust something similar to this project : https://github.com/G6EJD/ESP32-e-Paper-Weather-Display14:54:25
@simon0356:matrix.orgsimon0356my goal is to learn Rust 14:54:29
@simon0356:matrix.orgsimon0356 Thanks ivmarkov for the quick start guide 14:54:57

There are no newer messages yet.


Back to Room List