tinkerforge_async/bindings/
joystick_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! 2-axis joystick with push-button.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/Joystick_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum JoystickBrickletFunction {
24    GetPosition,
25    IsPressed,
26    GetAnalogValue,
27    Calibrate,
28    SetPositionCallbackPeriod,
29    GetPositionCallbackPeriod,
30    SetAnalogValueCallbackPeriod,
31    GetAnalogValueCallbackPeriod,
32    SetPositionCallbackThreshold,
33    GetPositionCallbackThreshold,
34    SetAnalogValueCallbackThreshold,
35    GetAnalogValueCallbackThreshold,
36    SetDebouncePeriod,
37    GetDebouncePeriod,
38    GetIdentity,
39    CallbackPosition,
40    CallbackAnalogValue,
41    CallbackPositionReached,
42    CallbackAnalogValueReached,
43    CallbackPressed,
44    CallbackReleased,
45}
46impl From<JoystickBrickletFunction> for u8 {
47    fn from(fun: JoystickBrickletFunction) -> Self {
48        match fun {
49            JoystickBrickletFunction::GetPosition => 1,
50            JoystickBrickletFunction::IsPressed => 2,
51            JoystickBrickletFunction::GetAnalogValue => 3,
52            JoystickBrickletFunction::Calibrate => 4,
53            JoystickBrickletFunction::SetPositionCallbackPeriod => 5,
54            JoystickBrickletFunction::GetPositionCallbackPeriod => 6,
55            JoystickBrickletFunction::SetAnalogValueCallbackPeriod => 7,
56            JoystickBrickletFunction::GetAnalogValueCallbackPeriod => 8,
57            JoystickBrickletFunction::SetPositionCallbackThreshold => 9,
58            JoystickBrickletFunction::GetPositionCallbackThreshold => 10,
59            JoystickBrickletFunction::SetAnalogValueCallbackThreshold => 11,
60            JoystickBrickletFunction::GetAnalogValueCallbackThreshold => 12,
61            JoystickBrickletFunction::SetDebouncePeriod => 13,
62            JoystickBrickletFunction::GetDebouncePeriod => 14,
63            JoystickBrickletFunction::GetIdentity => 255,
64            JoystickBrickletFunction::CallbackPosition => 15,
65            JoystickBrickletFunction::CallbackAnalogValue => 16,
66            JoystickBrickletFunction::CallbackPositionReached => 17,
67            JoystickBrickletFunction::CallbackAnalogValueReached => 18,
68            JoystickBrickletFunction::CallbackPressed => 19,
69            JoystickBrickletFunction::CallbackReleased => 20,
70        }
71    }
72}
73pub const JOYSTICK_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
74pub const JOYSTICK_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
75pub const JOYSTICK_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
76pub const JOYSTICK_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
77pub const JOYSTICK_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
78
79#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
80pub struct Position {
81    pub x: i16,
82    pub y: i16,
83}
84impl FromByteSlice for Position {
85    fn bytes_expected() -> usize {
86        4
87    }
88    fn from_le_byte_slice(bytes: &[u8]) -> Position {
89        Position { x: <i16>::from_le_byte_slice(&bytes[0..2]), y: <i16>::from_le_byte_slice(&bytes[2..4]) }
90    }
91}
92
93#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
94pub struct AnalogValue {
95    pub x: u16,
96    pub y: u16,
97}
98impl FromByteSlice for AnalogValue {
99    fn bytes_expected() -> usize {
100        4
101    }
102    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValue {
103        AnalogValue { x: <u16>::from_le_byte_slice(&bytes[0..2]), y: <u16>::from_le_byte_slice(&bytes[2..4]) }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct PositionCallbackThreshold {
109    pub option: char,
110    pub min_x: i16,
111    pub max_x: i16,
112    pub min_y: i16,
113    pub max_y: i16,
114}
115impl FromByteSlice for PositionCallbackThreshold {
116    fn bytes_expected() -> usize {
117        9
118    }
119    fn from_le_byte_slice(bytes: &[u8]) -> PositionCallbackThreshold {
120        PositionCallbackThreshold {
121            option: <char>::from_le_byte_slice(&bytes[0..1]),
122            min_x: <i16>::from_le_byte_slice(&bytes[1..3]),
123            max_x: <i16>::from_le_byte_slice(&bytes[3..5]),
124            min_y: <i16>::from_le_byte_slice(&bytes[5..7]),
125            max_y: <i16>::from_le_byte_slice(&bytes[7..9]),
126        }
127    }
128}
129
130#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
131pub struct AnalogValueCallbackThreshold {
132    pub option: char,
133    pub min_x: u16,
134    pub max_x: u16,
135    pub min_y: u16,
136    pub max_y: u16,
137}
138impl FromByteSlice for AnalogValueCallbackThreshold {
139    fn bytes_expected() -> usize {
140        9
141    }
142    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValueCallbackThreshold {
143        AnalogValueCallbackThreshold {
144            option: <char>::from_le_byte_slice(&bytes[0..1]),
145            min_x: <u16>::from_le_byte_slice(&bytes[1..3]),
146            max_x: <u16>::from_le_byte_slice(&bytes[3..5]),
147            min_y: <u16>::from_le_byte_slice(&bytes[5..7]),
148            max_y: <u16>::from_le_byte_slice(&bytes[7..9]),
149        }
150    }
151}
152
153#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
154pub struct PositionEvent {
155    pub x: i16,
156    pub y: i16,
157}
158impl FromByteSlice for PositionEvent {
159    fn bytes_expected() -> usize {
160        4
161    }
162    fn from_le_byte_slice(bytes: &[u8]) -> PositionEvent {
163        PositionEvent { x: <i16>::from_le_byte_slice(&bytes[0..2]), y: <i16>::from_le_byte_slice(&bytes[2..4]) }
164    }
165}
166
167#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
168pub struct AnalogValueEvent {
169    pub x: u16,
170    pub y: u16,
171}
172impl FromByteSlice for AnalogValueEvent {
173    fn bytes_expected() -> usize {
174        4
175    }
176    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValueEvent {
177        AnalogValueEvent { x: <u16>::from_le_byte_slice(&bytes[0..2]), y: <u16>::from_le_byte_slice(&bytes[2..4]) }
178    }
179}
180
181#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
182pub struct PositionReachedEvent {
183    pub x: i16,
184    pub y: i16,
185}
186impl FromByteSlice for PositionReachedEvent {
187    fn bytes_expected() -> usize {
188        4
189    }
190    fn from_le_byte_slice(bytes: &[u8]) -> PositionReachedEvent {
191        PositionReachedEvent { x: <i16>::from_le_byte_slice(&bytes[0..2]), y: <i16>::from_le_byte_slice(&bytes[2..4]) }
192    }
193}
194
195#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
196pub struct AnalogValueReachedEvent {
197    pub x: u16,
198    pub y: u16,
199}
200impl FromByteSlice for AnalogValueReachedEvent {
201    fn bytes_expected() -> usize {
202        4
203    }
204    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValueReachedEvent {
205        AnalogValueReachedEvent { x: <u16>::from_le_byte_slice(&bytes[0..2]), y: <u16>::from_le_byte_slice(&bytes[2..4]) }
206    }
207}
208
209#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
210pub struct Identity {
211    pub uid: String,
212    pub connected_uid: String,
213    pub position: char,
214    pub hardware_version: [u8; 3],
215    pub firmware_version: [u8; 3],
216    pub device_identifier: u16,
217}
218impl FromByteSlice for Identity {
219    fn bytes_expected() -> usize {
220        25
221    }
222    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
223        Identity {
224            uid: <String>::from_le_byte_slice(&bytes[0..8]),
225            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
226            position: <char>::from_le_byte_slice(&bytes[16..17]),
227            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
228            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
229            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
230        }
231    }
232}
233
234/// 2-axis joystick with push-button
235#[derive(Clone)]
236pub struct JoystickBricklet {
237    device: Device,
238}
239impl JoystickBricklet {
240    pub const DEVICE_IDENTIFIER: u16 = 210;
241    pub const DEVICE_DISPLAY_NAME: &'static str = "Joystick Bricklet";
242    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
243    pub fn new(uid: Uid, connection: AsyncIpConnection) -> JoystickBricklet {
244        let mut result = JoystickBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
245        result.device.response_expected[u8::from(JoystickBrickletFunction::GetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
246        result.device.response_expected[u8::from(JoystickBrickletFunction::IsPressed) as usize] = ResponseExpectedFlag::AlwaysTrue;
247        result.device.response_expected[u8::from(JoystickBrickletFunction::GetAnalogValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
248        result.device.response_expected[u8::from(JoystickBrickletFunction::Calibrate) as usize] = ResponseExpectedFlag::False;
249        result.device.response_expected[u8::from(JoystickBrickletFunction::SetPositionCallbackPeriod) as usize] =
250            ResponseExpectedFlag::True;
251        result.device.response_expected[u8::from(JoystickBrickletFunction::GetPositionCallbackPeriod) as usize] =
252            ResponseExpectedFlag::AlwaysTrue;
253        result.device.response_expected[u8::from(JoystickBrickletFunction::SetAnalogValueCallbackPeriod) as usize] =
254            ResponseExpectedFlag::True;
255        result.device.response_expected[u8::from(JoystickBrickletFunction::GetAnalogValueCallbackPeriod) as usize] =
256            ResponseExpectedFlag::AlwaysTrue;
257        result.device.response_expected[u8::from(JoystickBrickletFunction::SetPositionCallbackThreshold) as usize] =
258            ResponseExpectedFlag::True;
259        result.device.response_expected[u8::from(JoystickBrickletFunction::GetPositionCallbackThreshold) as usize] =
260            ResponseExpectedFlag::AlwaysTrue;
261        result.device.response_expected[u8::from(JoystickBrickletFunction::SetAnalogValueCallbackThreshold) as usize] =
262            ResponseExpectedFlag::True;
263        result.device.response_expected[u8::from(JoystickBrickletFunction::GetAnalogValueCallbackThreshold) as usize] =
264            ResponseExpectedFlag::AlwaysTrue;
265        result.device.response_expected[u8::from(JoystickBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
266        result.device.response_expected[u8::from(JoystickBrickletFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
267        result.device.response_expected[u8::from(JoystickBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
268        result
269    }
270
271    /// Returns the response expected flag for the function specified by the function ID parameter.
272    /// It is true if the function is expected to send a response, false otherwise.
273    ///
274    /// For getter functions this is enabled by default and cannot be disabled, because those
275    /// functions will always send a response. For callback configuration functions it is enabled
276    /// by default too, but can be disabled by [`set_response_expected`](crate::joystick_bricklet::JoystickBricklet::set_response_expected).
277    /// For setter functions it is disabled by default and can be enabled.
278    ///
279    /// Enabling the response expected flag for a setter function allows to detect timeouts
280    /// and other error conditions calls of this setter as well. The device will then send a response
281    /// for this purpose. If this flag is disabled for a setter function then no response is sent
282    /// and errors are silently ignored, because they cannot be detected.
283    ///
284    /// See [`set_response_expected`](crate::joystick_bricklet::JoystickBricklet::set_response_expected) for the list of function ID constants available for this function.
285    pub fn get_response_expected(&mut self, fun: JoystickBrickletFunction) -> Result<bool, GetResponseExpectedError> {
286        self.device.get_response_expected(u8::from(fun))
287    }
288
289    /// Changes the response expected flag of the function specified by the function ID parameter.
290    /// This flag can only be changed for setter (default value: false) and callback configuration
291    /// functions (default value: true). For getter functions it is always enabled.
292    ///
293    /// Enabling the response expected flag for a setter function allows to detect timeouts and
294    /// other error conditions calls of this setter as well. The device will then send a response
295    /// for this purpose. If this flag is disabled for a setter function then no response is sent
296    /// and errors are silently ignored, because they cannot be detected.
297    pub fn set_response_expected(
298        &mut self,
299        fun: JoystickBrickletFunction,
300        response_expected: bool,
301    ) -> Result<(), SetResponseExpectedError> {
302        self.device.set_response_expected(u8::from(fun), response_expected)
303    }
304
305    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
306    pub fn set_response_expected_all(&mut self, response_expected: bool) {
307        self.device.set_response_expected_all(response_expected)
308    }
309
310    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
311    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
312    pub fn get_api_version(&self) -> [u8; 3] {
313        self.device.api_version
314    }
315
316    /// This receiver is triggered periodically with the period that is set by
317    /// [`set_position_callback_period`]. The parameter is the position of the
318    /// joystick.
319    ///
320    /// The [`get_position_callback_receiver`] receiver is only triggered if the position has changed since the
321    /// last triggering.
322    ///
323    /// [`set_position_callback_period`]: #method.set_position_callback_period
324    /// [`get_position_callback_receiver`]: #method.get_position_callback_receiver
325    pub async fn get_position_callback_receiver(&mut self) -> impl Stream<Item = PositionEvent> {
326        self.device
327            .get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackPosition))
328            .await
329            .map(|p| PositionEvent::from_le_byte_slice(p.body()))
330    }
331
332    /// This receiver is triggered periodically with the period that is set by
333    /// [`set_analog_value_callback_period`]. The parameters are the
334    /// analog values of the joystick.
335    ///
336    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the values have changed
337    /// since the last triggering.
338    pub async fn get_analog_value_callback_receiver(&mut self) -> impl Stream<Item = AnalogValueEvent> {
339        self.device
340            .get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackAnalogValue))
341            .await
342            .map(|p| AnalogValueEvent::from_le_byte_slice(p.body()))
343    }
344
345    /// This receiver is triggered when the threshold as set by
346    /// [`set_position_callback_threshold`] is reached.
347    /// The parameters are the position of the joystick.
348    ///
349    /// If the threshold keeps being reached, the receiver is triggered periodically
350    /// with the period as set by [`set_debounce_period`].
351    pub async fn get_position_reached_callback_receiver(&mut self) -> impl Stream<Item = PositionReachedEvent> {
352        self.device
353            .get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackPositionReached))
354            .await
355            .map(|p| PositionReachedEvent::from_le_byte_slice(p.body()))
356    }
357
358    /// This receiver is triggered when the threshold as set by
359    /// [`set_analog_value_callback_threshold`] is reached.
360    /// The parameters are the analog values of the joystick.
361    ///
362    /// If the threshold keeps being reached, the receiver is triggered periodically
363    /// with the period as set by [`set_debounce_period`].
364    pub async fn get_analog_value_reached_callback_receiver(&mut self) -> impl Stream<Item = AnalogValueReachedEvent> {
365        self.device
366            .get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackAnalogValueReached))
367            .await
368            .map(|p| AnalogValueReachedEvent::from_le_byte_slice(p.body()))
369    }
370
371    /// This receiver is triggered when the button is pressed.
372    pub async fn get_pressed_callback_receiver(&mut self) -> impl Stream<Item = ()> {
373        self.device.get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackPressed)).await.map(|_p| ())
374    }
375
376    /// This receiver is triggered when the button is released.
377    pub async fn get_released_callback_receiver(&mut self) -> impl Stream<Item = ()> {
378        self.device.get_callback_receiver(u8::from(JoystickBrickletFunction::CallbackReleased)).await.map(|_p| ())
379    }
380
381    /// Returns the position of the joystick. The middle position of the joystick is x=0, y=0.
382    /// The returned values are averaged and calibrated (see [`calibrate`]).
383    ///
384    /// If you want to get the position periodically, it is recommended to use the
385    /// [`get_position_callback_receiver`] receiver and set the period with
386    /// [`set_position_callback_period`].
387    pub async fn get_position(&mut self) -> Result<Position, TinkerforgeError> {
388        let payload = [0; 0];
389
390        #[allow(unused_variables)]
391        let result = self.device.get(u8::from(JoystickBrickletFunction::GetPosition), &payload).await?;
392        Ok(Position::from_le_byte_slice(result.body()))
393    }
394
395    /// Returns *true* if the button is pressed and *false* otherwise.
396    ///
397    /// It is recommended to use the [`get_pressed_callback_receiver`] and [`get_released_callback_receiver`] receivers
398    /// to handle the button.
399    pub async fn is_pressed(&mut self) -> Result<bool, TinkerforgeError> {
400        let payload = [0; 0];
401
402        #[allow(unused_variables)]
403        let result = self.device.get(u8::from(JoystickBrickletFunction::IsPressed), &payload).await?;
404        Ok(bool::from_le_byte_slice(result.body()))
405    }
406
407    /// Returns the values as read by a 12-bit analog-to-digital converter.
408    ///
409    /// # Note
410    ///  The values returned by [`get_position`] are averaged over several samples
411    ///  to yield less noise, while [`get_analog_value`] gives back raw
412    ///  unfiltered analog values. The only reason to use [`get_analog_value`] is,
413    ///  if you need the full resolution of the analog-to-digital converter.
414    ///
415    /// If you want the analog values periodically, it is recommended to use the
416    /// [`get_analog_value_callback_receiver`] receiver and set the period with
417    /// [`set_analog_value_callback_period`].
418    pub async fn get_analog_value(&mut self) -> Result<AnalogValue, TinkerforgeError> {
419        let payload = [0; 0];
420
421        #[allow(unused_variables)]
422        let result = self.device.get(u8::from(JoystickBrickletFunction::GetAnalogValue), &payload).await?;
423        Ok(AnalogValue::from_le_byte_slice(result.body()))
424    }
425
426    /// Calibrates the middle position of the joystick. If your Joystick Bricklet
427    /// does not return x=0 and y=0 in the middle position, call this function
428    /// while the joystick is standing still in the middle position.
429    ///
430    /// The resulting calibration will be saved on the EEPROM of the Joystick
431    /// Bricklet, thus you only have to calibrate it once.
432    pub async fn calibrate(&mut self) -> Result<(), TinkerforgeError> {
433        let payload = [0; 0];
434
435        #[allow(unused_variables)]
436        let result = self.device.set(u8::from(JoystickBrickletFunction::Calibrate), &payload).await?;
437        Ok(())
438    }
439
440    /// Sets the period with which the [`get_position_callback_receiver`] receiver is triggered
441    /// periodically. A value of 0 turns the receiver off.
442    ///
443    /// The [`get_position_callback_receiver`] receiver is only triggered if the position has changed since the
444    /// last triggering.
445    pub async fn set_position_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
446        let mut payload = [0; 4];
447        period.write_to_slice(&mut payload[0..4]);
448
449        #[allow(unused_variables)]
450        let result = self.device.set(u8::from(JoystickBrickletFunction::SetPositionCallbackPeriod), &payload).await?;
451        Ok(())
452    }
453
454    /// Returns the period as set by [`set_position_callback_period`].
455    pub async fn get_position_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
456        let payload = [0; 0];
457
458        #[allow(unused_variables)]
459        let result = self.device.get(u8::from(JoystickBrickletFunction::GetPositionCallbackPeriod), &payload).await?;
460        Ok(u32::from_le_byte_slice(result.body()))
461    }
462
463    /// Sets the period with which the [`get_analog_value_callback_receiver`] receiver is triggered
464    /// periodically. A value of 0 turns the receiver off.
465    ///
466    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the analog values have
467    /// changed since the last triggering.
468    pub async fn set_analog_value_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
469        let mut payload = [0; 4];
470        period.write_to_slice(&mut payload[0..4]);
471
472        #[allow(unused_variables)]
473        let result = self.device.set(u8::from(JoystickBrickletFunction::SetAnalogValueCallbackPeriod), &payload).await?;
474        Ok(())
475    }
476
477    /// Returns the period as set by [`set_analog_value_callback_period`].
478    pub async fn get_analog_value_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
479        let payload = [0; 0];
480
481        #[allow(unused_variables)]
482        let result = self.device.get(u8::from(JoystickBrickletFunction::GetAnalogValueCallbackPeriod), &payload).await?;
483        Ok(u32::from_le_byte_slice(result.body()))
484    }
485
486    /// Sets the thresholds for the [`get_position_reached_callback_receiver`] receiver.
487    ///
488    /// The following options are possible:
489    ///
490    ///  Option| Description
491    ///  --- | ---
492    ///  'x'|    Receiver is turned off
493    ///  'o'|    Receiver is triggered when the position is *outside* the min and max values
494    ///  'i'|    Receiver is triggered when the position is *inside* the min and max values
495    ///  '<'|    Receiver is triggered when the position is smaller than the min values (max is ignored)
496    ///  '>'|    Receiver is triggered when the position is greater than the min values (max is ignored)
497    ///
498    /// Associated constants:
499    /// * JOYSTICK_BRICKLET_THRESHOLD_OPTION_OFF
500    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_OUTSIDE
501    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_INSIDE
502    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_SMALLER
503    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_GREATER
504    pub async fn set_position_callback_threshold(
505        &mut self,
506        option: char,
507        min_x: i16,
508        max_x: i16,
509        min_y: i16,
510        max_y: i16,
511    ) -> Result<(), TinkerforgeError> {
512        let mut payload = [0; 9];
513        option.write_to_slice(&mut payload[0..1]);
514        min_x.write_to_slice(&mut payload[1..3]);
515        max_x.write_to_slice(&mut payload[3..5]);
516        min_y.write_to_slice(&mut payload[5..7]);
517        max_y.write_to_slice(&mut payload[7..9]);
518
519        #[allow(unused_variables)]
520        let result = self.device.set(u8::from(JoystickBrickletFunction::SetPositionCallbackThreshold), &payload).await?;
521        Ok(())
522    }
523
524    /// Returns the threshold as set by [`set_position_callback_threshold`].
525    ///
526    /// Associated constants:
527    /// * JOYSTICK_BRICKLET_THRESHOLD_OPTION_OFF
528    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_OUTSIDE
529    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_INSIDE
530    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_SMALLER
531    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_GREATER
532    pub async fn get_position_callback_threshold(&mut self) -> Result<PositionCallbackThreshold, TinkerforgeError> {
533        let payload = [0; 0];
534
535        #[allow(unused_variables)]
536        let result = self.device.get(u8::from(JoystickBrickletFunction::GetPositionCallbackThreshold), &payload).await?;
537        Ok(PositionCallbackThreshold::from_le_byte_slice(result.body()))
538    }
539
540    /// Sets the thresholds for the [`get_analog_value_reached_callback_receiver`] receiver.
541    ///
542    /// The following options are possible:
543    ///
544    ///  Option| Description
545    ///  --- | ---
546    ///  'x'|    Receiver is turned off
547    ///  'o'|    Receiver is triggered when the analog values are *outside* the min and max values
548    ///  'i'|    Receiver is triggered when the analog values are *inside* the min and max values
549    ///  '<'|    Receiver is triggered when the analog values are smaller than the min values (max is ignored)
550    ///  '>'|    Receiver is triggered when the analog values are greater than the min values (max is ignored)
551    ///
552    /// Associated constants:
553    /// * JOYSTICK_BRICKLET_THRESHOLD_OPTION_OFF
554    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_OUTSIDE
555    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_INSIDE
556    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_SMALLER
557    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_GREATER
558    pub async fn set_analog_value_callback_threshold(
559        &mut self,
560        option: char,
561        min_x: u16,
562        max_x: u16,
563        min_y: u16,
564        max_y: u16,
565    ) -> Result<(), TinkerforgeError> {
566        let mut payload = [0; 9];
567        option.write_to_slice(&mut payload[0..1]);
568        min_x.write_to_slice(&mut payload[1..3]);
569        max_x.write_to_slice(&mut payload[3..5]);
570        min_y.write_to_slice(&mut payload[5..7]);
571        max_y.write_to_slice(&mut payload[7..9]);
572
573        #[allow(unused_variables)]
574        let result = self.device.set(u8::from(JoystickBrickletFunction::SetAnalogValueCallbackThreshold), &payload).await?;
575        Ok(())
576    }
577
578    /// Returns the threshold as set by [`set_analog_value_callback_threshold`].
579    ///
580    /// Associated constants:
581    /// * JOYSTICK_BRICKLET_THRESHOLD_OPTION_OFF
582    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_OUTSIDE
583    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_INSIDE
584    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_SMALLER
585    ///	* JOYSTICK_BRICKLET_THRESHOLD_OPTION_GREATER
586    pub async fn get_analog_value_callback_threshold(&mut self) -> Result<AnalogValueCallbackThreshold, TinkerforgeError> {
587        let payload = [0; 0];
588
589        #[allow(unused_variables)]
590        let result = self.device.get(u8::from(JoystickBrickletFunction::GetAnalogValueCallbackThreshold), &payload).await?;
591        Ok(AnalogValueCallbackThreshold::from_le_byte_slice(result.body()))
592    }
593
594    /// Sets the period with which the threshold receivers
595    ///
596    /// * [`get_position_reached_callback_receiver`],
597    /// * [`get_analog_value_reached_callback_receiver`]
598    ///
599    /// are triggered, if the thresholds
600    ///
601    /// * [`set_position_callback_threshold`],
602    /// * [`set_analog_value_callback_threshold`]
603    ///
604    /// keep being reached.
605    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
606        let mut payload = [0; 4];
607        debounce.write_to_slice(&mut payload[0..4]);
608
609        #[allow(unused_variables)]
610        let result = self.device.set(u8::from(JoystickBrickletFunction::SetDebouncePeriod), &payload).await?;
611        Ok(())
612    }
613
614    /// Returns the debounce period as set by [`set_debounce_period`].
615    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
616        let payload = [0; 0];
617
618        #[allow(unused_variables)]
619        let result = self.device.get(u8::from(JoystickBrickletFunction::GetDebouncePeriod), &payload).await?;
620        Ok(u32::from_le_byte_slice(result.body()))
621    }
622
623    /// Returns the UID, the UID where the Bricklet is connected to,
624    /// the position, the hardware and firmware version as well as the
625    /// device identifier.
626    ///
627    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
628    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
629    /// position 'z'.
630    ///
631    /// The device identifier numbers can be found [here](device_identifier).
632    /// |device_identifier_constant|
633    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
634        let payload = [0; 0];
635
636        #[allow(unused_variables)]
637        let result = self.device.get(u8::from(JoystickBrickletFunction::GetIdentity), &payload).await?;
638        Ok(Identity::from_le_byte_slice(result.body()))
639    }
640}