Skip to content

Commit 2963b5b

Browse files
committed
Update to latest rs-matter
1 parent 7743943 commit 2963b5b

File tree

3 files changed

+14
-91
lines changed

3 files changed

+14
-91
lines changed

README.md

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ The [`esp-idf-matter`](https://github.com/ivmarkov/esp-idf-matter) crate provide
6464

6565
use core::pin::pin;
6666

67-
use embassy_futures::select::select;
68-
use embassy_time::{Duration, Timer};
69-
7067
use env_logger::Target;
7168
use log::info;
7269

@@ -83,7 +80,6 @@ use rs_matter_stack::matter::dm::{Async, Dataver, Endpoint, Node};
8380
use rs_matter_stack::matter::dm::{EmptyHandler, EpClMatcher};
8481
use rs_matter_stack::matter::error::Error;
8582
use rs_matter_stack::matter::utils::init::InitMaybeUninit;
86-
use rs_matter_stack::matter::utils::select::Coalesce;
8783
use rs_matter_stack::matter::{clusters, devices};
8884
use rs_matter_stack::mdns::ZeroconfMdns;
8985
use rs_matter_stack::persist::DirKvBlobStore;
@@ -112,11 +108,11 @@ fn main() -> Result<(), Error> {
112108
));
113109

114110
// Our "light" on-off cluster.
115-
// Can be anything implementing `rs_matter::dm::AsyncHandler`
111+
// It will toggle the light state every 5 seconds
116112
let on_off = on_off::OnOffHandler::new_standalone(
117113
Dataver::new_rand(stack.matter().rand()),
118114
LIGHT_ENDPOINT_ID,
119-
TestOnOffDeviceLogic::new(),
115+
TestOnOffDeviceLogic::new(true),
120116
);
121117

