DaneSlattery / hx711

A no-std rust library for the ESP32
GNU General Public License v3.0
6 stars 5 forks source link

Add `set_offset` #13

Closed weiying-chen closed 5 months ago

weiying-chen commented 5 months ago

Use case:

When the ESP32 wakes up from deep sleep, it runs the code from the beginning. If tare() is used, a new offset will be created each time, which will produce a reading of 0 even if there is an object on the load cell. To overcome this, one could store a TARE_OFFSET variable in the RTC RAM and use that instead of tare(). To do that, we need a set_offset() function.

unsafe {
    if TARE_OFFSET != 0 {
        scale.set_offset(TARE_OFFSET);
    } else {
        scale.tare(32);
        TARE_OFFSET = scale.get_offset();
    }
    warn!("TARE_OFFSET after check: {}", TARE_OFFSET);
}
DaneSlattery commented 5 months ago

Hi Weiying-chan, thank you for the PR. I am happy for the change to go in, just want to use the associated types.