MCPcopy Create free account
hub / github.com/OpenActionAPI/rust-elgato-streamdeck / read

Method read

src/asynchronous.rs:201–268  ·  view source on GitHub ↗

Reads states and returns updates

(&self, poll_rate: f32)

Source from the content-addressed store, hash-verified

199impl AsyncDeviceStateReader {
200 /// Reads states and returns updates
201 pub async fn read(&self, poll_rate: f32) -> Result<Vec<DeviceStateUpdate>, StreamDeckError> {
202 let input = self.device.read_input(poll_rate).await?;
203 let mut my_states = self.states.lock().await;
204
205 let mut updates = vec![];
206
207 match input {
208 StreamDeckInput::ButtonStateChange(buttons) => {
209 for (index, (their, mine)) in zip(buttons.iter(), my_states.buttons.iter()).enumerate() {
210 if *their != *mine {
211 if index < self.device.kind.key_count() as usize {
212 if *their {
213 updates.push(DeviceStateUpdate::ButtonDown(index as u8));
214 } else {
215 updates.push(DeviceStateUpdate::ButtonUp(index as u8));
216 }
217 } else if *their {
218 updates.push(DeviceStateUpdate::TouchPointDown(index as u8 - self.device.kind.key_count()));
219 } else {
220 updates.push(DeviceStateUpdate::TouchPointUp(index as u8 - self.device.kind.key_count()));
221 }
222 }
223 }
224
225 my_states.buttons = buttons;
226 }
227
228 StreamDeckInput::EncoderStateChange(encoders) => {
229 for (index, (their, mine)) in zip(encoders.iter(), my_states.encoders.iter()).enumerate() {
230 if *their != *mine {
231 if *their {
232 updates.push(DeviceStateUpdate::EncoderDown(index as u8));
233 } else {
234 updates.push(DeviceStateUpdate::EncoderUp(index as u8));
235 }
236 }
237 }
238
239 my_states.encoders = encoders;
240 }
241
242 StreamDeckInput::EncoderTwist(twist) => {
243 for (index, change) in twist.iter().enumerate() {
244 if *change != 0 {
245 updates.push(DeviceStateUpdate::EncoderTwist(index as u8, *change));
246 }
247 }
248 }
249
250 StreamDeckInput::TouchScreenPress(x, y) => {
251 updates.push(DeviceStateUpdate::TouchScreenPress(x, y));
252 }
253
254 StreamDeckInput::TouchScreenLongPress(x, y) => {
255 updates.push(DeviceStateUpdate::TouchScreenLongPress(x, y));
256 }
257
258 StreamDeckInput::TouchScreenSwipe(s, e) => {

Callers

nothing calls this directly

Calls 2

key_countMethod · 0.80
read_inputMethod · 0.45

Tested by

no test coverage detected