How it works...
Instead of the naive busy waiting loop we created in the Creating I2C device drivers recipe, we now use a tokio-rs stream (effectively an asynchronous iterator) of events on which we can register a handler. Let's see how this more efficient structure is implemented.
First, in step 2, we recreate the sensor code from the Creating I2C device drivers recipe in order to have a sensor to use. In short, the code simulates an I2C-connected temperature sensor with a random number generator to show how a bus-connected device driver operates.
In step 3, we are preparing to use the driver to read a value and send it to a worker thread using a channel. Therefore, we create a Reading struct that saves a sensor reading at a certain timestamp. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access