Compare commits
14 Commits
d8b4352a0f
...
v0.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
054b42547e | ||
|
|
b729d3f23d | ||
|
|
ba2b3b188a | ||
|
|
70e1559b24 | ||
|
|
94c591c087 | ||
|
|
a910015856 | ||
|
|
c5fef061f4 | ||
|
|
273bf2f946 | ||
|
|
5c12591524 | ||
|
|
6fe77a1286 | ||
|
|
1cb6f3a3ee | ||
|
|
fe4e48fbcc | ||
|
|
5e7285f45d | ||
|
|
5efb08ef99 |
@@ -53,6 +53,7 @@ shellHook = ''
|
|||||||
rustc --version
|
rustc --version
|
||||||
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
||||||
|
|
||||||
|
echo "cargo espflash save-image --release --chip esp32 test.bin"
|
||||||
echo ""
|
echo ""
|
||||||
echo "MQTT broker test (run manually in two terminals):"
|
echo "MQTT broker test (run manually in two terminals):"
|
||||||
echo " Terminal 1:"
|
echo " Terminal 1:"
|
||||||
|
|||||||
493
mqtt_display/Cargo.lock
generated
493
mqtt_display/Cargo.lock
generated
@@ -2,6 +2,12 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -20,6 +26,12 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "az"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "basic-toml"
|
name = "basic-toml"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@@ -46,7 +58,7 @@ checksum = "52511b09931f7d5fe3a14f23adefbc23e5725b184013e96c8419febb61f14734"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -57,9 +69,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.9.4"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
|
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byte-slice-cast"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
@@ -73,12 +91,35 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "castaway"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
|
||||||
|
dependencies = [
|
||||||
|
"rustversion",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.3"
|
version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "compact_str"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a"
|
||||||
|
dependencies = [
|
||||||
|
"castaway",
|
||||||
|
"cfg-if",
|
||||||
|
"itoa",
|
||||||
|
"rustversion",
|
||||||
|
"ryu",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "critical-section"
|
name = "critical-section"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -126,7 +167,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -139,7 +180,7 @@ dependencies = [
|
|||||||
"ident_case",
|
"ident_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -150,7 +191,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.20.11",
|
"darling_core 0.20.11",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -161,7 +202,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.21.3",
|
"darling_core 0.21.3",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -193,7 +234,7 @@ dependencies = [
|
|||||||
"proc-macro-error2",
|
"proc-macro-error2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -205,16 +246,6 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "defmt-rtt"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b2cac3b8a5644a9e02b75085ebad3b6deafdbdbdec04bb25086523828aa4dfd1"
|
|
||||||
dependencies = [
|
|
||||||
"critical-section",
|
|
||||||
"defmt 1.0.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "delegate"
|
name = "delegate"
|
||||||
version = "0.13.4"
|
version = "0.13.4"
|
||||||
@@ -223,7 +254,16 @@ checksum = "6178a82cf56c836a3ba61a7935cdb1c49bfaa6fa4327cd5bf554a503087de26b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -235,6 +275,35 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "display-interface"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7ba2aab1ef3793e6f7804162debb5ac5edb93b3d650fbcc5aeb72fcd0e6c03a0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "display-interface-i2c"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d964fa85bbbb5a6ecd06e58699407ac5dc3e3ad72dac0ab7e6b0d00a1cd262d"
|
||||||
|
dependencies = [
|
||||||
|
"display-interface",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "display-interface-spi"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f86b9ec30048b1955da2038fcc3c017f419ab21bb0001879d16c0a3749dc6b7a"
|
||||||
|
dependencies = [
|
||||||
|
"byte-slice-cast",
|
||||||
|
"display-interface",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "document-features"
|
name = "document-features"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -250,6 +319,12 @@ version = "0.15.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embassy-embedded-hal"
|
name = "embassy-embedded-hal"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -306,7 +381,7 @@ dependencies = [
|
|||||||
"darling 0.20.11",
|
"darling 0.20.11",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -437,6 +512,29 @@ dependencies = [
|
|||||||
"nb 1.1.0",
|
"nb 1.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-graphics"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0"
|
||||||
|
dependencies = [
|
||||||
|
"az",
|
||||||
|
"byteorder",
|
||||||
|
"embedded-graphics-core",
|
||||||
|
"float-cmp",
|
||||||
|
"micromath",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-graphics-core"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
|
||||||
|
dependencies = [
|
||||||
|
"az",
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-hal"
|
name = "embedded-hal"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
@@ -462,6 +560,16 @@ dependencies = [
|
|||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-hal-bus"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "513e0b3a8fb7d3013a8ae17a834283f170deaf7d0eeab0a7c1a36ad4dd356d22"
|
||||||
|
dependencies = [
|
||||||
|
"critical-section",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-io"
|
name = "embedded-io"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@@ -529,7 +637,7 @@ dependencies = [
|
|||||||
"darling 0.21.3",
|
"darling 0.21.3",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -544,7 +652,7 @@ version = "0.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7e95f1de57ce5a6600368f3d3c931b0dfe00501661e96f5ab83bc5cdee031784"
|
checksum = "7e95f1de57ce5a6600368f3d3c931b0dfe00501661e96f5ab83bc5cdee031784"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"allocator-api2",
|
"allocator-api2 0.3.1",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"critical-section",
|
"critical-section",
|
||||||
"document-features",
|
"document-features",
|
||||||
@@ -600,7 +708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f3887eda2917deef3d99e7a5c324f9190714e99055361ad36890dffd0a995b49"
|
checksum = "f3887eda2917deef3d99e7a5c324f9190714e99055361ad36890dffd0a995b49"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitfield",
|
"bitfield",
|
||||||
"bitflags 2.9.4",
|
"bitflags 2.10.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"critical-section",
|
"critical-section",
|
||||||
@@ -678,7 +786,7 @@ dependencies = [
|
|||||||
"proc-macro-crate",
|
"proc-macro-crate",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -713,6 +821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "3e7e3ab41e96093d7fd307e93bfc88bd646a8ff23036ebf809e116b18869f719"
|
checksum = "3e7e3ab41e96093d7fd307e93bfc88bd646a8ff23036ebf809e116b18869f719"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"critical-section",
|
"critical-section",
|
||||||
|
"defmt 1.0.1",
|
||||||
"document-features",
|
"document-features",
|
||||||
"esp-metadata-generated",
|
"esp-metadata-generated",
|
||||||
"log",
|
"log",
|
||||||
@@ -747,7 +856,7 @@ version = "0.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84908f2e95cb99a200cf448abafc416576338be590778a15d9224eee237f3210"
|
checksum = "84908f2e95cb99a200cf448abafc416576338be590778a15d9224eee237f3210"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"allocator-api2",
|
"allocator-api2 0.3.1",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"critical-section",
|
"critical-section",
|
||||||
"document-features",
|
"document-features",
|
||||||
@@ -856,12 +965,27 @@ version = "12.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "02a3229bec56a977f174b32fe7b8d89e8c79ebb4493d10ad763b6676dc2dc0c9"
|
checksum = "02a3229bec56a977f174b32fe7b8d89e8c79ebb4493d10ad763b6676dc2dc0c9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "float-cmp"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foldhash"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fugit"
|
name = "fugit"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -931,6 +1055,11 @@ name = "hashbrown"
|
|||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
||||||
|
dependencies = [
|
||||||
|
"allocator-api2 0.2.21",
|
||||||
|
"equivalent",
|
||||||
|
"foldhash",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heapless"
|
name = "heapless"
|
||||||
@@ -944,9 +1073,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heapless"
|
name = "heapless"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b1edcd5a338e64688fbdcb7531a846cfd3476a54784dcb918a0844682bc7ada5"
|
checksum = "2af2455f757db2b292a9b1768c4b70186d443bcb3b316252d6b540aec1cd89ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hash32",
|
"hash32",
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
@@ -992,7 +1121,25 @@ dependencies = [
|
|||||||
"indoc",
|
"indoc",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1022,7 +1169,28 @@ checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kasuari"
|
||||||
|
version = "0.4.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fe90c1150662e858c7d5f945089b7517b0a80d8bf7ba4b1b5ffc984e7230a5b"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown",
|
||||||
|
"portable-atomic",
|
||||||
|
"portable-atomic-util",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "line-clipping"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f4de44e98ddbf09375cbf4d17714d18f39195f4f4894e8524501726fd9a8a4a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1046,18 +1214,56 @@ version = "0.4.28"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lru"
|
||||||
|
version = "0.16.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "managed"
|
name = "managed"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
|
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "maybe-async-cfg"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1e083394889336bc66a4eaf1011ffbfa74893e910f902a9f271fa624c61e1b2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"pulldown-cmark",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.6"
|
version = "2.7.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "micromath"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mousefood"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "git+https://github.com/j-g00da/mousefood?branch=main#693d82ae9482c32be6363e72474faeb7d962cb1b"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-graphics",
|
||||||
|
"ratatui-core",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nb"
|
name = "nb"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
@@ -1073,6 +1279,12 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-derive"
|
name = "num-derive"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -1081,7 +1293,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1093,6 +1305,13 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pages-tui"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"heapless 0.9.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "paste"
|
name = "paste"
|
||||||
version = "1.0.15"
|
version = "1.0.15"
|
||||||
@@ -1144,9 +1363,15 @@ checksum = "a33fa6ec7f2047f572d49317cca19c87195de99c6e5b6ee492da701cfe02b053"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "3.4.0"
|
version = "3.4.0"
|
||||||
@@ -1156,6 +1381,30 @@ dependencies = [
|
|||||||
"toml_edit",
|
"toml_edit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error-attr2"
|
name = "proc-macro-error-attr2"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@@ -1175,7 +1424,7 @@ dependencies = [
|
|||||||
"proc-macro-error-attr2",
|
"proc-macro-error-attr2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1189,16 +1438,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "projekt_final"
|
name = "projekt_final"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"critical-section",
|
"critical-section",
|
||||||
"defmt-rtt",
|
"defmt 1.0.1",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
"embassy-futures",
|
"embassy-futures",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
"embassy-sync 0.7.2",
|
"embassy-sync 0.7.2",
|
||||||
"embassy-time 0.5.0",
|
"embassy-time 0.5.0",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-bus",
|
||||||
"embedded-io",
|
"embedded-io",
|
||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"esp-alloc",
|
"esp-alloc",
|
||||||
@@ -1208,13 +1459,28 @@ dependencies = [
|
|||||||
"esp-hal-embassy",
|
"esp-hal-embassy",
|
||||||
"esp-println",
|
"esp-println",
|
||||||
"esp-wifi",
|
"esp-wifi",
|
||||||
"heapless 0.9.1",
|
"heapless 0.9.2",
|
||||||
"log",
|
"log",
|
||||||
|
"mousefood",
|
||||||
|
"pages-tui",
|
||||||
|
"ratatui",
|
||||||
"rust-mqtt",
|
"rust-mqtt",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
|
"ssd1306",
|
||||||
"static_cell",
|
"static_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pulldown-cmark"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"memchr",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.41"
|
version = "1.0.41"
|
||||||
@@ -1242,6 +1508,67 @@ version = "0.9.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1ce67fb8ba4446454d1c8dbaeda0557ff5e94d39d5e5ed7f10a65eb4c8266bc"
|
||||||
|
dependencies = [
|
||||||
|
"instability",
|
||||||
|
"ratatui-core",
|
||||||
|
"ratatui-macros",
|
||||||
|
"ratatui-widgets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ef8dea09a92caaf73bff7adb70b76162e5937524058a7e5bff37869cbbec293"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"compact_str",
|
||||||
|
"hashbrown",
|
||||||
|
"indoc",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"kasuari",
|
||||||
|
"lru",
|
||||||
|
"strum",
|
||||||
|
"thiserror",
|
||||||
|
"unicode-segmentation",
|
||||||
|
"unicode-truncate",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui-macros"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a7f1342a13e83e4bb9d0b793d0ea762be633f9582048c892ae9041ef39c936f4"
|
||||||
|
dependencies = [
|
||||||
|
"ratatui-core",
|
||||||
|
"ratatui-widgets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui-widgets"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d7dbfa023cd4e604c2553483820c5fe8aa9d71a42eea5aa77c6e7f35756612db"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"hashbrown",
|
||||||
|
"indoc",
|
||||||
|
"instability",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"line-clipping",
|
||||||
|
"ratatui-core",
|
||||||
|
"strum",
|
||||||
|
"time",
|
||||||
|
"unicode-segmentation",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "riscv"
|
name = "riscv"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -1263,7 +1590,7 @@ checksum = "f265be5d634272320a7de94cea15c22a3bfdd4eb42eb43edc528415f066a1f25"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1280,7 +1607,7 @@ checksum = "fc71814687c45ba4cd1e47a54e03a2dbc62ca3667098fbae9cc6b423956758fa"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1296,6 +1623,12 @@ dependencies = [
|
|||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustversion"
|
||||||
|
version = "1.0.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
@@ -1335,7 +1668,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1365,12 +1698,32 @@ dependencies = [
|
|||||||
"managed",
|
"managed",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ssd1306"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ea6aac2d078bbc71d9b8ac3f657335311f3b6625e9a1a96ccc29f5abfa77c56"
|
||||||
|
dependencies = [
|
||||||
|
"display-interface",
|
||||||
|
"display-interface-i2c",
|
||||||
|
"display-interface-spi",
|
||||||
|
"embedded-graphics-core",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"maybe-async-cfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stable_deref_trait"
|
name = "stable_deref_trait"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "static_assertions"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_cell"
|
name = "static_cell"
|
||||||
version = "2.1.1"
|
version = "2.1.1"
|
||||||
@@ -1404,7 +1757,18 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1444,9 +1808,27 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
@@ -1489,12 +1871,41 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicase"
|
||||||
|
version = "2.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.19"
|
version = "1.0.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-segmentation"
|
||||||
|
version = "1.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-truncate"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fbf03860ff438702f3910ca5f28f8dac63c1c11e7efb5012b8b175493606330"
|
||||||
|
dependencies = [
|
||||||
|
"itertools 0.13.0",
|
||||||
|
"unicode-segmentation",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unsafe-libyaml"
|
name = "unsafe-libyaml"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -1581,5 +1992,5 @@ checksum = "c5a56a616147f5947ceb673790dd618d77b30e26e677f4a896df049d73059438"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "projekt_final"
|
name = "projekt_final"
|
||||||
rust-version = "1.86"
|
rust-version = "1.89.0"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "projekt_final"
|
name = "projekt_final"
|
||||||
path = "./src/bin/main.rs"
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
pages-tui = { path = "../../../pages-tui" }
|
||||||
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
esp-hal = { version = "=1.0.0-rc.0", features = [
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
"esp32",
|
"esp32",
|
||||||
@@ -34,7 +35,7 @@ esp-backtrace = { version = "0.17.0", features = [
|
|||||||
"panic-handler",
|
"panic-handler",
|
||||||
"println",
|
"println",
|
||||||
] }
|
] }
|
||||||
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04", "defmt-espflash"] }
|
||||||
# for more networking protocol support see https://crates.io/crates/edge-net
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
critical-section = "1.2.0"
|
critical-section = "1.2.0"
|
||||||
embassy-executor = { version = "0.7.0", features = [
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
@@ -67,10 +68,15 @@ smoltcp = { version = "0.12.0", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
static_cell = "2.1.1"
|
static_cell = "2.1.1"
|
||||||
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
||||||
defmt-rtt = "1.0.0"
|
|
||||||
embassy-futures = "0.1.2"
|
embassy-futures = "0.1.2"
|
||||||
embassy-sync = "0.7.2"
|
embassy-sync = "0.7.2"
|
||||||
heapless = "0.9.1"
|
heapless = "0.9.1"
|
||||||
|
mousefood = { git = "https://github.com/j-g00da/mousefood", branch = "main", default-features = false }
|
||||||
|
ssd1306 = "0.10.0"
|
||||||
|
ratatui = { version = "0.30.0", default-features = false, features = ["macros", "all-widgets", "portable-atomic"] }
|
||||||
|
embedded-hal-bus = "0.3.0"
|
||||||
|
embedded-hal = "1.0.0"
|
||||||
|
defmt = "1.0.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
|
|||||||
181
mqtt_display/old_main.rs
Normal file
181
mqtt_display/old_main.rs
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
// src/bin/main.rs
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![deny(
|
||||||
|
clippy::mem_forget,
|
||||||
|
reason = "mem::forget is generally not safe to do with esp_hal types"
|
||||||
|
)]
|
||||||
|
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::select::{select, Either};
|
||||||
|
use embassy_net::{Runner, StackResources};
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
|
use esp_alloc as _;
|
||||||
|
use esp_backtrace as _;
|
||||||
|
use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup};
|
||||||
|
use esp_wifi::{
|
||||||
|
init,
|
||||||
|
wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState},
|
||||||
|
EspWifiController,
|
||||||
|
};
|
||||||
|
use log::info;
|
||||||
|
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||||
|
use projekt_final::mqtt::client::{
|
||||||
|
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg,
|
||||||
|
};
|
||||||
|
use defmt_rtt as _;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
macro_rules! mk_static {
|
||||||
|
($t:ty,$val:expr) => {{
|
||||||
|
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||||
|
#[deny(unused_attributes)]
|
||||||
|
let x = STATIC_CELL.uninit().write(($val));
|
||||||
|
x
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
const SSID: &str = env!("SSID");
|
||||||
|
const PASSWORD: &str = env!("PASSWORD");
|
||||||
|
|
||||||
|
#[esp_hal_embassy::main]
|
||||||
|
async fn main(spawner: Spawner) -> ! {
|
||||||
|
esp_println::logger::init_logger_from_env();
|
||||||
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||||
|
let peripherals = esp_hal::init(config);
|
||||||
|
|
||||||
|
esp_alloc::heap_allocator!(size: 72 * 1024);
|
||||||
|
|
||||||
|
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
|
let mut rng = Rng::new(peripherals.RNG);
|
||||||
|
|
||||||
|
let esp_wifi_ctrl = &*mk_static!(
|
||||||
|
EspWifiController<'static>,
|
||||||
|
init(timg0.timer0, rng.clone()).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
let (controller, interfaces) =
|
||||||
|
esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap();
|
||||||
|
|
||||||
|
let wifi_interface = interfaces.sta;
|
||||||
|
|
||||||
|
let timg1 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
esp_hal_embassy::init(timg1.timer0);
|
||||||
|
|
||||||
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
|
|
||||||
|
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
||||||
|
|
||||||
|
// Init network stack
|
||||||
|
let (stack, runner) = embassy_net::new(
|
||||||
|
wifi_interface,
|
||||||
|
config,
|
||||||
|
mk_static!(StackResources<3>, StackResources::<3>::new()),
|
||||||
|
seed,
|
||||||
|
);
|
||||||
|
|
||||||
|
spawner.spawn(connection(controller)).ok();
|
||||||
|
spawner.spawn(net_task(runner)).ok();
|
||||||
|
|
||||||
|
// Wait for link up
|
||||||
|
loop {
|
||||||
|
if stack.is_link_up() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Waiting to get IP address...");
|
||||||
|
loop {
|
||||||
|
if let Some(config) = stack.config_v4() {
|
||||||
|
info!("Got IP: {}", config.address);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
||||||
|
info!("MQTT task started");
|
||||||
|
|
||||||
|
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
||||||
|
info!("Sent initial MQTT message");
|
||||||
|
|
||||||
|
mqtt_subscribe("esp32/topic").await;
|
||||||
|
|
||||||
|
// Get a receiver for incoming MQTT messages
|
||||||
|
let mqtt_rx = mqtt_events();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// Drive both: either process an MQTT message or publish periodically
|
||||||
|
match select(mqtt_rx.receive(), Timer::after(Duration::from_secs(5))).await
|
||||||
|
{
|
||||||
|
// Received inbound MQTT message (from broker)
|
||||||
|
Either::First(msg) => {
|
||||||
|
handle_incoming(msg);
|
||||||
|
}
|
||||||
|
// Time-based example publish
|
||||||
|
Either::Second(_) => {
|
||||||
|
// mqtt_publish(
|
||||||
|
// "esp32/topic",
|
||||||
|
// b"hello from main",
|
||||||
|
// QualityOfService::QoS1,
|
||||||
|
// false,
|
||||||
|
// )
|
||||||
|
// .await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_incoming(msg: IncomingMsg) {
|
||||||
|
if let Ok(txt) = core::str::from_utf8(&msg.payload) {
|
||||||
|
info!("MAIN RX [{}]: {}", msg.topic.as_str(), txt);
|
||||||
|
info!("Received MQTT message -> topic: '{}', payload: '{}'", msg.topic.as_str(), txt);
|
||||||
|
} else {
|
||||||
|
info!("MAIN RX [{}]: {:?}", msg.topic.as_str(), msg.payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn connection(mut controller: WifiController<'static>) {
|
||||||
|
info!("start connection task");
|
||||||
|
info!("Device capabilities: {:?}", controller.capabilities());
|
||||||
|
loop {
|
||||||
|
match esp_wifi::wifi::wifi_state() {
|
||||||
|
WifiState::StaConnected => {
|
||||||
|
controller.wait_for_event(WifiEvent::StaDisconnected).await;
|
||||||
|
Timer::after(Duration::from_millis(5000)).await
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if !matches!(controller.is_started(), Ok(true)) {
|
||||||
|
let client_config = Configuration::Client(ClientConfiguration {
|
||||||
|
ssid: SSID.into(),
|
||||||
|
password: PASSWORD.into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
controller.set_configuration(&client_config).unwrap();
|
||||||
|
info!("Starting wifi");
|
||||||
|
controller.start_async().await.unwrap();
|
||||||
|
info!("Wifi started!");
|
||||||
|
}
|
||||||
|
info!("About to connect...");
|
||||||
|
|
||||||
|
match controller.connect_async().await {
|
||||||
|
Ok(_) => info!("Wifi connected!"),
|
||||||
|
Err(e) => {
|
||||||
|
info!("Failed to connect to wifi: {e:?}");
|
||||||
|
Timer::after(Duration::from_millis(5000)).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn net_task(mut runner: Runner<'static, WifiDevice<'static>>) {
|
||||||
|
runner.run().await
|
||||||
|
}
|
||||||
@@ -6,30 +6,54 @@
|
|||||||
clippy::mem_forget,
|
clippy::mem_forget,
|
||||||
reason = "mem::forget is generally not safe to do with esp_hal types"
|
reason = "mem::forget is generally not safe to do with esp_hal types"
|
||||||
)]
|
)]
|
||||||
|
// TODO WARNING core 1 should be logic, core 0 wifi, its flipped now
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_futures::select::{select, Either};
|
use embassy_futures::select::{select, Either, select3, Either3};
|
||||||
use embassy_net::{Runner, StackResources};
|
use embassy_net::{Runner, StackResources};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_sync::signal::Signal;
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_time::{Duration, Timer, Instant};
|
||||||
|
use projekt_final::bus::I2cInner;
|
||||||
|
use projekt_final::mqtt::client::mqtt_set_imu;
|
||||||
|
|
||||||
use esp_alloc as _;
|
use esp_alloc as _;
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup};
|
|
||||||
|
use esp_hal::{
|
||||||
|
gpio::InputConfig,
|
||||||
|
clock::CpuClock,
|
||||||
|
gpio::{Input, Pull},
|
||||||
|
i2c::master::{Config as I2cConfig, I2c},
|
||||||
|
rng::Rng,
|
||||||
|
system::{CpuControl, Stack},
|
||||||
|
timer::timg::TimerGroup,
|
||||||
|
};
|
||||||
use esp_wifi::{
|
use esp_wifi::{
|
||||||
init,
|
|
||||||
wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState},
|
wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState},
|
||||||
EspWifiController,
|
EspWifiController,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use pages_tui::input::Key;
|
||||||
use log::info;
|
use log::info;
|
||||||
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||||
use projekt_final::mqtt::client::{
|
use static_cell::StaticCell;
|
||||||
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg,
|
use core::cell::RefCell;
|
||||||
|
|
||||||
|
use projekt_final::{
|
||||||
|
bus,
|
||||||
|
display,
|
||||||
|
mpu,
|
||||||
|
mqtt::client::{mqtt_events, mqtt_try_publish, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg},
|
||||||
};
|
};
|
||||||
use projekt_final::i2c::com::i2c_check;
|
|
||||||
use defmt_rtt as _;
|
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
use alloc::format;
|
||||||
|
|
||||||
esp_bootloader_esp_idf::esp_app_desc!();
|
static I2C_BUS: StaticCell<RefCell<I2cInner>> = StaticCell::new();
|
||||||
|
static APP_CORE_STACK: StaticCell<Stack<8192>> = StaticCell::new();
|
||||||
|
static EXECUTOR_CORE1: StaticCell<esp_hal_embassy::Executor> = StaticCell::new();
|
||||||
|
static NETWORK_READY: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
||||||
|
|
||||||
macro_rules! mk_static {
|
macro_rules! mk_static {
|
||||||
($t:ty,$val:expr) => {{
|
($t:ty,$val:expr) => {{
|
||||||
@@ -42,55 +66,159 @@ macro_rules! mk_static {
|
|||||||
|
|
||||||
const SSID: &str = env!("SSID");
|
const SSID: &str = env!("SSID");
|
||||||
const PASSWORD: &str = env!("PASSWORD");
|
const PASSWORD: &str = env!("PASSWORD");
|
||||||
|
const MQTT_PUBLISH_DIVIDER: u32 = 10;
|
||||||
|
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
#[esp_hal_embassy::main]
|
#[esp_hal_embassy::main]
|
||||||
async fn main(spawner: Spawner) -> ! {
|
async fn main(spawner: Spawner) -> ! {
|
||||||
esp_println::logger::init_logger_from_env();
|
esp_println::logger::init_logger_from_env();
|
||||||
|
info!("===============================");
|
||||||
|
info!(" ESP32 IoT Firmware Starting");
|
||||||
|
info!("===============================");
|
||||||
|
|
||||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||||
let peripherals = esp_hal::init(config);
|
let peripherals = esp_hal::init(config);
|
||||||
|
|
||||||
esp_alloc::heap_allocator!(size: 72 * 1024);
|
esp_alloc::heap_allocator!(size: 72 * 1024);
|
||||||
|
|
||||||
|
info!("Initializing I2C bus...");
|
||||||
|
let i2c = I2c::new(peripherals.I2C0, I2cConfig::default())
|
||||||
|
.expect("Failed to create I2C instance")
|
||||||
|
.with_sda(peripherals.GPIO21)
|
||||||
|
.with_scl(peripherals.GPIO22)
|
||||||
|
.into_async();
|
||||||
|
|
||||||
|
let i2c_bus = I2C_BUS.init(RefCell::new(i2c));
|
||||||
|
let display_i2c = bus::new_device(i2c_bus);
|
||||||
|
let mpu_i2c = bus::new_device(i2c_bus);
|
||||||
|
|
||||||
|
info!("Initializing WiFi...");
|
||||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
let mut rng = Rng::new(peripherals.RNG);
|
let mut rng = Rng::new(peripherals.RNG);
|
||||||
|
|
||||||
let esp_wifi_ctrl = &*mk_static!(
|
let esp_wifi_ctrl = mk_static!(
|
||||||
EspWifiController<'static>,
|
EspWifiController<'static>,
|
||||||
init(timg0.timer0, rng.clone()).unwrap()
|
esp_wifi::init(timg0.timer0, rng.clone()).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let (controller, interfaces) =
|
let (controller, interfaces) =
|
||||||
esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap();
|
esp_wifi::wifi::new(esp_wifi_ctrl, peripherals.WIFI).unwrap();
|
||||||
|
|
||||||
let wifi_interface = interfaces.sta;
|
let wifi_interface = interfaces.sta;
|
||||||
|
|
||||||
let timg1 = TimerGroup::new(peripherals.TIMG1);
|
let timg1 = TimerGroup::new(peripherals.TIMG1);
|
||||||
esp_hal_embassy::init(timg1.timer0);
|
esp_hal_embassy::init(timg1.timer0);
|
||||||
|
|
||||||
let config = embassy_net::Config::dhcpv4(Default::default());
|
|
||||||
|
|
||||||
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
||||||
|
|
||||||
// Init network stack
|
// Start core 1 for WiFi and MQTT (network stack created there)
|
||||||
|
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
|
||||||
|
let _guard = cpu_control.start_app_core(
|
||||||
|
APP_CORE_STACK.init(Stack::new()),
|
||||||
|
move || {
|
||||||
|
let executor = EXECUTOR_CORE1.init(esp_hal_embassy::Executor::new());
|
||||||
|
executor.run(|spawner| {
|
||||||
|
spawner.spawn(core1_network_task(spawner, controller, wifi_interface, seed)).ok();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
// Wait for network to be ready (signaled from core 1)
|
||||||
|
NETWORK_READY.wait().await;
|
||||||
|
info!("Network ready, starting core 0 tasks");
|
||||||
|
|
||||||
|
let config = InputConfig::default().with_pull(Pull::Down);
|
||||||
|
let button_select = Input::new(peripherals.GPIO32, config);
|
||||||
|
let button_next = Input::new(peripherals.GPIO35, config);
|
||||||
|
spawner.spawn(button_detection_task(button_select, button_next)).unwrap();
|
||||||
|
|
||||||
|
// Core 0: display and MPU tasks
|
||||||
|
spawner.spawn(display::task::display_task(display_i2c)).expect("spawn display_task");
|
||||||
|
spawner.spawn(mpu::task::mpu_task(mpu_i2c)).expect("spawn mpu_task");
|
||||||
|
|
||||||
|
display::api::set_status("Booting...").await;
|
||||||
|
mqtt_subscribe("esp32/read").await;
|
||||||
|
mqtt_publish("esp32/imu", b"online", QualityOfService::QoS1, false).await;
|
||||||
|
|
||||||
|
display::api::set_status("Running").await;
|
||||||
|
display::api::set_mqtt_status(true, 0).await;
|
||||||
|
|
||||||
|
let mqtt_rx = mqtt_events();
|
||||||
|
let imu_rx = mpu::api::events();
|
||||||
|
let mut imu_reading_count: u32 = 0;
|
||||||
|
let mut mqtt_msg_count: u32 = 0;
|
||||||
|
let mut mqtt_publish_drops: u32 = 0;
|
||||||
|
let mut last_mqtt_publish = Instant::now();
|
||||||
|
let mqtt_publish_interval = Duration::from_secs(3);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match select3(
|
||||||
|
mqtt_rx.receive(),
|
||||||
|
imu_rx.receive(),
|
||||||
|
Timer::after(Duration::from_secs(5)),
|
||||||
|
).await {
|
||||||
|
Either3::First(msg) => {
|
||||||
|
mqtt_msg_count += 1;
|
||||||
|
handle_mqtt_message(msg).await;
|
||||||
|
display::api::set_mqtt_status(true, mqtt_msg_count).await;
|
||||||
|
}
|
||||||
|
Either3::Second(mut reading) => {
|
||||||
|
// Drain zabezpečuje, že 'reading' je najčerstvejšia možná hodnota
|
||||||
|
let mut drained = 0;
|
||||||
|
while let Ok(next) = imu_rx.try_receive() {
|
||||||
|
reading = next;
|
||||||
|
drained += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
imu_reading_count += 1;
|
||||||
|
display::api::show_imu(reading);
|
||||||
|
|
||||||
|
// 3. Nahraďte pôvodnú podmienku týmto časovým zámkom
|
||||||
|
if last_mqtt_publish.elapsed() >= mqtt_publish_interval {
|
||||||
|
let payload = format!(
|
||||||
|
"{{\"ax\":{:.2},\"ay\":{:.2},\"az\":{:.2},\"t\":{:.1}}}",
|
||||||
|
reading.accel_g[0], reading.accel_g[1], reading.accel_g[2], reading.temp_c
|
||||||
|
);
|
||||||
|
mqtt_set_imu(payload.as_bytes());
|
||||||
|
|
||||||
|
// Aktualizujeme čas posledného odoslania
|
||||||
|
last_mqtt_publish = Instant::now();
|
||||||
|
log::info!("MQTT IMU payload buffered (freshest data)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Either3::Third(_) => {
|
||||||
|
crate::mpu::api::IMU_CHANNEL.clear();
|
||||||
|
info!("IMU heartbeat: force-cleared queue, {} readings total, {} mqtt drops",
|
||||||
|
imu_reading_count, mqtt_publish_drops);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runs on core 1 - creates and owns the network stack
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn core1_network_task(
|
||||||
|
spawner: Spawner,
|
||||||
|
controller: WifiController<'static>,
|
||||||
|
wifi_interface: WifiDevice<'static>,
|
||||||
|
seed: u64,
|
||||||
|
) {
|
||||||
|
spawner.spawn(connection_task(controller)).ok();
|
||||||
|
|
||||||
|
let net_config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
let (stack, runner) = embassy_net::new(
|
let (stack, runner) = embassy_net::new(
|
||||||
wifi_interface,
|
wifi_interface,
|
||||||
config,
|
net_config,
|
||||||
mk_static!(StackResources<3>, StackResources::<3>::new()),
|
mk_static!(StackResources<3>, StackResources::<3>::new()),
|
||||||
seed,
|
seed,
|
||||||
);
|
);
|
||||||
|
|
||||||
spawner.spawn(connection(controller)).ok();
|
|
||||||
spawner.spawn(net_task(runner)).ok();
|
spawner.spawn(net_task(runner)).ok();
|
||||||
|
|
||||||
// Wait for link up
|
// Wait for network
|
||||||
loop {
|
loop {
|
||||||
if stack.is_link_up() {
|
if stack.is_link_up() { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Waiting to get IP address...");
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(config) = stack.config_v4() {
|
if let Some(config) = stack.config_v4() {
|
||||||
info!("Got IP: {}", config.address);
|
info!("Got IP: {}", config.address);
|
||||||
@@ -99,62 +227,28 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
Timer::after(Duration::from_millis(500)).await;
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
// Signal core 0 that network is ready
|
||||||
info!("MQTT task started");
|
NETWORK_READY.signal(());
|
||||||
|
|
||||||
spawner.spawn(i2c_check()).expect("failed to spawn I2C task");
|
spawner.spawn(mqtt_task(stack)).ok();
|
||||||
info!("I2C scan task started");
|
|
||||||
|
|
||||||
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
|
||||||
info!("Sent initial MQTT message");
|
|
||||||
|
|
||||||
mqtt_subscribe("esp32/topic").await;
|
|
||||||
|
|
||||||
// Get a receiver for incoming MQTT messages
|
|
||||||
let mqtt_rx = mqtt_events();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
// Drive both: either process an MQTT message or publish periodically
|
|
||||||
match select(mqtt_rx.receive(), Timer::after(Duration::from_secs(5))).await
|
|
||||||
{
|
|
||||||
// Received inbound MQTT message (from broker)
|
|
||||||
Either::First(msg) => {
|
|
||||||
handle_incoming(msg);
|
|
||||||
}
|
|
||||||
// Time-based example publish
|
|
||||||
Either::Second(_) => {
|
|
||||||
// mqtt_publish(
|
|
||||||
// "esp32/topic",
|
|
||||||
// b"hello from main",
|
|
||||||
// QualityOfService::QoS1,
|
|
||||||
// false,
|
|
||||||
// )
|
|
||||||
// .await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_incoming(msg: IncomingMsg) {
|
async fn handle_mqtt_message(msg: IncomingMsg) {
|
||||||
if let Ok(txt) = core::str::from_utf8(&msg.payload) {
|
if let Ok(txt) = core::str::from_utf8(&msg.payload) {
|
||||||
info!("MAIN RX [{}]: {}", msg.topic.as_str(), txt);
|
match txt {
|
||||||
info!("Received MQTT message -> topic: '{}', payload: '{}'", msg.topic.as_str(), txt);
|
"clear" => { display::api::clear().await; }
|
||||||
} else {
|
"status" => { mqtt_publish("esp32/status", b"running", QualityOfService::QoS1, false).await; }
|
||||||
info!("MAIN RX [{}]: {:?}", msg.topic.as_str(), msg.payload);
|
_ => { display::api::add_chat_message(txt).await; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn connection(mut controller: WifiController<'static>) {
|
async fn connection_task(mut controller: WifiController<'static>) {
|
||||||
info!("start connection task");
|
|
||||||
info!("Device capabilities: {:?}", controller.capabilities());
|
|
||||||
loop {
|
loop {
|
||||||
match esp_wifi::wifi::wifi_state() {
|
if esp_wifi::wifi::wifi_state() == WifiState::StaConnected {
|
||||||
WifiState::StaConnected => {
|
|
||||||
controller.wait_for_event(WifiEvent::StaDisconnected).await;
|
controller.wait_for_event(WifiEvent::StaDisconnected).await;
|
||||||
Timer::after(Duration::from_millis(5000)).await
|
Timer::after(Duration::from_millis(5000)).await;
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
if !matches!(controller.is_started(), Ok(true)) {
|
if !matches!(controller.is_started(), Ok(true)) {
|
||||||
let client_config = Configuration::Client(ClientConfiguration {
|
let client_config = Configuration::Client(ClientConfiguration {
|
||||||
@@ -163,16 +257,13 @@ async fn connection(mut controller: WifiController<'static>) {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
controller.set_configuration(&client_config).unwrap();
|
controller.set_configuration(&client_config).unwrap();
|
||||||
info!("Starting wifi");
|
info!("Wi-Fi starting...");
|
||||||
controller.start_async().await.unwrap();
|
controller.start_async().await.unwrap();
|
||||||
info!("Wifi started!");
|
|
||||||
}
|
}
|
||||||
info!("About to connect...");
|
|
||||||
|
|
||||||
match controller.connect_async().await {
|
match controller.connect_async().await {
|
||||||
Ok(_) => info!("Wifi connected!"),
|
Ok(_) => info!("Wifi connected!"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("Failed to connect to wifi: {e:?}");
|
info!("Failed to connect to wifi: {e:#?}");
|
||||||
Timer::after(Duration::from_millis(5000)).await
|
Timer::after(Duration::from_millis(5000)).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,3 +274,24 @@ async fn connection(mut controller: WifiController<'static>) {
|
|||||||
async fn net_task(mut runner: Runner<'static, WifiDevice<'static>>) {
|
async fn net_task(mut runner: Runner<'static, WifiDevice<'static>>) {
|
||||||
runner.run().await
|
runner.run().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn button_detection_task(mut select_btn: Input<'static>, mut next_btn: Input<'static>) {
|
||||||
|
loop {
|
||||||
|
match select(
|
||||||
|
select_btn.wait_for_rising_edge(),
|
||||||
|
next_btn.wait_for_rising_edge(),
|
||||||
|
).await {
|
||||||
|
Either::First(_) => {
|
||||||
|
info!("Detection: GPIO 32 (Select) triggered!");
|
||||||
|
display::api::push_key(Key::enter()).await;
|
||||||
|
}
|
||||||
|
Either::Second(_) => {
|
||||||
|
info!("Detection: GPIO 35 (Next) triggered!");
|
||||||
|
display::api::push_key(Key::tab()).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Debounce: prevent mechanical bouncing from double-triggering
|
||||||
|
embassy_time::Timer::after(embassy_time::Duration::from_millis(200)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
20
mqtt_display/src/bus/mod.rs
Normal file
20
mqtt_display/src/bus/mod.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// src/bus/mod.rs
|
||||||
|
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use embedded_hal_bus::i2c::RefCellDevice;
|
||||||
|
use esp_hal::i2c::master::I2c;
|
||||||
|
use esp_hal::Async;
|
||||||
|
|
||||||
|
/// The underlying I2C peripheral type
|
||||||
|
pub type I2cInner = I2c<'static, Async>;
|
||||||
|
|
||||||
|
/// RefCell to share the bus on a single core.
|
||||||
|
pub type SharedI2c = RefCell<I2cInner>;
|
||||||
|
|
||||||
|
/// A handle to a shared I2C device.
|
||||||
|
pub type I2cDevice = RefCellDevice<'static, I2cInner>;
|
||||||
|
|
||||||
|
/// New I2C device handle from the shared bus.
|
||||||
|
pub fn new_device(bus: &'static SharedI2c) -> I2cDevice {
|
||||||
|
RefCellDevice::new(bus)
|
||||||
|
}
|
||||||
36
mqtt_display/src/contracts.rs
Normal file
36
mqtt_display/src/contracts.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// src/contracts.rs
|
||||||
|
//! Cross-feature message contracts.
|
||||||
|
//!
|
||||||
|
//! This is the ONLY coupling point between features.
|
||||||
|
//! Features depend on these types, not on each other.
|
||||||
|
|
||||||
|
use heapless::String as HString;
|
||||||
|
use pages_tui::input::Key;
|
||||||
|
|
||||||
|
/// IMU sensor reading from MPU6050
|
||||||
|
#[derive(Clone, Copy, Default, Debug)]
|
||||||
|
pub struct ImuReading {
|
||||||
|
pub accel_g: [f32; 3],
|
||||||
|
pub gyro_dps: [f32; 3],
|
||||||
|
pub temp_c: f32,
|
||||||
|
/// Timestamp in milliseconds since boot
|
||||||
|
pub timestamp_ms: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Commands that can be sent to the display actor
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum DisplayCommand {
|
||||||
|
/// Show IMU sensor data
|
||||||
|
SetImu(ImuReading),
|
||||||
|
/// Show a status line (max 32 chars)
|
||||||
|
SetStatus(HString<32>),
|
||||||
|
/// Show an error message (max 64 chars)
|
||||||
|
ShowError(HString<64>),
|
||||||
|
/// Show MQTT connection status
|
||||||
|
SetMqttStatus { connected: bool, msg_count: u32 },
|
||||||
|
/// Clear the display to default state
|
||||||
|
Clear,
|
||||||
|
|
||||||
|
PushKey(Key),
|
||||||
|
AddChatMessage(HString<24>),
|
||||||
|
}
|
||||||
66
mqtt_display/src/display/api.rs
Normal file
66
mqtt_display/src/display/api.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// src/display/api.rs
|
||||||
|
//! Public API for the display feature.
|
||||||
|
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::channel::{Channel, Receiver, TrySendError};
|
||||||
|
use heapless::String;
|
||||||
|
|
||||||
|
use crate::contracts::{DisplayCommand, ImuReading};
|
||||||
|
use pages_tui::input::Key;
|
||||||
|
|
||||||
|
const QUEUE_SIZE: usize = 8;
|
||||||
|
|
||||||
|
pub(crate) static DISPLAY_CHANNEL: Channel<CriticalSectionRawMutex, DisplayCommand, QUEUE_SIZE> =
|
||||||
|
Channel::new();
|
||||||
|
|
||||||
|
pub async fn send(cmd: DisplayCommand) {
|
||||||
|
DISPLAY_CHANNEL.send(cmd).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_send(cmd: DisplayCommand) -> Result<(), DisplayCommand> {
|
||||||
|
DISPLAY_CHANNEL.try_send(cmd).map_err(|e| match e {
|
||||||
|
TrySendError::Full(command) => command,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn receiver() -> Receiver<'static, CriticalSectionRawMutex, DisplayCommand, QUEUE_SIZE> {
|
||||||
|
DISPLAY_CHANNEL.receiver()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show IMU data - NON-BLOCKING to prevent backpressure deadlock
|
||||||
|
pub fn show_imu(reading: ImuReading) {
|
||||||
|
// CRITICAL FIX: Use try_send instead of send().await
|
||||||
|
// If display is slow, we drop the reading rather than blocking the main loop
|
||||||
|
let _ = try_send(DisplayCommand::SetImu(reading));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_status(text: &str) {
|
||||||
|
let mut s = String::<32>::new();
|
||||||
|
let _ = s.push_str(&text[..text.len().min(32)]);
|
||||||
|
send(DisplayCommand::SetStatus(s)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn show_error(text: &str) {
|
||||||
|
let mut s = String::<64>::new();
|
||||||
|
let _ = s.push_str(&text[..text.len().min(64)]);
|
||||||
|
send(DisplayCommand::ShowError(s)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_mqtt_status(connected: bool, msg_count: u32) {
|
||||||
|
send(DisplayCommand::SetMqttStatus { connected, msg_count }).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn clear() {
|
||||||
|
send(DisplayCommand::Clear).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn push_key(key: Key) {
|
||||||
|
send(DisplayCommand::PushKey(key)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a chat message (for Chat page)
|
||||||
|
pub async fn add_chat_message(msg: &str) {
|
||||||
|
let mut s = String::<24>::new();
|
||||||
|
let _ = s.push_str(&msg[..msg.len().min(24)]);
|
||||||
|
send(DisplayCommand::AddChatMessage(s)).await;
|
||||||
|
}
|
||||||
6
mqtt_display/src/display/mod.rs
Normal file
6
mqtt_display/src/display/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// src/display/mod.rs
|
||||||
|
//! SSD1306 OLED display
|
||||||
|
|
||||||
|
pub mod api;
|
||||||
|
pub mod task;
|
||||||
|
pub mod tui;
|
||||||
100
mqtt_display/src/display/task.rs
Normal file
100
mqtt_display/src/display/task.rs
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
// src/display/task.rs
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
|
use log::{error, info};
|
||||||
|
|
||||||
|
use alloc::boxed::Box;
|
||||||
|
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
|
||||||
|
use ratatui::Terminal;
|
||||||
|
use ssd1306::{mode::BufferedGraphicsMode, prelude::*, I2CDisplayInterface, Ssd1306};
|
||||||
|
|
||||||
|
use crate::bus::I2cDevice;
|
||||||
|
use crate::display::api::receiver;
|
||||||
|
use crate::display::tui::{render_frame, next_page_id, prev_page_id, DisplayState, Screen, ScreenEvent};
|
||||||
|
use crate::contracts::DisplayCommand;
|
||||||
|
use pages_tui::prelude::*;
|
||||||
|
|
||||||
|
const REFRESH_INTERVAL_MS: u64 = 100;
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn display_task(i2c: I2cDevice) {
|
||||||
|
info!("Display task starting...");
|
||||||
|
|
||||||
|
let interface = I2CDisplayInterface::new(i2c);
|
||||||
|
let mut display = Ssd1306::new(interface, DisplaySize128x32, DisplayRotation::Rotate0)
|
||||||
|
.into_buffered_graphics_mode();
|
||||||
|
|
||||||
|
if let Err(e) = display.init() {
|
||||||
|
error!("Display init failed: {:?}", e);
|
||||||
|
loop { Timer::after(Duration::from_secs(60)).await; }
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = EmbeddedBackendConfig {
|
||||||
|
flush_callback: Box::new(|d: &mut Ssd1306<_, _, BufferedGraphicsMode<DisplaySize128x32>>| {
|
||||||
|
let _ = d.flush();
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let backend = EmbeddedBackend::new(&mut display, config);
|
||||||
|
let mut terminal = Terminal::new(backend).expect("terminal init failed");
|
||||||
|
|
||||||
|
let mut state = DisplayState::default();
|
||||||
|
let mut orchestrator = Orchestrator::<Screen>::new();
|
||||||
|
let rx = receiver();
|
||||||
|
|
||||||
|
// Register pages
|
||||||
|
orchestrator.register_page("menu".into(), Screen::Menu);
|
||||||
|
orchestrator.register_page("imu".into(), Screen::Imu);
|
||||||
|
orchestrator.register_page("chat".into(), Screen::Chat);
|
||||||
|
|
||||||
|
orchestrator.bind(Key::tab(), ComponentAction::Next);
|
||||||
|
orchestrator.bind(Key::enter(), ComponentAction::Select);
|
||||||
|
|
||||||
|
let _ = orchestrator.navigate_to("menu".into());
|
||||||
|
|
||||||
|
info!("Display ready");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
while let Ok(cmd) = rx.try_receive() {
|
||||||
|
match cmd {
|
||||||
|
DisplayCommand::PushKey(key) => {
|
||||||
|
if key == Key::tab() {
|
||||||
|
orchestrator.focus_manager_mut().wrap_next();
|
||||||
|
} else if key == Key::enter() {
|
||||||
|
if let Ok(events) = orchestrator.process_frame(key) {
|
||||||
|
for event in events {
|
||||||
|
match event {
|
||||||
|
ScreenEvent::GoToImu => {
|
||||||
|
let _ = orchestrator.navigate_to("imu".into());
|
||||||
|
}
|
||||||
|
ScreenEvent::GoToChat => {
|
||||||
|
let _ = orchestrator.navigate_to("chat".into());
|
||||||
|
}
|
||||||
|
ScreenEvent::NavigatePrev => {
|
||||||
|
if let Some(cur) = orchestrator.current_id() {
|
||||||
|
let prev = prev_page_id(cur.as_str());
|
||||||
|
let _ = orchestrator.navigate_to(prev.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ScreenEvent::NavigateNext => {
|
||||||
|
if let Some(cur) = orchestrator.current_id() {
|
||||||
|
let next = next_page_id(cur.as_str());
|
||||||
|
let _ = orchestrator.navigate_to(next.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => state.apply_command(cmd),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(screen) = orchestrator.current() {
|
||||||
|
render_frame(&mut terminal, screen, orchestrator.focus_manager().current(), &state);
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::after(Duration::from_millis(REFRESH_INTERVAL_MS)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
263
mqtt_display/src/display/tui.rs
Normal file
263
mqtt_display/src/display/tui.rs
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
// src/display/tui.rs
|
||||||
|
use crate::contracts::{DisplayCommand, ImuReading};
|
||||||
|
use alloc::format;
|
||||||
|
use heapless::String as HString;
|
||||||
|
use pages_tui::prelude::*;
|
||||||
|
use ratatui::{
|
||||||
|
layout::Rect,
|
||||||
|
style::Stylize,
|
||||||
|
widgets::Paragraph,
|
||||||
|
Terminal,
|
||||||
|
};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
/// Focus targets - different per screen
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum PageFocus {
|
||||||
|
MenuImu,
|
||||||
|
MenuChat,
|
||||||
|
NavPrev,
|
||||||
|
NavNext,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FocusId for PageFocus {}
|
||||||
|
|
||||||
|
const MENU_TARGETS: &[PageFocus] = &[PageFocus::MenuImu, PageFocus::MenuChat];
|
||||||
|
const NAV_TARGETS: &[PageFocus] = &[PageFocus::NavPrev, PageFocus::NavNext];
|
||||||
|
|
||||||
|
/// Display state
|
||||||
|
pub struct DisplayState {
|
||||||
|
pub(crate) status: HString<32>,
|
||||||
|
pub(crate) last_imu: Option<ImuReading>,
|
||||||
|
pub(crate) last_error: Option<HString<64>>,
|
||||||
|
pub(crate) mqtt_connected: bool,
|
||||||
|
pub(crate) mqtt_msg_count: u32,
|
||||||
|
pub(crate) chat_msg1: HString<24>,
|
||||||
|
pub(crate) chat_msg2: HString<24>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DisplayState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
status: HString::new(),
|
||||||
|
last_imu: None,
|
||||||
|
last_error: None,
|
||||||
|
mqtt_connected: false,
|
||||||
|
mqtt_msg_count: 0,
|
||||||
|
chat_msg1: HString::new(),
|
||||||
|
chat_msg2: HString::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DisplayState {
|
||||||
|
pub fn apply_command(&mut self, cmd: DisplayCommand) {
|
||||||
|
match cmd {
|
||||||
|
DisplayCommand::SetImu(reading) => {
|
||||||
|
self.last_imu = Some(reading);
|
||||||
|
self.last_error = None;
|
||||||
|
}
|
||||||
|
DisplayCommand::SetStatus(s) => self.status = s,
|
||||||
|
DisplayCommand::ShowError(e) => self.last_error = Some(e),
|
||||||
|
DisplayCommand::SetMqttStatus { connected, msg_count } => {
|
||||||
|
self.mqtt_connected = connected;
|
||||||
|
self.mqtt_msg_count = msg_count;
|
||||||
|
}
|
||||||
|
DisplayCommand::Clear => {
|
||||||
|
self.last_imu = None;
|
||||||
|
self.last_error = None;
|
||||||
|
self.status = HString::new();
|
||||||
|
}
|
||||||
|
DisplayCommand::PushKey(_) => {}
|
||||||
|
DisplayCommand::AddChatMessage(msg) => {
|
||||||
|
self.add_chat_message(msg.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_chat_message(&mut self, msg: &str) {
|
||||||
|
self.chat_msg2 = self.chat_msg1.clone();
|
||||||
|
self.chat_msg1.clear();
|
||||||
|
let _ = self.chat_msg1.push_str(&msg[..msg.len().min(24)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum Screen {
|
||||||
|
Menu,
|
||||||
|
Imu,
|
||||||
|
Chat,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ScreenEvent {
|
||||||
|
GoToImu,
|
||||||
|
GoToChat,
|
||||||
|
NavigatePrev,
|
||||||
|
NavigateNext,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Screen {
|
||||||
|
type Action = ComponentAction;
|
||||||
|
type Event = ScreenEvent;
|
||||||
|
type Focus = PageFocus;
|
||||||
|
|
||||||
|
fn handle(
|
||||||
|
&mut self,
|
||||||
|
focus: &Self::Focus,
|
||||||
|
action: Self::Action,
|
||||||
|
) -> Result<Option<Self::Event>, ComponentError> {
|
||||||
|
if let ComponentAction::Select = action {
|
||||||
|
info!("Select {:?} focus:{:?}", self, focus);
|
||||||
|
return Ok(Some(match focus {
|
||||||
|
PageFocus::MenuImu => ScreenEvent::GoToImu,
|
||||||
|
PageFocus::MenuChat => ScreenEvent::GoToChat,
|
||||||
|
PageFocus::NavPrev => ScreenEvent::NavigatePrev,
|
||||||
|
PageFocus::NavNext => ScreenEvent::NavigateNext,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn targets(&self) -> &[Self::Focus] {
|
||||||
|
match self {
|
||||||
|
Screen::Menu => MENU_TARGETS,
|
||||||
|
Screen::Imu | Screen::Chat => NAV_TARGETS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_enter(&mut self) -> Result<(), ComponentError> {
|
||||||
|
info!("Enter: {:?}", self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_exit(&mut self) -> Result<(), ComponentError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PAGE ORDER
|
||||||
|
const PAGE_ORDER: &[&str] = &["menu", "imu", "chat"];
|
||||||
|
|
||||||
|
pub fn next_page_id(current: &str) -> &'static str {
|
||||||
|
let idx = PAGE_ORDER.iter().position(|&p| p == current).unwrap_or(0);
|
||||||
|
PAGE_ORDER[(idx + 1) % PAGE_ORDER.len()]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prev_page_id(current: &str) -> &'static str {
|
||||||
|
let idx = PAGE_ORDER.iter().position(|&p| p == current).unwrap_or(0);
|
||||||
|
if idx == 0 { PAGE_ORDER[PAGE_ORDER.len() - 1] } else { PAGE_ORDER[idx - 1] }
|
||||||
|
}
|
||||||
|
|
||||||
|
// RENDERING
|
||||||
|
/// Get row rect (0-3) for 128x32 display
|
||||||
|
#[inline]
|
||||||
|
fn row(area: Rect, n: u16) -> Rect {
|
||||||
|
Rect::new(area.x, area.y + n, area.width, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render_frame<B: ratatui::backend::Backend>(
|
||||||
|
terminal: &mut Terminal<B>,
|
||||||
|
current_screen: &Screen,
|
||||||
|
focused: Option<&PageFocus>,
|
||||||
|
state: &DisplayState,
|
||||||
|
) {
|
||||||
|
let _ = terminal.draw(|f| {
|
||||||
|
let area = f.area();
|
||||||
|
|
||||||
|
if let Some(ref err) = state.last_error {
|
||||||
|
f.render_widget(Paragraph::new(format!("ERR:{}", err.as_str())).white().bold(), area);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
match current_screen {
|
||||||
|
Screen::Menu => render_menu(f, area, focused, state),
|
||||||
|
Screen::Imu => render_imu(f, area, focused, state),
|
||||||
|
Screen::Chat => render_chat(f, area, focused, state),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_menu(f: &mut ratatui::Frame, area: Rect, focused: Option<&PageFocus>, state: &DisplayState) {
|
||||||
|
// Row 0 Title
|
||||||
|
let conn = if state.mqtt_connected { "*" } else { "x" };
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(format!("-- ESP32 Hub {} --", conn)).white().bold(),
|
||||||
|
row(area, 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Row 1 Sensors
|
||||||
|
let imu_sel = focused == Some(&PageFocus::MenuImu);
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(if imu_sel { " > Sensors" } else { " Sensors" })
|
||||||
|
.style(if imu_sel { ratatui::style::Style::default().white().bold() } else { ratatui::style::Style::default().white() }),
|
||||||
|
row(area, 1),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Row 2 Messages
|
||||||
|
let chat_sel = focused == Some(&PageFocus::MenuChat);
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(if chat_sel { " > Messages" } else { " Messages" })
|
||||||
|
.style(if chat_sel { ratatui::style::Style::default().white().bold() } else { ratatui::style::Style::default().white() }),
|
||||||
|
row(area, 2),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_imu(f: &mut ratatui::Frame, area: Rect, focused: Option<&PageFocus>, state: &DisplayState) {
|
||||||
|
if let Some(ref imu) = state.last_imu {
|
||||||
|
// Row 0 Gyro
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(format!("G:{:+5.0}{:+5.0}{:+5.0}", imu.gyro_dps[0], imu.gyro_dps[1], imu.gyro_dps[2])).cyan(),
|
||||||
|
row(area, 0),
|
||||||
|
);
|
||||||
|
// Row 1 Accel
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(format!("A:{:+.1} {:+.1} {:+.1}", imu.accel_g[0], imu.accel_g[1], imu.accel_g[2])).green(),
|
||||||
|
row(area, 1),
|
||||||
|
);
|
||||||
|
// Row 2 Temp
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(format!("T: {:.1}C", imu.temp_c)).yellow(),
|
||||||
|
row(area, 2),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
f.render_widget(Paragraph::new("Waiting for MPU...").white(), row(area, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Row 3 Nav bar
|
||||||
|
// render_nav_bar(f, row(area, 3), focused);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_chat(f: &mut ratatui::Frame, area: Rect, focused: Option<&PageFocus>, state: &DisplayState) {
|
||||||
|
// Row 0 Message 1
|
||||||
|
if state.chat_msg1.is_empty() {
|
||||||
|
f.render_widget(Paragraph::new("(no messages)").white(), row(area, 0));
|
||||||
|
} else {
|
||||||
|
f.render_widget(Paragraph::new(format!(">{}", state.chat_msg1.as_str())).green(), row(area, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Row 1 Message 2
|
||||||
|
if !state.chat_msg2.is_empty() {
|
||||||
|
f.render_widget(Paragraph::new(format!(">{}", state.chat_msg2.as_str())).white(), row(area, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Row 3 Nav bar
|
||||||
|
render_nav_bar(f, row(area, 2), focused);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Nav bar: --[<]-------[>]--
|
||||||
|
fn render_nav_bar(f: &mut ratatui::Frame, area: Rect, focused: Option<&PageFocus>) {
|
||||||
|
let prev_sel = focused == Some(&PageFocus::NavPrev);
|
||||||
|
let next_sel = focused == Some(&PageFocus::NavNext);
|
||||||
|
|
||||||
|
let prev = if prev_sel { "[<]" } else { " < " };
|
||||||
|
let next = if next_sel { "[>]" } else { " > " };
|
||||||
|
|
||||||
|
// Build the line: --[<]-------[>]--
|
||||||
|
let line = format!("--{}-------{}--", prev, next);
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(line).style(ratatui::style::Style::default().white()),
|
||||||
|
area,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,37 +1,93 @@
|
|||||||
// src/i2c/com.rs
|
// src/i2c/com.rs
|
||||||
|
|
||||||
use embassy_executor::task;
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
gpio::Io,
|
|
||||||
i2c::master::{Config, I2c},
|
i2c::master::{Config, I2c},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
};
|
};
|
||||||
use esp_println::println;
|
use ssd1306::mode::BufferedGraphicsMode;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn display_task() {
|
||||||
|
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Constraint, Direction, Layout},
|
||||||
|
widgets::{Block, Borders, Paragraph},
|
||||||
|
Terminal,
|
||||||
|
};
|
||||||
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||||
|
|
||||||
#[task]
|
|
||||||
pub async fn i2c_check() {
|
|
||||||
let peripherals = unsafe { Peripherals::steal() };
|
let peripherals = unsafe { Peripherals::steal() };
|
||||||
let _io = Io::new(peripherals.IO_MUX);
|
|
||||||
|
|
||||||
let sda = peripherals.GPIO21;
|
let i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||||
let scl = peripherals.GPIO22;
|
|
||||||
|
|
||||||
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
|
||||||
.expect("Failed to initialize I2C")
|
.expect("Failed to initialize I2C")
|
||||||
.with_sda(sda)
|
.with_sda(peripherals.GPIO21)
|
||||||
.with_scl(scl);
|
.with_scl(peripherals.GPIO22);
|
||||||
|
|
||||||
|
let interface = I2CDisplayInterface::new(i2c);
|
||||||
|
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
||||||
|
.into_buffered_graphics_mode();
|
||||||
|
|
||||||
|
display.init().unwrap();
|
||||||
|
|
||||||
|
let config = EmbeddedBackendConfig {
|
||||||
|
flush_callback: alloc::boxed::Box::new(|display| {
|
||||||
|
let d: &mut Ssd1306<_, _, BufferedGraphicsMode<DisplaySize128x64>> = display;
|
||||||
|
d.flush().unwrap();
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let backend = EmbeddedBackend::new(&mut display, config);
|
||||||
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
|
||||||
|
let mut counter = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("I2C bus scan start");
|
terminal
|
||||||
// Skenujeme adresy 0x03 až 0x77
|
.draw(|f| {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([Constraint::Length(3), Constraint::Min(0)])
|
||||||
|
.split(f.area());
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Block::default().title(" ESP32 Status ").borders(Borders::ALL),
|
||||||
|
chunks[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
let content = alloc::format!("MQTT Active\nCounter: {}", counter);
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(content).block(
|
||||||
|
Block::default().borders(Borders::LEFT | Borders::RIGHT | Borders::BOTTOM),
|
||||||
|
),
|
||||||
|
chunks[1],
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
counter += 1;
|
||||||
|
Timer::after(Duration::from_millis(1000)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn i2c_check() {
|
||||||
|
let peripherals = unsafe { Peripherals::steal() };
|
||||||
|
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||||
|
.expect("Failed to initialize I2C")
|
||||||
|
.with_sda(peripherals.GPIO21)
|
||||||
|
.with_scl(peripherals.GPIO22);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
info!("hehe");
|
||||||
|
esp_println::println!("I2C bus scan start");
|
||||||
for addr in 0x03..0x78 {
|
for addr in 0x03..0x78 {
|
||||||
// Skúsime zapísať prázdne dáta na adresu
|
|
||||||
if i2c.write(addr, &[]).is_ok() {
|
if i2c.write(addr, &[]).is_ok() {
|
||||||
println!("Device found at address 0x{:02X}", addr);
|
esp_println::println!("Device found at address 0x{:02X}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Scan finished");
|
|
||||||
Timer::after(Duration::from_secs(5)).await;
|
Timer::after(Duration::from_secs(5)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
pub mod mqtt;
|
pub mod mqtt;
|
||||||
pub mod i2c;
|
pub mod bus;
|
||||||
|
pub mod contracts;
|
||||||
|
pub mod display;
|
||||||
|
pub mod mpu;
|
||||||
|
|||||||
17
mqtt_display/src/mpu/api.rs
Normal file
17
mqtt_display/src/mpu/api.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// src/mpu/api.rs
|
||||||
|
//! Public API for the MPU6050 feature.
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::channel::{Channel, Receiver, Sender};
|
||||||
|
use crate::contracts::ImuReading;
|
||||||
|
|
||||||
|
const QUEUE_SIZE: usize = 16;
|
||||||
|
|
||||||
|
pub static IMU_CHANNEL: Channel<CriticalSectionRawMutex, ImuReading, QUEUE_SIZE> = Channel::new();
|
||||||
|
|
||||||
|
pub fn events() -> Receiver<'static, CriticalSectionRawMutex, ImuReading, QUEUE_SIZE> {
|
||||||
|
IMU_CHANNEL.receiver()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn sender() -> Sender<'static, CriticalSectionRawMutex, ImuReading, QUEUE_SIZE> {
|
||||||
|
IMU_CHANNEL.sender()
|
||||||
|
}
|
||||||
241
mqtt_display/src/mpu/driver.rs
Normal file
241
mqtt_display/src/mpu/driver.rs
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
// src/mpu/driver.rs
|
||||||
|
//! MPU6050 driver using raw register I/O.
|
||||||
|
|
||||||
|
use embedded_hal::i2c::I2c;
|
||||||
|
|
||||||
|
/// MPU6050 register addresses
|
||||||
|
mod reg {
|
||||||
|
pub const PWR_MGMT_1: u8 = 0x6B;
|
||||||
|
pub const CONFIG: u8 = 0x1A;
|
||||||
|
pub const GYRO_CONFIG: u8 = 0x1B;
|
||||||
|
pub const ACCEL_CONFIG: u8 = 0x1C;
|
||||||
|
pub const ACCEL_XOUT_H: u8 = 0x3B; // Start of 14-byte burst read
|
||||||
|
pub const WHO_AM_I: u8 = 0x75;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Expected WHO_AM_I value for MPU6050
|
||||||
|
const MPU6050_WHO_AM_I: u8 = 0x68;
|
||||||
|
|
||||||
|
/// MPU6050 accelerometer full-scale range
|
||||||
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
|
pub enum AccelRange {
|
||||||
|
#[default]
|
||||||
|
G2 = 0, // ±2g -> 16384 LSB/g
|
||||||
|
G4 = 1, // ±4g -> 8192 LSB/g
|
||||||
|
G8 = 2, // ±8g -> 4096 LSB/g
|
||||||
|
G16 = 3, // ±16g -> 2048 LSB/g
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccelRange {
|
||||||
|
/// LSB per g for this range
|
||||||
|
pub fn sensitivity(self) -> f32 {
|
||||||
|
match self {
|
||||||
|
AccelRange::G2 => 16384.0,
|
||||||
|
AccelRange::G4 => 8192.0,
|
||||||
|
AccelRange::G8 => 4096.0,
|
||||||
|
AccelRange::G16 => 2048.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// MPU6050 gyroscope full-scale range
|
||||||
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
|
pub enum GyroRange {
|
||||||
|
#[default]
|
||||||
|
Dps250 = 0, // ±250°/s -> 131 LSB/°/s
|
||||||
|
Dps500 = 1, // ±500°/s -> 65.5 LSB/°/s
|
||||||
|
Dps1000 = 2, // ±1000°/s -> 32.8 LSB/°/s
|
||||||
|
Dps2000 = 3, // ±2000°/s -> 16.4 LSB/°/s
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GyroRange {
|
||||||
|
/// LSB per degree/second for this range
|
||||||
|
pub fn sensitivity(self) -> f32 {
|
||||||
|
match self {
|
||||||
|
GyroRange::Dps250 => 131.0,
|
||||||
|
GyroRange::Dps500 => 65.5,
|
||||||
|
GyroRange::Dps1000 => 32.8,
|
||||||
|
GyroRange::Dps2000 => 16.4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raw sensor data from a single read
|
||||||
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
|
pub struct RawReading {
|
||||||
|
pub accel: [i16; 3], // X, Y, Z
|
||||||
|
pub gyro: [i16; 3], // X, Y, Z
|
||||||
|
pub temp: i16,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// MPU6050 driver
|
||||||
|
pub struct Mpu6050<I> {
|
||||||
|
i2c: I,
|
||||||
|
addr: u8,
|
||||||
|
accel_range: AccelRange,
|
||||||
|
gyro_range: GyroRange,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Mpu6050<I> {
|
||||||
|
/// Create a new MPU6050 driver.
|
||||||
|
///
|
||||||
|
/// Default I2C address is 0x68. Use 0x69 if AD0 pin is high.
|
||||||
|
pub fn new(i2c: I, addr: u8) -> Self {
|
||||||
|
Self {
|
||||||
|
i2c,
|
||||||
|
addr,
|
||||||
|
accel_range: AccelRange::default(),
|
||||||
|
gyro_range: GyroRange::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create with default address 0x68
|
||||||
|
pub fn new_default(i2c: I) -> Self {
|
||||||
|
Self::new(i2c, 0x68)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Release the I2C peripheral
|
||||||
|
pub fn release(self) -> I {
|
||||||
|
self.i2c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get current accelerometer range
|
||||||
|
pub fn accel_range(&self) -> AccelRange {
|
||||||
|
self.accel_range
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get current gyroscope range
|
||||||
|
pub fn gyro_range(&self) -> GyroRange {
|
||||||
|
self.gyro_range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I, E> Mpu6050<I>
|
||||||
|
where
|
||||||
|
I: I2c<Error = E>,
|
||||||
|
{
|
||||||
|
/// Initialize the sensor with default configuration.
|
||||||
|
///
|
||||||
|
/// - Wakes up the device (exits sleep mode)
|
||||||
|
/// - Sets DLPF to ~44Hz bandwidth
|
||||||
|
/// - Sets accel range to ±2g
|
||||||
|
/// - Sets gyro range to ±250°/s
|
||||||
|
///
|
||||||
|
/// Call this once after creating the driver.
|
||||||
|
/// Consider adding a ~50ms delay after init before first read.
|
||||||
|
pub fn init(&mut self) -> Result<(), E> {
|
||||||
|
// Wake up (clear sleep bit in PWR_MGMT_1)
|
||||||
|
self.write_reg(reg::PWR_MGMT_1, 0x00)?;
|
||||||
|
|
||||||
|
// Set DLPF (Digital Low Pass Filter) to ~44Hz
|
||||||
|
// CONFIG register, bits 2:0 = DLPF_CFG
|
||||||
|
self.write_reg(reg::CONFIG, 0x03)?;
|
||||||
|
|
||||||
|
// Set accelerometer range (default ±2g)
|
||||||
|
self.write_reg(reg::ACCEL_CONFIG, (self.accel_range as u8) << 3)?;
|
||||||
|
|
||||||
|
// Set gyroscope range (default ±250°/s)
|
||||||
|
self.write_reg(reg::GYRO_CONFIG, (self.gyro_range as u8) << 3)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify the device is responding and is an MPU6050.
|
||||||
|
///
|
||||||
|
/// Returns true if WHO_AM_I register returns expected value.
|
||||||
|
pub fn verify(&mut self) -> Result<bool, E> {
|
||||||
|
let who = self.read_reg(reg::WHO_AM_I)?;
|
||||||
|
Ok(who == MPU6050_WHO_AM_I)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set accelerometer full-scale range.
|
||||||
|
///
|
||||||
|
/// Takes effect immediately.
|
||||||
|
pub fn set_accel_range(&mut self, range: AccelRange) -> Result<(), E> {
|
||||||
|
self.accel_range = range;
|
||||||
|
self.write_reg(reg::ACCEL_CONFIG, (range as u8) << 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set gyroscope full-scale range.
|
||||||
|
///
|
||||||
|
/// Takes effect immediately.
|
||||||
|
pub fn set_gyro_range(&mut self, range: GyroRange) -> Result<(), E> {
|
||||||
|
self.gyro_range = range;
|
||||||
|
self.write_reg(reg::GYRO_CONFIG, (range as u8) << 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read all sensor data in a single burst.
|
||||||
|
///
|
||||||
|
/// This reads 14 bytes starting at ACCEL_XOUT_H:
|
||||||
|
/// - Accelerometer X, Y, Z (6 bytes)
|
||||||
|
/// - Temperature (2 bytes)
|
||||||
|
/// - Gyroscope X, Y, Z (6 bytes)
|
||||||
|
///
|
||||||
|
/// Returns raw values; use `convert_reading` for physical units.
|
||||||
|
pub fn read_raw(&mut self) -> Result<RawReading, E> {
|
||||||
|
let mut buf = [0u8; 14];
|
||||||
|
self.i2c.write_read(self.addr, &[reg::ACCEL_XOUT_H], &mut buf)?;
|
||||||
|
|
||||||
|
Ok(RawReading {
|
||||||
|
accel: [
|
||||||
|
i16::from_be_bytes([buf[0], buf[1]]),
|
||||||
|
i16::from_be_bytes([buf[2], buf[3]]),
|
||||||
|
i16::from_be_bytes([buf[4], buf[5]]),
|
||||||
|
],
|
||||||
|
temp: i16::from_be_bytes([buf[6], buf[7]]),
|
||||||
|
gyro: [
|
||||||
|
i16::from_be_bytes([buf[8], buf[9]]),
|
||||||
|
i16::from_be_bytes([buf[10], buf[11]]),
|
||||||
|
i16::from_be_bytes([buf[12], buf[13]]),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert raw reading to physical units.
|
||||||
|
///
|
||||||
|
/// Returns (accel_g, gyro_dps, temp_c)
|
||||||
|
pub fn convert_reading(&self, raw: &RawReading) -> ([f32; 3], [f32; 3], f32) {
|
||||||
|
let accel_sens = self.accel_range.sensitivity();
|
||||||
|
let gyro_sens = self.gyro_range.sensitivity();
|
||||||
|
|
||||||
|
let accel_g = [
|
||||||
|
raw.accel[0] as f32 / accel_sens,
|
||||||
|
raw.accel[1] as f32 / accel_sens,
|
||||||
|
raw.accel[2] as f32 / accel_sens,
|
||||||
|
];
|
||||||
|
|
||||||
|
let gyro_dps = [
|
||||||
|
raw.gyro[0] as f32 / gyro_sens,
|
||||||
|
raw.gyro[1] as f32 / gyro_sens,
|
||||||
|
raw.gyro[2] as f32 / gyro_sens,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Temperature formula from datasheet:
|
||||||
|
// Temp in °C = (TEMP_OUT / 340.0) + 36.53
|
||||||
|
let temp_c = (raw.temp as f32 / 340.0) + 36.53;
|
||||||
|
|
||||||
|
(accel_g, gyro_dps, temp_c)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read and convert in one call.
|
||||||
|
///
|
||||||
|
/// Convenience method that combines `read_raw` and `convert_reading`.
|
||||||
|
pub fn read(&mut self) -> Result<([f32; 3], [f32; 3], f32), E> {
|
||||||
|
let raw = self.read_raw()?;
|
||||||
|
Ok(self.convert_reading(&raw))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────────
|
||||||
|
// Low-level register access
|
||||||
|
// ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
fn write_reg(&mut self, reg: u8, val: u8) -> Result<(), E> {
|
||||||
|
self.i2c.write(self.addr, &[reg, val])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_reg(&mut self, reg: u8) -> Result<u8, E> {
|
||||||
|
let mut buf = [0u8];
|
||||||
|
self.i2c.write_read(self.addr, &[reg], &mut buf)?;
|
||||||
|
Ok(buf[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
6
mqtt_display/src/mpu/mod.rs
Normal file
6
mqtt_display/src/mpu/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// src/mpu/mod.rs
|
||||||
|
//! MPU6050 accelerometer/gyroscope
|
||||||
|
|
||||||
|
pub mod api;
|
||||||
|
pub mod driver;
|
||||||
|
pub mod task;
|
||||||
142
mqtt_display/src/mpu/task.rs
Normal file
142
mqtt_display/src/mpu/task.rs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
// src/mpu/task.rs
|
||||||
|
//! MPU6050 sampling task.
|
||||||
|
//!
|
||||||
|
//! This task:
|
||||||
|
//! 1. Initializes the MPU6050 sensor
|
||||||
|
//! 2. Continuously reads sensor data at a fixed rate
|
||||||
|
//! 3. Publishes readings to the IMU channel
|
||||||
|
|
||||||
|
use embassy_time::{Duration, Instant, Timer};
|
||||||
|
use log::{error, info, warn};
|
||||||
|
|
||||||
|
use crate::bus::I2cDevice;
|
||||||
|
use crate::contracts::ImuReading;
|
||||||
|
use crate::mpu::api::sender;
|
||||||
|
use crate::mpu::driver::Mpu6050;
|
||||||
|
|
||||||
|
/// Sampling interval in milliseconds.
|
||||||
|
/// 50ms = 20Hz
|
||||||
|
const SAMPLE_INTERVAL_MS: u64 = 50;
|
||||||
|
|
||||||
|
/// MPU6050 I2C address (0x68 with AD0 low, 0x69 with AD0 high)
|
||||||
|
const MPU_ADDR: u8 = 0x68;
|
||||||
|
|
||||||
|
/// The MPU6050 sampling task.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `i2c` - An I2C device handle from the shared bus
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// Does not panic; logs errors and retries on failure.
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn mpu_task(i2c: I2cDevice) {
|
||||||
|
info!("MPU task starting...");
|
||||||
|
|
||||||
|
let mut mpu = Mpu6050::new(i2c, MPU_ADDR);
|
||||||
|
|
||||||
|
// Initialize with retries
|
||||||
|
let mut init_attempts = 0;
|
||||||
|
loop {
|
||||||
|
init_attempts += 1;
|
||||||
|
|
||||||
|
// Verify device is present
|
||||||
|
match mpu.verify() {
|
||||||
|
Ok(true) => {
|
||||||
|
info!("MPU6050 detected at 0x{:02X}", MPU_ADDR);
|
||||||
|
}
|
||||||
|
Ok(false) => {
|
||||||
|
warn!(
|
||||||
|
"Device at 0x{:02X} is not MPU6050 (attempt {})",
|
||||||
|
MPU_ADDR, init_attempts
|
||||||
|
);
|
||||||
|
Timer::after(Duration::from_secs(2)).await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
warn!(
|
||||||
|
"I2C error verifying MPU6050 (attempt {})",
|
||||||
|
init_attempts
|
||||||
|
);
|
||||||
|
Timer::after(Duration::from_secs(2)).await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize sensor
|
||||||
|
match mpu.init() {
|
||||||
|
Ok(()) => {
|
||||||
|
info!("MPU6050 initialized successfully");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
error!("MPU6050 init failed (attempt {})", init_attempts);
|
||||||
|
Timer::after(Duration::from_secs(2)).await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow sensor to stabilize after wake-up
|
||||||
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
|
info!(
|
||||||
|
"MPU task entering sampling loop ({}ms interval)",
|
||||||
|
SAMPLE_INTERVAL_MS
|
||||||
|
);
|
||||||
|
|
||||||
|
let tx = sender();
|
||||||
|
let mut consecutive_errors = 0u32;
|
||||||
|
let mut sent_count: u32 = 0;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
|
match mpu.read() {
|
||||||
|
Ok((accel_g, gyro_dps, temp_c)) => {
|
||||||
|
consecutive_errors = 0;
|
||||||
|
|
||||||
|
let reading = ImuReading {
|
||||||
|
accel_g,
|
||||||
|
gyro_dps,
|
||||||
|
temp_c,
|
||||||
|
timestamp_ms: start.as_millis(),
|
||||||
|
};
|
||||||
|
|
||||||
|
sent_count = sent_count.wrapping_add(1);
|
||||||
|
if tx.try_send(reading).is_ok() {
|
||||||
|
if sent_count % 20 == 0 {
|
||||||
|
info!(
|
||||||
|
"IMU send#{} ax:{:.2} ay:{:.2} az:{:.2} t:{:.1}",
|
||||||
|
sent_count, accel_g[0], accel_g[1], accel_g[2], temp_c
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if sent_count % 20 == 0 {
|
||||||
|
info!("IMU drop: channel full ({} sent)", sent_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(_) => {
|
||||||
|
consecutive_errors += 1;
|
||||||
|
if consecutive_errors == 1 || consecutive_errors % 10 == 0 {
|
||||||
|
warn!("MPU read error (consecutive: {})", consecutive_errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If too many errors, try to reinitialize
|
||||||
|
if consecutive_errors >= 50 {
|
||||||
|
error!("Too many MPU errors, attempting reinit...");
|
||||||
|
if mpu.init().is_ok() {
|
||||||
|
info!("MPU reinit successful");
|
||||||
|
consecutive_errors = 0;
|
||||||
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maintain a steady period
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let target = Duration::from_millis(SAMPLE_INTERVAL_MS);
|
||||||
|
if elapsed < target {
|
||||||
|
Timer::after(target - elapsed).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,29 @@
|
|||||||
// src/mqtt/client.rs
|
// src/mqtt/client.rs
|
||||||
|
|
||||||
use embassy_futures::select::{select, Either};
|
use embassy_futures::select::{select, Either};
|
||||||
use embassy_net::{tcp::TcpSocket, Stack};
|
use embassy_net::{tcp::TcpSocket, Stack};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer, with_timeout, Instant};
|
||||||
use log::info;
|
|
||||||
use rust_mqtt::client::client::MqttClient;
|
use rust_mqtt::client::client::MqttClient;
|
||||||
use rust_mqtt::client::client_config::{ClientConfig, MqttVersion};
|
use rust_mqtt::client::client_config::{ClientConfig, MqttVersion};
|
||||||
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||||
use rust_mqtt::packet::v5::reason_codes::ReasonCode;
|
use rust_mqtt::packet::v5::reason_codes::ReasonCode;
|
||||||
use rust_mqtt::utils::rng_generator::CountingRng;
|
use rust_mqtt::utils::rng_generator::CountingRng;
|
||||||
use static_cell::ConstStaticCell;
|
|
||||||
|
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::mutex::Mutex;
|
||||||
use embassy_sync::channel::{Channel, Receiver};
|
use embassy_sync::channel::{Channel, Receiver};
|
||||||
|
use heapless::{String, Vec};
|
||||||
use heapless::{String as HString, Vec as HVec};
|
use static_cell::ConstStaticCell;
|
||||||
|
use log::{info, warn};
|
||||||
|
|
||||||
use crate::mqtt::config::mqtt_broker_endpoint;
|
use crate::mqtt::config::mqtt_broker_endpoint;
|
||||||
|
|
||||||
const RECONNECT_DELAY_SECS: u64 = 5;
|
const RECONNECT_DELAY_SECS: u64 = 5;
|
||||||
const KEEPALIVE_SECS: u64 = 60;
|
const KEEPALIVE_SECS: u64 = 60;
|
||||||
const PING_PERIOD: Duration = Duration::from_secs(KEEPALIVE_SECS / 2);
|
const PING_PERIOD: Duration = Duration::from_secs(KEEPALIVE_SECS / 2);
|
||||||
|
const PING_TIMEOUT: Duration = Duration::from_secs(2);
|
||||||
|
|
||||||
// Limits for small, static buffers (no heap)
|
// Limits for static buffers
|
||||||
pub const TOPIC_MAX: usize = 128;
|
pub const TOPIC_MAX: usize = 128;
|
||||||
pub const PAYLOAD_MAX: usize = 512;
|
pub const PAYLOAD_MAX: usize = 512;
|
||||||
const COMMAND_QUEUE: usize = 8;
|
const COMMAND_QUEUE: usize = 8;
|
||||||
@@ -31,7 +33,7 @@ const EVENT_QUEUE: usize = 8;
|
|||||||
static TCP_RX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
static TCP_RX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
||||||
static TCP_TX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
static TCP_TX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
||||||
|
|
||||||
// MQTT client buffers (separate from the TcpSocket's buffers)
|
// MQTT client buffers (separate from the TcpSocket buffers)
|
||||||
static MQTT_TX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
static MQTT_TX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||||
static MQTT_RX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
static MQTT_RX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||||
|
|
||||||
@@ -40,14 +42,14 @@ type Client<'a, 'net> = MqttClient<'a, TcpSocket<'net>, 8, CountingRng>;
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct IncomingMsg {
|
pub struct IncomingMsg {
|
||||||
pub topic: HString<TOPIC_MAX>,
|
pub topic: String<TOPIC_MAX>,
|
||||||
pub payload: HVec<u8, PAYLOAD_MAX>,
|
pub payload: Vec<u8, PAYLOAD_MAX>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct PublishMsg {
|
struct PublishMsg {
|
||||||
topic: HString<TOPIC_MAX>,
|
topic: String<TOPIC_MAX>,
|
||||||
payload: HVec<u8, PAYLOAD_MAX>,
|
payload: Vec<u8, PAYLOAD_MAX>,
|
||||||
qos: QualityOfService,
|
qos: QualityOfService,
|
||||||
retain: bool,
|
retain: bool,
|
||||||
}
|
}
|
||||||
@@ -55,13 +57,20 @@ struct PublishMsg {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum Command {
|
enum Command {
|
||||||
Publish(PublishMsg),
|
Publish(PublishMsg),
|
||||||
Subscribe(HString<TOPIC_MAX>),
|
Subscribe(String<TOPIC_MAX>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Command/info channels
|
||||||
static CMD_CHAN: Channel<CriticalSectionRawMutex, Command, COMMAND_QUEUE> = Channel::new();
|
static CMD_CHAN: Channel<CriticalSectionRawMutex, Command, COMMAND_QUEUE> = Channel::new();
|
||||||
static EVT_CHAN: Channel<CriticalSectionRawMutex, IncomingMsg, EVENT_QUEUE> = Channel::new();
|
static EVT_CHAN: Channel<CriticalSectionRawMutex, IncomingMsg, EVENT_QUEUE> = Channel::new();
|
||||||
|
|
||||||
// Public API
|
/// Shared latest IMU payload (non-blocking, latest-value semantics)
|
||||||
|
static IMU_LATEST: Mutex<CriticalSectionRawMutex, Option<Vec<u8, PAYLOAD_MAX>>> =
|
||||||
|
Mutex::new(None);
|
||||||
|
|
||||||
|
/// Public API
|
||||||
|
|
||||||
|
/// Blocking publish for command/response messages.
|
||||||
pub async fn mqtt_publish(topic: &str, payload: &[u8], qos: QualityOfService, retain: bool) {
|
pub async fn mqtt_publish(topic: &str, payload: &[u8], qos: QualityOfService, retain: bool) {
|
||||||
CMD_CHAN
|
CMD_CHAN
|
||||||
.send(Command::Publish(PublishMsg {
|
.send(Command::Publish(PublishMsg {
|
||||||
@@ -73,8 +82,31 @@ pub async fn mqtt_publish(topic: &str, payload: &[u8], qos: QualityOfService, re
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Non-blocking publish for other traffic (fire-and-forget)
|
||||||
|
pub fn mqtt_try_publish(topic: &str, payload: &[u8], qos: QualityOfService, retain: bool) -> bool {
|
||||||
|
CMD_CHAN
|
||||||
|
.try_send(Command::Publish(PublishMsg {
|
||||||
|
topic: truncate_str::<TOPIC_MAX>(topic),
|
||||||
|
payload: truncate_payload(payload),
|
||||||
|
qos,
|
||||||
|
retain,
|
||||||
|
}))
|
||||||
|
.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set latest IMU telemetry payload (non-blocking, overwrites previous)
|
||||||
|
pub fn mqtt_set_imu(payload: &[u8]) {
|
||||||
|
if let Ok(mut guard) = IMU_LATEST.try_lock() {
|
||||||
|
let mut buf: Vec<u8, PAYLOAD_MAX> = Vec::new();
|
||||||
|
let _ = buf.extend_from_slice(&payload[..payload.len().min(PAYLOAD_MAX)]);
|
||||||
|
*guard = Some(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn mqtt_subscribe(topic: &str) {
|
pub async fn mqtt_subscribe(topic: &str) {
|
||||||
CMD_CHAN.send(Command::Subscribe(truncate_str::<TOPIC_MAX>(topic))).await;
|
CMD_CHAN
|
||||||
|
.send(Command::Subscribe(truncate_str::<TOPIC_MAX>(topic)))
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mqtt_events(
|
pub fn mqtt_events(
|
||||||
@@ -82,101 +114,82 @@ pub fn mqtt_events(
|
|||||||
EVT_CHAN.receiver()
|
EVT_CHAN.receiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions for memory-safe truncation
|
/// Internals
|
||||||
fn truncate_str<const N: usize>(s: &str) -> HString<N> {
|
|
||||||
let mut h = HString::new();
|
fn truncate_str<const N: usize>(s: &str) -> String<N> {
|
||||||
let _ = h.push_str(&s[..s.len().min(N)]);
|
let mut h = String::new();
|
||||||
|
if N == 0 {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
if s.len() <= N {
|
||||||
|
let _ = h.push_str(s);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cut on a UTF-8 char boundary to avoid panics.
|
||||||
|
let mut cut = N;
|
||||||
|
while cut > 0 && !s.is_char_boundary(cut) {
|
||||||
|
cut -= 1;
|
||||||
|
}
|
||||||
|
let _ = h.push_str(&s[..cut]);
|
||||||
h
|
h
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate_payload(data: &[u8]) -> HVec<u8, PAYLOAD_MAX> {
|
fn truncate_payload(data: &[u8]) -> Vec<u8, PAYLOAD_MAX> {
|
||||||
let mut v = HVec::new();
|
let mut v = Vec::new();
|
||||||
let _ = v.extend_from_slice(&data[..data.len().min(PAYLOAD_MAX)]);
|
let _ = v.extend_from_slice(&data[..data.len().min(PAYLOAD_MAX)]);
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
// MQTT configuration and client setup
|
|
||||||
fn build_client_config() -> ClientConfig<'static, 8, CountingRng> {
|
|
||||||
let mut cfg = ClientConfig::new(MqttVersion::MQTTv5, CountingRng(0));
|
|
||||||
cfg.keep_alive = KEEPALIVE_SECS as u16;
|
|
||||||
cfg.add_client_id("esp32-client");
|
|
||||||
cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_client<'a, 'net>(
|
|
||||||
socket: TcpSocket<'net>,
|
|
||||||
mqtt_tx: &'a mut [u8],
|
|
||||||
mqtt_rx: &'a mut [u8],
|
|
||||||
) -> Client<'a, 'net> {
|
|
||||||
let mqtt_tx_len = mqtt_tx.len();
|
|
||||||
let mqtt_rx_len = mqtt_rx.len();
|
|
||||||
MqttClient::new(socket, mqtt_tx, mqtt_tx_len, mqtt_rx, mqtt_rx_len, build_client_config())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connection lifecycle and main session loop
|
|
||||||
|
|
||||||
async fn connect_tcp<'net>(socket: &mut TcpSocket<'net>) -> Result<(), ()> {
|
|
||||||
match socket.connect(mqtt_broker_endpoint()).await {
|
|
||||||
Ok(_) => {
|
|
||||||
info!("Connected TCP to MQTT broker");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
info!("TCP connect failed: {:?}", e);
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn connect_mqtt(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
|
||||||
client.connect_to_broker().await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_loop(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
|
||||||
let default_topic = "esp32/topic";
|
|
||||||
match client.subscribe_to_topic(default_topic).await {
|
|
||||||
Ok(_) => info!("Subscribed to '{}'", default_topic),
|
|
||||||
Err(e) => info!("Default subscribe failed: {:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let net_or_ping = select(client.receive_message(), Timer::after(PING_PERIOD));
|
|
||||||
|
|
||||||
match select(CMD_CHAN.receive(), net_or_ping).await {
|
|
||||||
Either::First(cmd) => handle_command(client, cmd).await?,
|
|
||||||
Either::Second(Either::First(result)) => handle_incoming(result).await?,
|
|
||||||
Either::Second(Either::Second(_)) => client.send_ping().await?,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_command(client: &mut Client<'_, '_>, cmd: Command) -> Result<(), ReasonCode> {
|
async fn handle_command(client: &mut Client<'_, '_>, cmd: Command) -> Result<(), ReasonCode> {
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Publish(msg) => {
|
Command::Publish(msg) => {
|
||||||
client
|
match with_timeout(
|
||||||
.send_message(msg.topic.as_str(), &msg.payload, msg.qos, msg.retain)
|
Duration::from_secs(5),
|
||||||
|
client.send_message(msg.topic.as_str(), &msg.payload, msg.qos, msg.retain),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
|
{
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(_) => {
|
||||||
|
warn!("MQTT send timed out, forcing reconnect");
|
||||||
|
Err(ReasonCode::UnspecifiedError)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Command::Subscribe(topic) => {
|
Command::Subscribe(topic) => {
|
||||||
client.subscribe_to_topic(topic.as_str()).await?;
|
match with_timeout(
|
||||||
|
Duration::from_secs(5),
|
||||||
|
client.subscribe_to_topic(topic.as_str()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(result) => {
|
||||||
|
result?;
|
||||||
info!("Subscribed to '{}'", topic);
|
info!("Subscribed to '{}'", topic);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Err(_) => {
|
||||||
|
warn!("MQTT subscribe timed out");
|
||||||
|
Err(ReasonCode::UnspecifiedError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_incoming(result: Result<(&str, &[u8]), ReasonCode>) -> Result<(), ReasonCode> {
|
async fn handle_incoming(result: Result<(&str, &[u8]), ReasonCode>) -> Result<(), ReasonCode> {
|
||||||
let (topic, payload) = result?;
|
let (topic, payload) = result?;
|
||||||
EVT_CHAN
|
let msg = IncomingMsg {
|
||||||
.send(IncomingMsg {
|
|
||||||
topic: truncate_str::<TOPIC_MAX>(topic),
|
topic: truncate_str::<TOPIC_MAX>(topic),
|
||||||
payload: truncate_payload(payload),
|
payload: truncate_payload(payload),
|
||||||
})
|
};
|
||||||
.await;
|
if EVT_CHAN.try_send(msg).is_err() {
|
||||||
|
warn!("MQTT EVT queue full, dropping incoming message");
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session and reconnect control
|
|
||||||
async fn run_one_session(
|
async fn run_one_session(
|
||||||
stack: Stack<'static>,
|
stack: Stack<'static>,
|
||||||
tcp_rx: &mut [u8],
|
tcp_rx: &mut [u8],
|
||||||
@@ -185,12 +198,25 @@ async fn run_one_session(
|
|||||||
mqtt_rx: &mut [u8],
|
mqtt_rx: &mut [u8],
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
let mut socket = TcpSocket::new(stack, tcp_rx, tcp_tx);
|
let mut socket = TcpSocket::new(stack, tcp_rx, tcp_tx);
|
||||||
if connect_tcp(&mut socket).await.is_err() {
|
socket.set_timeout(Some(Duration::from_secs(20)));
|
||||||
|
match socket.connect(mqtt_broker_endpoint()).await {
|
||||||
|
Ok(_) => info!("Connected TCP to MQTT broker"),
|
||||||
|
Err(e) => {
|
||||||
|
info!("TCP connect failed: {:#?}", e);
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut client = build_client(socket, mqtt_tx, mqtt_rx);
|
// MQTT configuration and client setup
|
||||||
match connect_mqtt(&mut client).await {
|
let mut cfg: ClientConfig<8, CountingRng> =
|
||||||
|
ClientConfig::new(MqttVersion::MQTTv5, CountingRng(0));
|
||||||
|
cfg.keep_alive = KEEPALIVE_SECS as u16;
|
||||||
|
cfg.add_client_id("esp32-client");
|
||||||
|
|
||||||
|
let mut client =
|
||||||
|
MqttClient::new(socket, mqtt_tx, mqtt_tx.len(), mqtt_rx, mqtt_rx.len(), cfg);
|
||||||
|
|
||||||
|
match client.connect_to_broker().await {
|
||||||
Ok(_) => info!("MQTT CONNACK received"),
|
Ok(_) => info!("MQTT CONNACK received"),
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
info!("MQTT connect failed: {:?}", reason);
|
info!("MQTT connect failed: {:?}", reason);
|
||||||
@@ -198,10 +224,79 @@ async fn run_one_session(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run_loop(&mut client).await.map_err(|_| ())
|
let mut next_ping_at = Instant::now() + PING_PERIOD;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// Send latest IMU payload if available
|
||||||
|
if let Ok(mut guard) = IMU_LATEST.try_lock() {
|
||||||
|
if let Some(payload) = guard.take() {
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
|
log::info!("MQTT IMU TX start ({} bytes)", payload.len());
|
||||||
|
|
||||||
|
// Limit send to max 2 seconds to catch network stalls
|
||||||
|
let send_res = with_timeout(
|
||||||
|
Duration::from_secs(2),
|
||||||
|
client.send_message("esp32/imu", &payload, QualityOfService::QoS0, false),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match send_res {
|
||||||
|
Ok(Ok(_)) => {
|
||||||
|
log::info!("MQTT IMU TX ok");
|
||||||
|
next_ping_at = Instant::now() + PING_PERIOD;
|
||||||
|
}
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
log::warn!("MQTT IMU TX failed: {:?}", e);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
log::warn!("MQTT IMU TX timed out, restarting session");
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main MQTT embassy task
|
// Process any queued control commands
|
||||||
|
while let Ok(cmd) = CMD_CHAN.try_receive() {
|
||||||
|
handle_command(&mut client, cmd).await.map_err(|_| ())?;
|
||||||
|
next_ping_at = Instant::now() + PING_PERIOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for incoming messages with timeout
|
||||||
|
match with_timeout(Duration::from_millis(100), client.receive_message()).await {
|
||||||
|
Ok(Ok((topic, payload))) => {
|
||||||
|
// Handle incoming message
|
||||||
|
let _ = handle_incoming(Ok((topic, payload))).await;
|
||||||
|
next_ping_at = Instant::now() + PING_PERIOD;
|
||||||
|
}
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
log::warn!("MQTT receive error: {:?}", e);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if Instant::now() >= next_ping_at {
|
||||||
|
match with_timeout(PING_TIMEOUT, client.send_ping()).await {
|
||||||
|
Ok(Ok(_)) => {
|
||||||
|
next_ping_at = Instant::now() + PING_PERIOD;
|
||||||
|
}
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
warn!("MQTT ping failed: {:?}", e);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
warn!("MQTT ping timed out, restarting session");
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Main MQTT embassy task
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn mqtt_task(stack: Stack<'static>) {
|
pub async fn mqtt_task(stack: Stack<'static>) {
|
||||||
info!("MQTT task starting...");
|
info!("MQTT task starting...");
|
||||||
|
|||||||
Reference in New Issue
Block a user