122118
// Chain our endpoint clusters with the
@@ -139,7 +135,7 @@ fn main() -> Result<(), Error> {
139135
// Run the Matter stack with our handler
140136
// Using `pin!` is completely optional, but reduces the size of the final future
141137
let store = stack.create_shared_store(DirKvBlobStore::new_default());
142-
let mut matter = pin!(stack.run_preex(
138+
let matter = pin!(stack.run_preex(
143139
// The Matter stack needs UDP sockets to communicate with other Matter devices
144140
edge_nal_std::Stack::new(),
145141
// Will try to find a default network interface
@@ -154,29 +150,8 @@ fn main() -> Result<(), Error> {
154150
(),
155151
));
156152

157-
// Just for demoing purposes:
158-
//
159-
// Run a sample loop that simulates state changes triggered by the HAL
160-
// Changes will be properly communicated to the Matter controllers
161-
// (i.e. Google Home, Alexa) and other Matter devices thanks to subscriptions
162-
let mut device = pin!(async {
163-
loop {
164-
// Simulate user toggling the light with a physical switch every 5 seconds
165-
Timer::after(Duration::from_secs(5)).await;
166-
167-
// Toggle
168-
on_off.set_on_off(!on_off.on_off());
169-
170-
// Let the Matter stack know that we have changed
171-
// the state of our Light device
172-
stack.notify_cluster_changed(1, TestOnOffDeviceLogic::CLUSTER.id);
173-
174-
info!("Light toggled");
175-
}
176-
});
177-
178-
// Schedule the Matter run & the device loop together
179-
futures_lite::future::block_on(select(&mut matter, &mut device).coalesce())
153+
// Schedule the Matter run
154+
futures_lite::future::block_on(matter)
180155
}
181156

182157
/// The Matter stack is allocated statically to avoid

examples/light.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
use core::pin::pin;
1212

13-
use embassy_futures::select::select;
14-
use embassy_time::{Duration, Timer};
15-
1613
use log::info;
1714

1815
use rs_matter::dm::clusters::on_off::test::TestOnOffDeviceLogic;
@@ -29,7 +26,6 @@ use rs_matter_stack::matter::dm::{EmptyHandler, EpClMatcher};
2926
use rs_matter_stack::matter::error::Error;
3027
use rs_matter_stack::matter::transport::network::btp::bluer::BluerGattPeripheral;
3128
use rs_matter_stack::matter::utils::init::InitMaybeUninit;
32-
use rs_matter_stack::matter::utils::select::Coalesce;
3329
use rs_matter_stack::matter::utils::sync::blocking::raw::StdRawMutex;
3430
use rs_matter_stack::matter::{clusters, devices};
3531
use rs_matter_stack::mdns::ZeroconfMdns;
@@ -59,11 +55,11 @@ fn main() -> Result<(), Error> {
5955
));
6056

6157
// Our "light" on-off cluster.
62-
// Can be anything implementing `rs_matter::dm::AsyncHandler`
58+
// It will toggle the light state every 5 seconds
6359
let on_off = on_off::OnOffHandler::new_standalone(
6460
Dataver::new_rand(stack.matter().rand()),
6561
LIGHT_ENDPOINT_ID,
66-
TestOnOffDeviceLogic::new(),
62+
TestOnOffDeviceLogic::new(true),
6763
);
6864

6965
// Chain our endpoint clusters with the
@@ -87,7 +83,7 @@ fn main() -> Result<(), Error> {
8783
// Run the Matter stack with our handler
8884
// Using `pin!` is completely optional, but reduces the size of the final future
8985
let store = stack.create_shared_store(DirKvBlobStore::new_default());
90-
let mut matter = pin!(stack.run_coex(
86+
let matter = pin!(stack.run_coex(
9187
PreexistingWireless::new(
9288
// The Matter stack needs UDP sockets to communicate with other Matter devices
9389
edge_nal_std::Stack::new(),
@@ -107,31 +103,8 @@ fn main() -> Result<(), Error> {
107103
(),
108104
));
109105

110-
// Just for demoing purposes:
111-
//
112-
// Run a sample loop that simulates state changes triggered by the HAL
113-
// Changes will be properly communicated to the Matter controllers
114-
// (i.e. Google Home, Alexa) and other Matter devices thanks to subscriptions
115-
let mut device = pin!(async {
116-
loop {
117-
// Simulate user toggling the light with a physical switch every 5 seconds
118-
Timer::after(Duration::from_secs(5)).await;
119-
120-
// Toggle
121-
on_off.set_on_off(!on_off.on_off());
122-
123-
// Let the Matter stack know that we have changed
124-
// the state of our Light device
125-
stack.notify_cluster_changed(1, TestOnOffDeviceLogic::CLUSTER.id);
126-
127-
info!("Light toggled");
128-
}
129-
});
130-
131106
// Schedule the Matter run & the device loop together
132-
futures_lite::future::block_on(async_compat::Compat::new(
133-
select(&mut matter, &mut device).coalesce(),
134-
))
107+
futures_lite::future::block_on(async_compat::Compat::new(matter))
135108
}
136109

137110
/// The Matter stack is allocated statically to avoid

examples/light_eth.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
use core::pin::pin;
1414

15-
use embassy_futures::select::select;
16-
use embassy_time::{Duration, Timer};
17-
1815
use env_logger::Target;
1916
use log::info;
2017

@@ -31,7 +28,6 @@ use rs_matter_stack::matter::dm::{Async, Dataver, Endpoint, Node};
3128
use rs_matter_stack::matter::dm::{EmptyHandler, EpClMatcher};
3229
use rs_matter_stack::matter::error::Error;
3330
use rs_matter_stack::matter::utils::init::InitMaybeUninit;
34-
use rs_matter_stack::matter::utils::select::Coalesce;
3531
use rs_matter_stack::matter::{clusters, devices};
3632
use rs_matter_stack::mdns::ZeroconfMdns;
3733
use rs_matter_stack::persist::DirKvBlobStore;
@@ -60,11 +56,11 @@ fn main() -> Result<(), Error> {
6056
));
6157

6258
// Our "light" on-off cluster.
63-
// Can be anything implementing `rs_matter::dm::AsyncHandler`
59+
// It will toggle the light state every 5 seconds
6460
let on_off = on_off::OnOffHandler::new_standalone(
6561
Dataver::new_rand(stack.matter().rand()),
6662
LIGHT_ENDPOINT_ID,
67-
TestOnOffDeviceLogic::new(),
63+
TestOnOffDeviceLogic::new(true),
6864
);
6965

7066
// Chain our endpoint clusters with the
@@ -87,7 +83,7 @@ fn main() -> Result<(), Error> {
8783
// Run the Matter stack with our handler
8884
// Using `pin!` is completely optional, but reduces the size of the final future
8985
let store = stack.create_shared_store(DirKvBlobStore::new_default());
90-
let mut matter = pin!(stack.run_preex(
86+
let matter = pin!(stack.run_preex(
9187
// The Matter stack needs UDP sockets to communicate with other Matter devices
9288
edge_nal_std::Stack::new(),
9389
// Will try to find a default network interface
@@ -102,29 +98,8 @@ fn main() -> Result<(), Error> {
10298
(),
10399
));
104100

105-
// Just for demoing purposes:
106-
//
107-
// Run a sample loop that simulates state changes triggered by the HAL
108-
// Changes will be properly communicated to the Matter controllers
109-
// (i.e. Google Home, Alexa) and other Matter devices thanks to subscriptions
110-
let mut device = pin!(async {
111-
loop {
112-
// Simulate user toggling the light with a physical switch every 5 seconds
113-
Timer::after(Duration::from_secs(5)).await;
114-
115-
// Toggle
116-
on_off.set_on_off(!on_off.on_off());
117-
118-
// Let the Matter stack know that we have changed
119-
// the state of our Light device
120-
stack.notify_cluster_changed(1, TestOnOffDeviceLogic::CLUSTER.id);
121-
122-
info!("Light toggled");
123-
}
124-
});
125-
126-
// Schedule the Matter run & the device loop together
127-
futures_lite::future::block_on(select(&mut matter, &mut device).coalesce())
101+
// Schedule the Matter run
102+
futures_lite::future::block_on(matter)
128103
}
129104

130105
/// The Matter stack is allocated statically to avoid

0 commit comments

Comments
 (0)