From dc48f46a4f536d176d194d28642dabeffb891453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Kr=C3=BCger?= Date: Thu, 3 Oct 2024 20:58:44 +0200 Subject: [PATCH] fine tuned: ambient light level, PWM signal, LED dimming curve, readme --- README.md | 71 ++++++------- code/Cargo.lock | 159 ++++++++++++++++-------------- code/Cargo.toml | 2 +- code/src/main.rs | 10 +- code/src/peripheral.rs | 10 +- hardware/wiring_diagram.drawio | 59 +++-------- hardware/wiring_diagram_dark.svg | 2 +- hardware/wiring_diagram_light.svg | 2 +- 8 files changed, 149 insertions(+), 166 deletions(-) diff --git a/README.md b/README.md index fc69446..74d9cb0 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,20 @@ # Sensor Light -A smart light bar — illuminates dark places on-demand by gently dimming up/down a LED stripe depending on the ambient light level and a detected human presence. +_A smart light bar — illuminates dark places on-demand by gently dimming up/down a LED stripe depending on the ambient light level and a detected human presence._ -This automatic light is completely self-contained – just needs 12V power supply. +This automatic light is completely self-contained – just needs a suitable 12V power supply. -An advanced but quite cheap presence sensor is used here, which works to my satisfaction. The circuit and software is designed to save power where possible. -An ESP32-H2 SoC low power processor serves for the logic. It is connected to a VEML7700 ambient light sensor and the mentioned small but effective LD2410 radar based presence sensor. +An advanced (and quite cheap) presence sensor is used here, which works to my satisfaction. However, it should be fine-tuned using the manufacturers app at the final location to get the best out of it. -It does NOT need nor use any Wifi / Zigbee / Matter features of the ESP32-H2 SoC. One may feel free to add a Smart Home connector on his own. +The circuit and software is designed to save power where possible. +An ESP32-H2 SoC low power processor serves for the logic. It is connected to a VEML7700 ambient light sensor and the mentioned small but effective LD2410 radar based presence sensor. -_Status: Hardware and Software is feature complete, tested and ready to Roll 'n' Roll._ +It does NOT need nor use any Wifi / Zigbee / Matter features of the ESP32-H2 SoC. One may feel free to add some sort of Smart Home connector on his own. - - Light bar sketch - +__Status: Hardware and Software is feature complete, tested and ready to Roll 'n' Roll.__ +--- ## Hardware - - - - - - - -
drawingdrawing
-
- ### Wiring diagram @@ -41,27 +30,30 @@ Please note: ### Parts -#### LED Bar parts -- ESP32-H2-WROOM-03 (the 2MB flash model is sufficient) +#### LED bar + +_Designed for 12V and (up to) 35W LED Stripe._ + +- ESP32-H2-WROOM-03 _(the 2MB flash model is sufficient)_ - VEML7700 Ambient Light Sensor - HLK-LD2410 Radar presence sensor (2x) - BC337-40 TO92 NPN Transistor (2x) - BC327-40 TO92 PNP Transistor - IRLB8721PbF N-Channel MOSFET (TO-220) -- Resistor 1 kΩ -- Resistor 10 kΩ (2x) -- Resistor 4.7 kΩ -- Capacitor 0.1 µF (2x) -- Capacitor 1.0 µF +- Resistor 1kΩ +- Resistor 10kΩ (2x) +- Resistor 4.7kΩ +- Capacitor 0.1µF (2x) +- Capacitor 10µF - 3.3V LDO voltage regulator LD1117V33 (SOT-223) - Diode (any, working at 3.3 V and 150mA max.) -- 5m LED Stripe +- 5m LED Stripe (12V, 3000-3200k, COB, 8mm wide, power: 5-7 W/m) - 12V DC Connector -- 12V Power Supply +- 12V, 5A Power Supply _(look for a good one to avoid flickering)_ - Wiring Board - 4 Pin Connector Mini Socket - Cables -- 5m LED Housing +- LED Housing (5m) #### USB Flash Adapter - USB-C Plug Female @@ -88,15 +80,24 @@ After connecting the ESP32-H2 via a flash adapter to a USB computer port: - `cargo run --release` _(flashes the chip)_ - `espflash monitor` _(optional – see ESP32 console output)_ -## References +## Prototype pictures -- [Transistors](http://stefanfrings.de/transistoren/index.html) -- [Switching with transistors](https://dl6gl.de/schalten-mit-transistoren.html) -- [The Rust on ESP Book - Setting Up a Development Environment](https://esp-rs.github.io/book/installation/index.html) + + Light bar sketch + + + + + + + +
drawingdrawing
+
## Terms & Conditions -Feel free to use anything here for learning, building your own version or make a product out of it and sell it. + +Feel free to use anything here for learning, building your own version or make a product out of it and sell it. Have fun! Pull requests are welcome. @@ -105,4 +106,4 @@ _bitmagier, September 2024_ --- -_In case you find this work useful and like to support me, I would be delighted to notice a donation in [Solana](https://solana.com/) to: [`FTMfeKYhpVAouuwXjpJXhnT13fkeNJqQsRGMBxBo1GML`](./hardware/pictures/solana_wallet.png)_ +_In case you find this work useful and like to support me, I would appreciate a donation in [Solana](https://solana.com/) to: [`FTMfeKYhpVAouuwXjpJXhnT13fkeNJqQsRGMBxBo1GML`](./hardware/pictures/solana_wallet.png)_ diff --git a/code/Cargo.lock b/code/Cargo.lock index 4f4939f..331b504 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "as-slice" @@ -64,9 +64,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "base64" @@ -93,7 +93,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.77", + "syn 2.0.79", "which", ] @@ -129,7 +129,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.18" +version = "1.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" dependencies = [ "shlex", ] @@ -343,7 +343,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -354,7 +354,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -377,7 +377,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -553,7 +553,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -665,9 +665,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", "miniz_oxide", @@ -745,9 +745,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" dependencies = [ "aho-corasick", "bstr", @@ -809,9 +809,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -848,9 +848,9 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" dependencies = [ "crossbeam-deque", "globset", @@ -919,9 +919,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -1062,14 +1062,17 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "percent-encoding" @@ -1089,6 +1092,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "prettyplease" version = "0.2.22" @@ -1096,7 +1105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1105,7 +1114,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit 0.22.20", + "toml_edit 0.22.22", ] [[package]] @@ -1152,18 +1161,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -1173,9 +1182,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -1184,22 +1193,22 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "remove_dir_all" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c914caef075f03e9d5c568e2e71b3d3cf17dc61a5481ff379bb744721be0a75a" +checksum = "a694f9e0eb3104451127f6cc1e5de55f59d3b1fc8c5ddfaeb6f1e716479ceb4a" dependencies = [ "cfg-if", "cvt", "fs_at", "libc", "normpath", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1231,9 +1240,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.36" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -1244,9 +1253,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "log", "once_cell", @@ -1259,15 +1268,15 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -1306,7 +1315,7 @@ dependencies = [ [[package]] name = "sensor-light" -version = "1.0.3-pre" +version = "1.2.0-pre" dependencies = [ "anyhow", "embuild", @@ -1335,7 +1344,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1352,9 +1361,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -1418,7 +1427,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1440,9 +1449,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -1451,9 +1460,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -1464,22 +1473,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1533,13 +1542,13 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", - "winnow 0.6.18", + "winnow 0.6.20", ] [[package]] @@ -1559,24 +1568,24 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "untrusted" @@ -1671,7 +1680,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -1693,7 +1702,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1706,9 +1715,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] @@ -1836,9 +1845,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/code/Cargo.toml b/code/Cargo.toml index abca302..b0df27c 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sensor-light" -version = "1.0.3-pre" +version = "1.2.0" authors = ["bitmagier "] edition = "2021" resolver = "2" diff --git a/code/src/main.rs b/code/src/main.rs index 7a8a64f..868874a 100644 --- a/code/src/main.rs +++ b/code/src/main.rs @@ -16,18 +16,18 @@ mod peripheral; pub const LED_POWER_STAGES: u32 = 1000; /// Percentage of hardware maximum LED brightness we want to reach -pub const LED_MAX_POWER_LEVEL_PERCENT: f32 = 0.15; +pub const LED_MAX_POWER_LEVEL_PERCENT: f32 = 0.10; /// max. reaction delay when LED Power Phase is in Off or ON state pub const ON_OFF_REACTION_STEP_DELAY_MS: u32 = 500; // step-delay (and also max. reaction time) when LED Power Phase is in PowerDown or PowerUp state -pub const LED_DIMM_DOWN_STEP_DELAY_MS: u32 = 15; +pub const LED_DIM_DOWN_STEP_DELAY_MS: u32 = 15; -pub const LED_DIMM_UP_STEP_DELAY_MS: u32 = 6; +pub const LED_DIM_UP_STEP_DELAY_MS: u32 = 6; pub const LUX_BUFFER_SIZE: usize = 10; -pub const LUX_THRESHOLD: f32 = 0.30; +pub const LUX_THRESHOLD: f32 = 0.10; const STATUS_LOG_INTERVAL: Duration = Duration::from_secs(2); @@ -72,7 +72,7 @@ fn main() -> Result<()> { FreeRtos::delay_ms(state.duty_step_delay_ms()); devices.read_sensors(&mut state)?; - state.calc_dimm_progress(); + state.calc_dim_progress(); devices.apply_led_power_level(&mut state)?; devices.steer_presence_sensor(&mut state)?; } diff --git a/code/src/peripheral.rs b/code/src/peripheral.rs index e828fbe..3b5f2a6 100644 --- a/code/src/peripheral.rs +++ b/code/src/peripheral.rs @@ -16,7 +16,7 @@ use itertools::Itertools; use ringbuffer::{AllocRingBuffer, RingBuffer}; use veml7700::{PowerSavingMode, Veml7700}; -use crate::{LED_DIMM_DOWN_STEP_DELAY_MS, LED_DIMM_UP_STEP_DELAY_MS, LED_MAX_POWER_LEVEL_PERCENT, LED_POWER_STAGES, LUX_BUFFER_SIZE, LUX_THRESHOLD, ON_OFF_REACTION_STEP_DELAY_MS, STATUS_LOG_INTERVAL}; +use crate::{LED_DIM_DOWN_STEP_DELAY_MS, LED_DIM_UP_STEP_DELAY_MS, LED_MAX_POWER_LEVEL_PERCENT, LED_POWER_STAGES, LUX_BUFFER_SIZE, LUX_THRESHOLD, ON_OFF_REACTION_STEP_DELAY_MS, STATUS_LOG_INTERVAL}; use crate::error::Error; pub struct PresenceSensor { @@ -74,12 +74,12 @@ impl State { pub fn duty_step_delay_ms(&self) -> u32 { match self.phase { Phase::Off | Phase::On => ON_OFF_REACTION_STEP_DELAY_MS, - Phase::PowerDown => LED_DIMM_DOWN_STEP_DELAY_MS, - Phase::PowerUp => LED_DIMM_UP_STEP_DELAY_MS + Phase::PowerDown => LED_DIM_DOWN_STEP_DELAY_MS, + Phase::PowerUp => LED_DIM_UP_STEP_DELAY_MS } } - pub fn calc_dimm_progress(&mut self) { + pub fn calc_dim_progress(&mut self) { match self.phase { Phase::Off => debug_assert_eq!(self.led_power_stage, 0), Phase::PowerDown => { @@ -299,7 +299,7 @@ where C: LedcChannel::SpeedMode>, T: LedcTimer + 'static, { - let freq = 500.Hz(); + let freq = 4321.Hz(); let resolution = Resolution::Bits12; let timer_config = TimerConfig::default() diff --git a/hardware/wiring_diagram.drawio b/hardware/wiring_diagram.drawio index 7bdf45a..93073df 100644 --- a/hardware/wiring_diagram.drawio +++ b/hardware/wiring_diagram.drawio @@ -1,6 +1,6 @@ - + - + @@ -158,14 +158,8 @@ - - - - - - - + @@ -266,8 +260,7 @@ - - + @@ -355,12 +348,6 @@ - - - - - - @@ -478,11 +465,12 @@ - + - + + @@ -663,14 +651,8 @@ - - - - - - - + @@ -678,12 +660,6 @@ - - - - - - @@ -730,12 +706,6 @@ - - - - - - @@ -773,14 +743,14 @@ - + - + @@ -820,7 +790,7 @@ - + @@ -836,9 +806,9 @@ - + - + @@ -856,6 +826,9 @@ + + + diff --git a/hardware/wiring_diagram_dark.svg b/hardware/wiring_diagram_dark.svg index 7d5ef15..2cca8a6 100644 --- a/hardware/wiring_diagram_dark.svg +++ b/hardware/wiring_diagram_dark.svg @@ -1,3 +1,3 @@ -
LED Stripe (5m)
SCL
SDA
+ 12 V 
GND for LED (PWM)
GND
3.3V
PWM signal (inverted)
IO9
GND
D+
D-
Presence Sensor
HLK-LD2410
Presence Sensor
HLK -LD2410
12 V
Presence Sensor Signal
MOSFET
N-Channel
IRLB8721PbF
USB-C socket
0.1 µF
Boot mode selector
LDO
Voltage regulator
LD1117V33
10 µF
0.1 µF
ESP32-H2
(front side)
ESP32-H2
(back side)
NPN Transistor
BC337-40
10 kΩ
4.7 kΩ
PWM signal (inverted)
10 kΩ
Presence sensor power (12V switched)
NPN Transistor
BC337-40
Presence Sensor Power switch
PNP Transistor
BC327-40
kΩ
Sensor Light
Wiring Diagram
v1.1.2
Diode
Diode
\ No newline at end of file +
LED Stripe (5m)
SCL
SDA
+ 12 V 
GND for LED (PWM)
GND
3.3V
PWM signal (inverted)
IO9
GND
D+
D-
Presence Sensor
HLK-LD2410
Presence Sensor
HLK -LD2410
12 V
Presence Sensor Signal
MOSFET
N-Channel
IRLB8721PbF
USB-C socket
0.1 µF
Boot mode selector
LDO
Voltage regulator
LD1117V33
10 µF
0.1 µF
ESP32-H2
(front side)
ESP32-H2
(back side)
NPN Transistor
BC337-40
10 kΩ
4.7 kΩ
PWM signal (inverted)
10 kΩ
Presence sensor power (12V switched)
NPN Transistor
BC337-40
Presence Sensor Power switch
PNP Transistor
BC327-40
kΩ
Sensor Light
Wiring Diagram
v1.2
Diode
Diode
\ No newline at end of file diff --git a/hardware/wiring_diagram_light.svg b/hardware/wiring_diagram_light.svg index ce8b759..7ec46dd 100644 --- a/hardware/wiring_diagram_light.svg +++ b/hardware/wiring_diagram_light.svg @@ -1,3 +1,3 @@ -
LED Stripe (5m)
SCL
SDA
+ 12 V 
GND for LED (PWM)
GND
3.3V
PWM signal (inverted)
IO9
GND
D+
D-
Presence Sensor
HLK-LD2410
Presence Sensor
HLK -LD2410
12 V
Presence Sensor Signal
MOSFET
N-Channel
IRLB8721PbF
USB-C socket
0.1 µF
Boot mode selector
LDO
Voltage regulator
LD1117V33
10 µF
0.1 µF
ESP32-H2
(front side)
ESP32-H2
(back side)
NPN Transistor
BC337-40
10 kΩ
4.7 kΩ
PWM signal (inverted)
10 kΩ
Presence sensor power (12V switched)
NPN Transistor
BC337-40
Presence Sensor Power switch
PNP Transistor
BC327-40
kΩ
Sensor Light
Wiring Diagram
v1.1.2
Diode
Diode
\ No newline at end of file +
LED Stripe (5m)
SCL
SDA
+ 12 V 
GND for LED (PWM)
GND
3.3V
PWM signal (inverted)
IO9
GND
D+
D-
Presence Sensor
HLK-LD2410
Presence Sensor
HLK -LD2410
12 V
Presence Sensor Signal
MOSFET
N-Channel
IRLB8721PbF
USB-C socket
0.1 µF
Boot mode selector
LDO
Voltage regulator
LD1117V33
10 µF
0.1 µF
ESP32-H2
(front side)
ESP32-H2
(back side)
NPN Transistor
BC337-40
10 kΩ
4.7 kΩ
PWM signal (inverted)
10 kΩ
Presence sensor power (12V switched)
NPN Transistor
BC337-40
Presence Sensor Power switch
PNP Transistor
BC327-40
kΩ
Sensor Light
Wiring Diagram
v1.2
Diode
Diode
\ No newline at end of file