1use crate::{
15 byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16 ip_connection::GetRequestSender,
17};
18pub enum SilentStepperBrickFunction {
19 SetMaxVelocity,
20 GetMaxVelocity,
21 GetCurrentVelocity,
22 SetSpeedRamping,
23 GetSpeedRamping,
24 FullBrake,
25 SetCurrentPosition,
26 GetCurrentPosition,
27 SetTargetPosition,
28 GetTargetPosition,
29 SetSteps,
30 GetSteps,
31 GetRemainingSteps,
32 SetStepConfiguration,
33 GetStepConfiguration,
34 DriveForward,
35 DriveBackward,
36 Stop,
37 GetStackInputVoltage,
38 GetExternalInputVoltage,
39 SetMotorCurrent,
40 GetMotorCurrent,
41 Enable,
42 Disable,
43 IsEnabled,
44 SetBasicConfiguration,
45 GetBasicConfiguration,
46 SetSpreadcycleConfiguration,
47 GetSpreadcycleConfiguration,
48 SetStealthConfiguration,
49 GetStealthConfiguration,
50 SetCoolstepConfiguration,
51 GetCoolstepConfiguration,
52 SetMiscConfiguration,
53 GetMiscConfiguration,
54 GetDriverStatus,
55 SetMinimumVoltage,
56 GetMinimumVoltage,
57 SetTimeBase,
58 GetTimeBase,
59 GetAllData,
60 SetAllDataPeriod,
61 GetAllDataPeriod,
62 SetSpitfpBaudrateConfig,
63 GetSpitfpBaudrateConfig,
64 GetSendTimeoutCount,
65 SetSpitfpBaudrate,
66 GetSpitfpBaudrate,
67 GetSpitfpErrorCount,
68 EnableStatusLed,
69 DisableStatusLed,
70 IsStatusLedEnabled,
71 GetProtocol1BrickletName,
72 GetChipTemperature,
73 Reset,
74 WriteBrickletPlugin,
75 ReadBrickletPlugin,
76 GetIdentity,
77 CallbackUnderVoltage,
78 CallbackPositionReached,
79 CallbackAllData,
80 CallbackNewState,
81}
82impl From<SilentStepperBrickFunction> for u8 {
83 fn from(fun: SilentStepperBrickFunction) -> Self {
84 match fun {
85 SilentStepperBrickFunction::SetMaxVelocity => 1,
86 SilentStepperBrickFunction::GetMaxVelocity => 2,
87 SilentStepperBrickFunction::GetCurrentVelocity => 3,
88 SilentStepperBrickFunction::SetSpeedRamping => 4,
89 SilentStepperBrickFunction::GetSpeedRamping => 5,
90 SilentStepperBrickFunction::FullBrake => 6,
91 SilentStepperBrickFunction::SetCurrentPosition => 7,
92 SilentStepperBrickFunction::GetCurrentPosition => 8,
93 SilentStepperBrickFunction::SetTargetPosition => 9,
94 SilentStepperBrickFunction::GetTargetPosition => 10,
95 SilentStepperBrickFunction::SetSteps => 11,
96 SilentStepperBrickFunction::GetSteps => 12,
97 SilentStepperBrickFunction::GetRemainingSteps => 13,
98 SilentStepperBrickFunction::SetStepConfiguration => 14,
99 SilentStepperBrickFunction::GetStepConfiguration => 15,
100 SilentStepperBrickFunction::DriveForward => 16,
101 SilentStepperBrickFunction::DriveBackward => 17,
102 SilentStepperBrickFunction::Stop => 18,
103 SilentStepperBrickFunction::GetStackInputVoltage => 19,
104 SilentStepperBrickFunction::GetExternalInputVoltage => 20,
105 SilentStepperBrickFunction::SetMotorCurrent => 22,
106 SilentStepperBrickFunction::GetMotorCurrent => 23,
107 SilentStepperBrickFunction::Enable => 24,
108 SilentStepperBrickFunction::Disable => 25,
109 SilentStepperBrickFunction::IsEnabled => 26,
110 SilentStepperBrickFunction::SetBasicConfiguration => 27,
111 SilentStepperBrickFunction::GetBasicConfiguration => 28,
112 SilentStepperBrickFunction::SetSpreadcycleConfiguration => 29,
113 SilentStepperBrickFunction::GetSpreadcycleConfiguration => 30,
114 SilentStepperBrickFunction::SetStealthConfiguration => 31,
115 SilentStepperBrickFunction::GetStealthConfiguration => 32,
116 SilentStepperBrickFunction::SetCoolstepConfiguration => 33,
117 SilentStepperBrickFunction::GetCoolstepConfiguration => 34,
118 SilentStepperBrickFunction::SetMiscConfiguration => 35,
119 SilentStepperBrickFunction::GetMiscConfiguration => 36,
120 SilentStepperBrickFunction::GetDriverStatus => 37,
121 SilentStepperBrickFunction::SetMinimumVoltage => 38,
122 SilentStepperBrickFunction::GetMinimumVoltage => 39,
123 SilentStepperBrickFunction::SetTimeBase => 42,
124 SilentStepperBrickFunction::GetTimeBase => 43,
125 SilentStepperBrickFunction::GetAllData => 44,
126 SilentStepperBrickFunction::SetAllDataPeriod => 45,
127 SilentStepperBrickFunction::GetAllDataPeriod => 46,
128 SilentStepperBrickFunction::SetSpitfpBaudrateConfig => 231,
129 SilentStepperBrickFunction::GetSpitfpBaudrateConfig => 232,
130 SilentStepperBrickFunction::GetSendTimeoutCount => 233,
131 SilentStepperBrickFunction::SetSpitfpBaudrate => 234,
132 SilentStepperBrickFunction::GetSpitfpBaudrate => 235,
133 SilentStepperBrickFunction::GetSpitfpErrorCount => 237,
134 SilentStepperBrickFunction::EnableStatusLed => 238,
135 SilentStepperBrickFunction::DisableStatusLed => 239,
136 SilentStepperBrickFunction::IsStatusLedEnabled => 240,
137 SilentStepperBrickFunction::GetProtocol1BrickletName => 241,
138 SilentStepperBrickFunction::GetChipTemperature => 242,
139 SilentStepperBrickFunction::Reset => 243,
140 SilentStepperBrickFunction::WriteBrickletPlugin => 246,
141 SilentStepperBrickFunction::ReadBrickletPlugin => 247,
142 SilentStepperBrickFunction::GetIdentity => 255,
143 SilentStepperBrickFunction::CallbackUnderVoltage => 40,
144 SilentStepperBrickFunction::CallbackPositionReached => 41,
145 SilentStepperBrickFunction::CallbackAllData => 47,
146 SilentStepperBrickFunction::CallbackNewState => 48,
147 }
148 }
149}
150pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_1: u8 = 8;
151pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_2: u8 = 7;
152pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_4: u8 = 6;
153pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_8: u8 = 5;
154pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_16: u8 = 4;
155pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_32: u8 = 3;
156pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_64: u8 = 2;
157pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_128: u8 = 1;
158pub const SILENT_STEPPER_BRICK_STEP_RESOLUTION_256: u8 = 0;
159pub const SILENT_STEPPER_BRICK_CHOPPER_MODE_SPREAD_CYCLE: u8 = 0;
160pub const SILENT_STEPPER_BRICK_CHOPPER_MODE_FAST_DECAY: u8 = 1;
161pub const SILENT_STEPPER_BRICK_FREEWHEEL_MODE_NORMAL: u8 = 0;
162pub const SILENT_STEPPER_BRICK_FREEWHEEL_MODE_FREEWHEELING: u8 = 1;
163pub const SILENT_STEPPER_BRICK_FREEWHEEL_MODE_COIL_SHORT_LS: u8 = 2;
164pub const SILENT_STEPPER_BRICK_FREEWHEEL_MODE_COIL_SHORT_HS: u8 = 3;
165pub const SILENT_STEPPER_BRICK_CURRENT_UP_STEP_INCREMENT_1: u8 = 0;
166pub const SILENT_STEPPER_BRICK_CURRENT_UP_STEP_INCREMENT_2: u8 = 1;
167pub const SILENT_STEPPER_BRICK_CURRENT_UP_STEP_INCREMENT_4: u8 = 2;
168pub const SILENT_STEPPER_BRICK_CURRENT_UP_STEP_INCREMENT_8: u8 = 3;
169pub const SILENT_STEPPER_BRICK_CURRENT_DOWN_STEP_DECREMENT_1: u8 = 0;
170pub const SILENT_STEPPER_BRICK_CURRENT_DOWN_STEP_DECREMENT_2: u8 = 1;
171pub const SILENT_STEPPER_BRICK_CURRENT_DOWN_STEP_DECREMENT_8: u8 = 2;
172pub const SILENT_STEPPER_BRICK_CURRENT_DOWN_STEP_DECREMENT_32: u8 = 3;
173pub const SILENT_STEPPER_BRICK_MINIMUM_CURRENT_HALF: u8 = 0;
174pub const SILENT_STEPPER_BRICK_MINIMUM_CURRENT_QUARTER: u8 = 1;
175pub const SILENT_STEPPER_BRICK_STALLGUARD_MODE_STANDARD: u8 = 0;
176pub const SILENT_STEPPER_BRICK_STALLGUARD_MODE_FILTERED: u8 = 1;
177pub const SILENT_STEPPER_BRICK_OPEN_LOAD_NONE: u8 = 0;
178pub const SILENT_STEPPER_BRICK_OPEN_LOAD_PHASE_A: u8 = 1;
179pub const SILENT_STEPPER_BRICK_OPEN_LOAD_PHASE_B: u8 = 2;
180pub const SILENT_STEPPER_BRICK_OPEN_LOAD_PHASE_AB: u8 = 3;
181pub const SILENT_STEPPER_BRICK_SHORT_TO_GROUND_NONE: u8 = 0;
182pub const SILENT_STEPPER_BRICK_SHORT_TO_GROUND_PHASE_A: u8 = 1;
183pub const SILENT_STEPPER_BRICK_SHORT_TO_GROUND_PHASE_B: u8 = 2;
184pub const SILENT_STEPPER_BRICK_SHORT_TO_GROUND_PHASE_AB: u8 = 3;
185pub const SILENT_STEPPER_BRICK_OVER_TEMPERATURE_NONE: u8 = 0;
186pub const SILENT_STEPPER_BRICK_OVER_TEMPERATURE_WARNING: u8 = 1;
187pub const SILENT_STEPPER_BRICK_OVER_TEMPERATURE_LIMIT: u8 = 2;
188pub const SILENT_STEPPER_BRICK_STATE_STOP: u8 = 1;
189pub const SILENT_STEPPER_BRICK_STATE_ACCELERATION: u8 = 2;
190pub const SILENT_STEPPER_BRICK_STATE_RUN: u8 = 3;
191pub const SILENT_STEPPER_BRICK_STATE_DEACCELERATION: u8 = 4;
192pub const SILENT_STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_FORWARD: u8 = 5;
193pub const SILENT_STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_BACKWARD: u8 = 6;
194pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
195pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
196pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
197pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
198pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
199pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
200pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
201pub const SILENT_STEPPER_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
202
203#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
204pub struct SpeedRamping {
205 pub acceleration: u16,
206 pub deacceleration: u16,
207}
208impl FromByteSlice for SpeedRamping {
209 fn bytes_expected() -> usize { 4 }
210 fn from_le_byte_slice(bytes: &[u8]) -> SpeedRamping {
211 SpeedRamping { acceleration: <u16>::from_le_byte_slice(&bytes[0..2]), deacceleration: <u16>::from_le_byte_slice(&bytes[2..4]) }
212 }
213}
214
215#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
216pub struct StepConfiguration {
217 pub step_resolution: u8,
218 pub interpolation: bool,
219}
220impl FromByteSlice for StepConfiguration {
221 fn bytes_expected() -> usize { 2 }
222 fn from_le_byte_slice(bytes: &[u8]) -> StepConfiguration {
223 StepConfiguration {
224 step_resolution: <u8>::from_le_byte_slice(&bytes[0..1]),
225 interpolation: <bool>::from_le_byte_slice(&bytes[1..2]),
226 }
227 }
228}
229
230#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
231pub struct BasicConfiguration {
232 pub standstill_current: u16,
233 pub motor_run_current: u16,
234 pub standstill_delay_time: u16,
235 pub power_down_time: u16,
236 pub stealth_threshold: u16,
237 pub coolstep_threshold: u16,
238 pub classic_threshold: u16,
239 pub high_velocity_chopper_mode: bool,
240}
241impl FromByteSlice for BasicConfiguration {
242 fn bytes_expected() -> usize { 15 }
243 fn from_le_byte_slice(bytes: &[u8]) -> BasicConfiguration {
244 BasicConfiguration {
245 standstill_current: <u16>::from_le_byte_slice(&bytes[0..2]),
246 motor_run_current: <u16>::from_le_byte_slice(&bytes[2..4]),
247 standstill_delay_time: <u16>::from_le_byte_slice(&bytes[4..6]),
248 power_down_time: <u16>::from_le_byte_slice(&bytes[6..8]),
249 stealth_threshold: <u16>::from_le_byte_slice(&bytes[8..10]),
250 coolstep_threshold: <u16>::from_le_byte_slice(&bytes[10..12]),
251 classic_threshold: <u16>::from_le_byte_slice(&bytes[12..14]),
252 high_velocity_chopper_mode: <bool>::from_le_byte_slice(&bytes[14..15]),
253 }
254 }
255}
256
257#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
258pub struct SpreadcycleConfiguration {
259 pub slow_decay_duration: u8,
260 pub enable_random_slow_decay: bool,
261 pub fast_decay_duration: u8,
262 pub hysteresis_start_value: u8,
263 pub hysteresis_end_value: i8,
264 pub sine_wave_offset: i8,
265 pub chopper_mode: u8,
266 pub comparator_blank_time: u8,
267 pub fast_decay_without_comparator: bool,
268}
269impl FromByteSlice for SpreadcycleConfiguration {
270 fn bytes_expected() -> usize { 9 }
271 fn from_le_byte_slice(bytes: &[u8]) -> SpreadcycleConfiguration {
272 SpreadcycleConfiguration {
273 slow_decay_duration: <u8>::from_le_byte_slice(&bytes[0..1]),
274 enable_random_slow_decay: <bool>::from_le_byte_slice(&bytes[1..2]),
275 fast_decay_duration: <u8>::from_le_byte_slice(&bytes[2..3]),
276 hysteresis_start_value: <u8>::from_le_byte_slice(&bytes[3..4]),
277 hysteresis_end_value: <i8>::from_le_byte_slice(&bytes[4..5]),
278 sine_wave_offset: <i8>::from_le_byte_slice(&bytes[5..6]),
279 chopper_mode: <u8>::from_le_byte_slice(&bytes[6..7]),
280 comparator_blank_time: <u8>::from_le_byte_slice(&bytes[7..8]),
281 fast_decay_without_comparator: <bool>::from_le_byte_slice(&bytes[8..9]),
282 }
283 }
284}
285
286#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
287pub struct StealthConfiguration {
288 pub enable_stealth: bool,
289 pub amplitude: u8,
290 pub gradient: u8,
291 pub enable_autoscale: bool,
292 pub force_symmetric: bool,
293 pub freewheel_mode: u8,
294}
295impl FromByteSlice for StealthConfiguration {
296 fn bytes_expected() -> usize { 6 }
297 fn from_le_byte_slice(bytes: &[u8]) -> StealthConfiguration {
298 StealthConfiguration {
299 enable_stealth: <bool>::from_le_byte_slice(&bytes[0..1]),
300 amplitude: <u8>::from_le_byte_slice(&bytes[1..2]),
301 gradient: <u8>::from_le_byte_slice(&bytes[2..3]),
302 enable_autoscale: <bool>::from_le_byte_slice(&bytes[3..4]),
303 force_symmetric: <bool>::from_le_byte_slice(&bytes[4..5]),
304 freewheel_mode: <u8>::from_le_byte_slice(&bytes[5..6]),
305 }
306 }
307}
308
309#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
310pub struct CoolstepConfiguration {
311 pub minimum_stallguard_value: u8,
312 pub maximum_stallguard_value: u8,
313 pub current_up_step_width: u8,
314 pub current_down_step_width: u8,
315 pub minimum_current: u8,
316 pub stallguard_threshold_value: i8,
317 pub stallguard_mode: u8,
318}
319impl FromByteSlice for CoolstepConfiguration {
320 fn bytes_expected() -> usize { 7 }
321 fn from_le_byte_slice(bytes: &[u8]) -> CoolstepConfiguration {
322 CoolstepConfiguration {
323 minimum_stallguard_value: <u8>::from_le_byte_slice(&bytes[0..1]),
324 maximum_stallguard_value: <u8>::from_le_byte_slice(&bytes[1..2]),
325 current_up_step_width: <u8>::from_le_byte_slice(&bytes[2..3]),
326 current_down_step_width: <u8>::from_le_byte_slice(&bytes[3..4]),
327 minimum_current: <u8>::from_le_byte_slice(&bytes[4..5]),
328 stallguard_threshold_value: <i8>::from_le_byte_slice(&bytes[5..6]),
329 stallguard_mode: <u8>::from_le_byte_slice(&bytes[6..7]),
330 }
331 }
332}
333
334#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
335pub struct MiscConfiguration {
336 pub disable_short_to_ground_protection: bool,
337 pub synchronize_phase_frequency: u8,
338}
339impl FromByteSlice for MiscConfiguration {
340 fn bytes_expected() -> usize { 2 }
341 fn from_le_byte_slice(bytes: &[u8]) -> MiscConfiguration {
342 MiscConfiguration {
343 disable_short_to_ground_protection: <bool>::from_le_byte_slice(&bytes[0..1]),
344 synchronize_phase_frequency: <u8>::from_le_byte_slice(&bytes[1..2]),
345 }
346 }
347}
348
349#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
350pub struct DriverStatus {
351 pub open_load: u8,
352 pub short_to_ground: u8,
353 pub over_temperature: u8,
354 pub motor_stalled: bool,
355 pub actual_motor_current: u8,
356 pub full_step_active: bool,
357 pub stallguard_result: u8,
358 pub stealth_voltage_amplitude: u8,
359}
360impl FromByteSlice for DriverStatus {
361 fn bytes_expected() -> usize { 8 }
362 fn from_le_byte_slice(bytes: &[u8]) -> DriverStatus {
363 DriverStatus {
364 open_load: <u8>::from_le_byte_slice(&bytes[0..1]),
365 short_to_ground: <u8>::from_le_byte_slice(&bytes[1..2]),
366 over_temperature: <u8>::from_le_byte_slice(&bytes[2..3]),
367 motor_stalled: <bool>::from_le_byte_slice(&bytes[3..4]),
368 actual_motor_current: <u8>::from_le_byte_slice(&bytes[4..5]),
369 full_step_active: <bool>::from_le_byte_slice(&bytes[5..6]),
370 stallguard_result: <u8>::from_le_byte_slice(&bytes[6..7]),
371 stealth_voltage_amplitude: <u8>::from_le_byte_slice(&bytes[7..8]),
372 }
373 }
374}
375
376#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
377pub struct AllData {
378 pub current_velocity: u16,
379 pub current_position: i32,
380 pub remaining_steps: i32,
381 pub stack_voltage: u16,
382 pub external_voltage: u16,
383 pub current_consumption: u16,
384}
385impl FromByteSlice for AllData {
386 fn bytes_expected() -> usize { 16 }
387 fn from_le_byte_slice(bytes: &[u8]) -> AllData {
388 AllData {
389 current_velocity: <u16>::from_le_byte_slice(&bytes[0..2]),
390 current_position: <i32>::from_le_byte_slice(&bytes[2..6]),
391 remaining_steps: <i32>::from_le_byte_slice(&bytes[6..10]),
392 stack_voltage: <u16>::from_le_byte_slice(&bytes[10..12]),
393 external_voltage: <u16>::from_le_byte_slice(&bytes[12..14]),
394 current_consumption: <u16>::from_le_byte_slice(&bytes[14..16]),
395 }
396 }
397}
398
399#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
400pub struct AllDataEvent {
401 pub current_velocity: u16,
402 pub current_position: i32,
403 pub remaining_steps: i32,
404 pub stack_voltage: u16,
405 pub external_voltage: u16,
406 pub current_consumption: u16,
407}
408impl FromByteSlice for AllDataEvent {
409 fn bytes_expected() -> usize { 16 }
410 fn from_le_byte_slice(bytes: &[u8]) -> AllDataEvent {
411 AllDataEvent {
412 current_velocity: <u16>::from_le_byte_slice(&bytes[0..2]),
413 current_position: <i32>::from_le_byte_slice(&bytes[2..6]),
414 remaining_steps: <i32>::from_le_byte_slice(&bytes[6..10]),
415 stack_voltage: <u16>::from_le_byte_slice(&bytes[10..12]),
416 external_voltage: <u16>::from_le_byte_slice(&bytes[12..14]),
417 current_consumption: <u16>::from_le_byte_slice(&bytes[14..16]),
418 }
419 }
420}
421
422#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
423pub struct NewStateEvent {
424 pub state_new: u8,
425 pub state_previous: u8,
426}
427impl FromByteSlice for NewStateEvent {
428 fn bytes_expected() -> usize { 2 }
429 fn from_le_byte_slice(bytes: &[u8]) -> NewStateEvent {
430 NewStateEvent { state_new: <u8>::from_le_byte_slice(&bytes[0..1]), state_previous: <u8>::from_le_byte_slice(&bytes[1..2]) }
431 }
432}
433
434#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
435pub struct SpitfpBaudrateConfig {
436 pub enable_dynamic_baudrate: bool,
437 pub minimum_dynamic_baudrate: u32,
438}
439impl FromByteSlice for SpitfpBaudrateConfig {
440 fn bytes_expected() -> usize { 5 }
441 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
442 SpitfpBaudrateConfig {
443 enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
444 minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
445 }
446 }
447}
448
449#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
450pub struct SpitfpErrorCount {
451 pub error_count_ack_checksum: u32,
452 pub error_count_message_checksum: u32,
453 pub error_count_frame: u32,
454 pub error_count_overflow: u32,
455}
456impl FromByteSlice for SpitfpErrorCount {
457 fn bytes_expected() -> usize { 16 }
458 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
459 SpitfpErrorCount {
460 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
461 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
462 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
463 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
464 }
465 }
466}
467
468#[derive(Clone)]
469pub struct Protocol1BrickletName {
470 pub protocol_version: u8,
471 pub firmware_version: [u8; 3],
472 pub name: String,
473}
474impl FromByteSlice for Protocol1BrickletName {
475 fn bytes_expected() -> usize { 44 }
476 fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
477 Protocol1BrickletName {
478 protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
479 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
480 name: <String>::from_le_byte_slice(&bytes[4..44]),
481 }
482 }
483}
484
485#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
486pub struct Identity {
487 pub uid: String,
488 pub connected_uid: String,
489 pub position: char,
490 pub hardware_version: [u8; 3],
491 pub firmware_version: [u8; 3],
492 pub device_identifier: u16,
493}
494impl FromByteSlice for Identity {
495 fn bytes_expected() -> usize { 25 }
496 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
497 Identity {
498 uid: <String>::from_le_byte_slice(&bytes[0..8]),
499 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
500 position: <char>::from_le_byte_slice(&bytes[16..17]),
501 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
502 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
503 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
504 }
505 }
506}
507
508#[derive(Clone)]
510pub struct SilentStepperBrick {
511 device: Device,
512}
513impl SilentStepperBrick {
514 pub const DEVICE_IDENTIFIER: u16 = 19;
515 pub const DEVICE_DISPLAY_NAME: &'static str = "Silent Stepper Brick";
516 pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> SilentStepperBrick {
518 let mut result = SilentStepperBrick { device: Device::new([2, 0, 1], uid, req_sender, 0) };
519 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetMaxVelocity) as usize] = ResponseExpectedFlag::False;
520 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetMaxVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
521 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetCurrentVelocity) as usize] =
522 ResponseExpectedFlag::AlwaysTrue;
523 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetSpeedRamping) as usize] = ResponseExpectedFlag::False;
524 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSpeedRamping) as usize] = ResponseExpectedFlag::AlwaysTrue;
525 result.device.response_expected[u8::from(SilentStepperBrickFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
526 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetCurrentPosition) as usize] = ResponseExpectedFlag::False;
527 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetCurrentPosition) as usize] =
528 ResponseExpectedFlag::AlwaysTrue;
529 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetTargetPosition) as usize] = ResponseExpectedFlag::False;
530 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetTargetPosition) as usize] =
531 ResponseExpectedFlag::AlwaysTrue;
532 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetSteps) as usize] = ResponseExpectedFlag::False;
533 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSteps) as usize] = ResponseExpectedFlag::AlwaysTrue;
534 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetRemainingSteps) as usize] =
535 ResponseExpectedFlag::AlwaysTrue;
536 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetStepConfiguration) as usize] = ResponseExpectedFlag::False;
537 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetStepConfiguration) as usize] =
538 ResponseExpectedFlag::AlwaysTrue;
539 result.device.response_expected[u8::from(SilentStepperBrickFunction::DriveForward) as usize] = ResponseExpectedFlag::False;
540 result.device.response_expected[u8::from(SilentStepperBrickFunction::DriveBackward) as usize] = ResponseExpectedFlag::False;
541 result.device.response_expected[u8::from(SilentStepperBrickFunction::Stop) as usize] = ResponseExpectedFlag::False;
542 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetStackInputVoltage) as usize] =
543 ResponseExpectedFlag::AlwaysTrue;
544 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetExternalInputVoltage) as usize] =
545 ResponseExpectedFlag::AlwaysTrue;
546 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetMotorCurrent) as usize] = ResponseExpectedFlag::False;
547 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetMotorCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
548 result.device.response_expected[u8::from(SilentStepperBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
549 result.device.response_expected[u8::from(SilentStepperBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
550 result.device.response_expected[u8::from(SilentStepperBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
551 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetBasicConfiguration) as usize] = ResponseExpectedFlag::False;
552 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetBasicConfiguration) as usize] =
553 ResponseExpectedFlag::AlwaysTrue;
554 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetSpreadcycleConfiguration) as usize] =
555 ResponseExpectedFlag::False;
556 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSpreadcycleConfiguration) as usize] =
557 ResponseExpectedFlag::AlwaysTrue;
558 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetStealthConfiguration) as usize] =
559 ResponseExpectedFlag::False;
560 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetStealthConfiguration) as usize] =
561 ResponseExpectedFlag::AlwaysTrue;
562 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetCoolstepConfiguration) as usize] =
563 ResponseExpectedFlag::False;
564 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetCoolstepConfiguration) as usize] =
565 ResponseExpectedFlag::AlwaysTrue;
566 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetMiscConfiguration) as usize] = ResponseExpectedFlag::False;
567 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetMiscConfiguration) as usize] =
568 ResponseExpectedFlag::AlwaysTrue;
569 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetDriverStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
570 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
571 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetMinimumVoltage) as usize] =
572 ResponseExpectedFlag::AlwaysTrue;
573 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetTimeBase) as usize] = ResponseExpectedFlag::False;
574 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetTimeBase) as usize] = ResponseExpectedFlag::AlwaysTrue;
575 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetAllData) as usize] = ResponseExpectedFlag::AlwaysTrue;
576 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetAllDataPeriod) as usize] = ResponseExpectedFlag::True;
577 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetAllDataPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
578 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetSpitfpBaudrateConfig) as usize] =
579 ResponseExpectedFlag::False;
580 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSpitfpBaudrateConfig) as usize] =
581 ResponseExpectedFlag::AlwaysTrue;
582 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSendTimeoutCount) as usize] =
583 ResponseExpectedFlag::AlwaysTrue;
584 result.device.response_expected[u8::from(SilentStepperBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
585 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSpitfpBaudrate) as usize] =
586 ResponseExpectedFlag::AlwaysTrue;
587 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetSpitfpErrorCount) as usize] =
588 ResponseExpectedFlag::AlwaysTrue;
589 result.device.response_expected[u8::from(SilentStepperBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
590 result.device.response_expected[u8::from(SilentStepperBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
591 result.device.response_expected[u8::from(SilentStepperBrickFunction::IsStatusLedEnabled) as usize] =
592 ResponseExpectedFlag::AlwaysTrue;
593 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetProtocol1BrickletName) as usize] =
594 ResponseExpectedFlag::AlwaysTrue;
595 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetChipTemperature) as usize] =
596 ResponseExpectedFlag::AlwaysTrue;
597 result.device.response_expected[u8::from(SilentStepperBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
598 result.device.response_expected[u8::from(SilentStepperBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
599 result.device.response_expected[u8::from(SilentStepperBrickFunction::ReadBrickletPlugin) as usize] =
600 ResponseExpectedFlag::AlwaysTrue;
601 result.device.response_expected[u8::from(SilentStepperBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
602 result
603 }
604
605 pub fn get_response_expected(&mut self, fun: SilentStepperBrickFunction) -> Result<bool, GetResponseExpectedError> {
620 self.device.get_response_expected(u8::from(fun))
621 }
622
623 pub fn set_response_expected(
632 &mut self,
633 fun: SilentStepperBrickFunction,
634 response_expected: bool,
635 ) -> Result<(), SetResponseExpectedError> {
636 self.device.set_response_expected(u8::from(fun), response_expected)
637 }
638
639 pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
641
642 pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
645
646 pub fn get_under_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
651 self.device.get_callback_receiver(u8::from(SilentStepperBrickFunction::CallbackUnderVoltage))
652 }
653
654 pub fn get_position_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<i32> {
663 self.device.get_callback_receiver(u8::from(SilentStepperBrickFunction::CallbackPositionReached))
664 }
665
666 pub fn get_all_data_callback_receiver(&self) -> ConvertingCallbackReceiver<AllDataEvent> {
671 self.device.get_callback_receiver(u8::from(SilentStepperBrickFunction::CallbackAllData))
672 }
673
674 pub fn get_new_state_callback_receiver(&self) -> ConvertingCallbackReceiver<NewStateEvent> {
677 self.device.get_callback_receiver(u8::from(SilentStepperBrickFunction::CallbackNewState))
678 }
679
680 pub fn set_max_velocity(&self, velocity: u16) -> ConvertingReceiver<()> {
686 let mut payload = vec![0; 2];
687 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(velocity));
688
689 self.device.set(u8::from(SilentStepperBrickFunction::SetMaxVelocity), payload)
690 }
691
692 pub fn get_max_velocity(&self) -> ConvertingReceiver<u16> {
694 let payload = vec![0; 0];
695
696 self.device.get(u8::from(SilentStepperBrickFunction::GetMaxVelocity), payload)
697 }
698
699 pub fn get_current_velocity(&self) -> ConvertingReceiver<u16> {
701 let payload = vec![0; 0];
702
703 self.device.get(u8::from(SilentStepperBrickFunction::GetCurrentVelocity), payload)
704 }
705
706 pub fn set_speed_ramping(&self, acceleration: u16, deacceleration: u16) -> ConvertingReceiver<()> {
717 let mut payload = vec![0; 4];
718 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(acceleration));
719 payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(deacceleration));
720
721 self.device.set(u8::from(SilentStepperBrickFunction::SetSpeedRamping), payload)
722 }
723
724 pub fn get_speed_ramping(&self) -> ConvertingReceiver<SpeedRamping> {
727 let payload = vec![0; 0];
728
729 self.device.get(u8::from(SilentStepperBrickFunction::GetSpeedRamping), payload)
730 }
731
732 pub fn full_brake(&self) -> ConvertingReceiver<()> {
741 let payload = vec![0; 0];
742
743 self.device.set(u8::from(SilentStepperBrickFunction::FullBrake), payload)
744 }
745
746 pub fn set_current_position(&self, position: i32) -> ConvertingReceiver<()> {
750 let mut payload = vec![0; 4];
751 payload[0..4].copy_from_slice(&<i32>::to_le_byte_vec(position));
752
753 self.device.set(u8::from(SilentStepperBrickFunction::SetCurrentPosition), payload)
754 }
755
756 pub fn get_current_position(&self) -> ConvertingReceiver<i32> {
762 let payload = vec![0; 0];
763
764 self.device.get(u8::from(SilentStepperBrickFunction::GetCurrentPosition), payload)
765 }
766
767 pub fn set_target_position(&self, position: i32) -> ConvertingReceiver<()> {
777 let mut payload = vec![0; 4];
778 payload[0..4].copy_from_slice(&<i32>::to_le_byte_vec(position));
779
780 self.device.set(u8::from(SilentStepperBrickFunction::SetTargetPosition), payload)
781 }
782
783 pub fn get_target_position(&self) -> ConvertingReceiver<i32> {
785 let payload = vec![0; 0];
786
787 self.device.get(u8::from(SilentStepperBrickFunction::GetTargetPosition), payload)
788 }
789
790 pub fn set_steps(&self, steps: i32) -> ConvertingReceiver<()> {
795 let mut payload = vec![0; 4];
796 payload[0..4].copy_from_slice(&<i32>::to_le_byte_vec(steps));
797
798 self.device.set(u8::from(SilentStepperBrickFunction::SetSteps), payload)
799 }
800
801 pub fn get_steps(&self) -> ConvertingReceiver<i32> {
803 let payload = vec![0; 0];
804
805 self.device.get(u8::from(SilentStepperBrickFunction::GetSteps), payload)
806 }
807
808 pub fn get_remaining_steps(&self) -> ConvertingReceiver<i32> {
813 let payload = vec![0; 0];
814
815 self.device.get(u8::from(SilentStepperBrickFunction::GetRemainingSteps), payload)
816 }
817
818 pub fn set_step_configuration(&self, step_resolution: u8, interpolation: bool) -> ConvertingReceiver<()> {
841 let mut payload = vec![0; 2];
842 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(step_resolution));
843 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(interpolation));
844
845 self.device.set(u8::from(SilentStepperBrickFunction::SetStepConfiguration), payload)
846 }
847
848 pub fn get_step_configuration(&self) -> ConvertingReceiver<StepConfiguration> {
861 let payload = vec![0; 0];
862
863 self.device.get(u8::from(SilentStepperBrickFunction::GetStepConfiguration), payload)
864 }
865
866 pub fn drive_forward(&self) -> ConvertingReceiver<()> {
870 let payload = vec![0; 0];
871
872 self.device.set(u8::from(SilentStepperBrickFunction::DriveForward), payload)
873 }
874
875 pub fn drive_backward(&self) -> ConvertingReceiver<()> {
879 let payload = vec![0; 0];
880
881 self.device.set(u8::from(SilentStepperBrickFunction::DriveBackward), payload)
882 }
883
884 pub fn stop(&self) -> ConvertingReceiver<()> {
887 let payload = vec![0; 0];
888
889 self.device.set(u8::from(SilentStepperBrickFunction::Stop), payload)
890 }
891
892 pub fn get_stack_input_voltage(&self) -> ConvertingReceiver<u16> {
896 let payload = vec![0; 0];
897
898 self.device.get(u8::from(SilentStepperBrickFunction::GetStackInputVoltage), payload)
899 }
900
901 pub fn get_external_input_voltage(&self) -> ConvertingReceiver<u16> {
914 let payload = vec![0; 0];
915
916 self.device.get(u8::from(SilentStepperBrickFunction::GetExternalInputVoltage), payload)
917 }
918
919 pub fn set_motor_current(&self, current: u16) -> ConvertingReceiver<()> {
925 let mut payload = vec![0; 2];
926 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(current));
927
928 self.device.set(u8::from(SilentStepperBrickFunction::SetMotorCurrent), payload)
929 }
930
931 pub fn get_motor_current(&self) -> ConvertingReceiver<u16> {
933 let payload = vec![0; 0];
934
935 self.device.get(u8::from(SilentStepperBrickFunction::GetMotorCurrent), payload)
936 }
937
938 pub fn enable(&self) -> ConvertingReceiver<()> {
941 let payload = vec![0; 0];
942
943 self.device.set(u8::from(SilentStepperBrickFunction::Enable), payload)
944 }
945
946 pub fn disable(&self) -> ConvertingReceiver<()> {
957 let payload = vec![0; 0];
958
959 self.device.set(u8::from(SilentStepperBrickFunction::Disable), payload)
960 }
961
962 pub fn is_enabled(&self) -> ConvertingReceiver<bool> {
964 let payload = vec![0; 0];
965
966 self.device.get(u8::from(SilentStepperBrickFunction::IsEnabled), payload)
967 }
968
969 pub fn set_basic_configuration(
1009 &self,
1010 standstill_current: u16,
1011 motor_run_current: u16,
1012 standstill_delay_time: u16,
1013 power_down_time: u16,
1014 stealth_threshold: u16,
1015 coolstep_threshold: u16,
1016 classic_threshold: u16,
1017 high_velocity_chopper_mode: bool,
1018 ) -> ConvertingReceiver<()> {
1019 let mut payload = vec![0; 15];
1020 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(standstill_current));
1021 payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(motor_run_current));
1022 payload[4..6].copy_from_slice(&<u16>::to_le_byte_vec(standstill_delay_time));
1023 payload[6..8].copy_from_slice(&<u16>::to_le_byte_vec(power_down_time));
1024 payload[8..10].copy_from_slice(&<u16>::to_le_byte_vec(stealth_threshold));
1025 payload[10..12].copy_from_slice(&<u16>::to_le_byte_vec(coolstep_threshold));
1026 payload[12..14].copy_from_slice(&<u16>::to_le_byte_vec(classic_threshold));
1027 payload[14..15].copy_from_slice(&<bool>::to_le_byte_vec(high_velocity_chopper_mode));
1028
1029 self.device.set(u8::from(SilentStepperBrickFunction::SetBasicConfiguration), payload)
1030 }
1031
1032 pub fn get_basic_configuration(&self) -> ConvertingReceiver<BasicConfiguration> {
1034 let payload = vec![0; 0];
1035
1036 self.device.get(u8::from(SilentStepperBrickFunction::GetBasicConfiguration), payload)
1037 }
1038
1039 pub fn set_spreadcycle_configuration(
1083 &self,
1084 slow_decay_duration: u8,
1085 enable_random_slow_decay: bool,
1086 fast_decay_duration: u8,
1087 hysteresis_start_value: u8,
1088 hysteresis_end_value: i8,
1089 sine_wave_offset: i8,
1090 chopper_mode: u8,
1091 comparator_blank_time: u8,
1092 fast_decay_without_comparator: bool,
1093 ) -> ConvertingReceiver<()> {
1094 let mut payload = vec![0; 9];
1095 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slow_decay_duration));
1096 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(enable_random_slow_decay));
1097 payload[2..3].copy_from_slice(&<u8>::to_le_byte_vec(fast_decay_duration));
1098 payload[3..4].copy_from_slice(&<u8>::to_le_byte_vec(hysteresis_start_value));
1099 payload[4..5].copy_from_slice(&<i8>::to_le_byte_vec(hysteresis_end_value));
1100 payload[5..6].copy_from_slice(&<i8>::to_le_byte_vec(sine_wave_offset));
1101 payload[6..7].copy_from_slice(&<u8>::to_le_byte_vec(chopper_mode));
1102 payload[7..8].copy_from_slice(&<u8>::to_le_byte_vec(comparator_blank_time));
1103 payload[8..9].copy_from_slice(&<bool>::to_le_byte_vec(fast_decay_without_comparator));
1104
1105 self.device.set(u8::from(SilentStepperBrickFunction::SetSpreadcycleConfiguration), payload)
1106 }
1107
1108 pub fn get_spreadcycle_configuration(&self) -> ConvertingReceiver<SpreadcycleConfiguration> {
1114 let payload = vec![0; 0];
1115
1116 self.device.get(u8::from(SilentStepperBrickFunction::GetSpreadcycleConfiguration), payload)
1117 }
1118
1119 pub fn set_stealth_configuration(
1149 &self,
1150 enable_stealth: bool,
1151 amplitude: u8,
1152 gradient: u8,
1153 enable_autoscale: bool,
1154 force_symmetric: bool,
1155 freewheel_mode: u8,
1156 ) -> ConvertingReceiver<()> {
1157 let mut payload = vec![0; 6];
1158 payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable_stealth));
1159 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(amplitude));
1160 payload[2..3].copy_from_slice(&<u8>::to_le_byte_vec(gradient));
1161 payload[3..4].copy_from_slice(&<bool>::to_le_byte_vec(enable_autoscale));
1162 payload[4..5].copy_from_slice(&<bool>::to_le_byte_vec(force_symmetric));
1163 payload[5..6].copy_from_slice(&<u8>::to_le_byte_vec(freewheel_mode));
1164
1165 self.device.set(u8::from(SilentStepperBrickFunction::SetStealthConfiguration), payload)
1166 }
1167
1168 pub fn get_stealth_configuration(&self) -> ConvertingReceiver<StealthConfiguration> {
1176 let payload = vec![0; 0];
1177
1178 self.device.get(u8::from(SilentStepperBrickFunction::GetStealthConfiguration), payload)
1179 }
1180
1181 pub fn set_coolstep_configuration(
1223 &self,
1224 minimum_stallguard_value: u8,
1225 maximum_stallguard_value: u8,
1226 current_up_step_width: u8,
1227 current_down_step_width: u8,
1228 minimum_current: u8,
1229 stallguard_threshold_value: i8,
1230 stallguard_mode: u8,
1231 ) -> ConvertingReceiver<()> {
1232 let mut payload = vec![0; 7];
1233 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(minimum_stallguard_value));
1234 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(maximum_stallguard_value));
1235 payload[2..3].copy_from_slice(&<u8>::to_le_byte_vec(current_up_step_width));
1236 payload[3..4].copy_from_slice(&<u8>::to_le_byte_vec(current_down_step_width));
1237 payload[4..5].copy_from_slice(&<u8>::to_le_byte_vec(minimum_current));
1238 payload[5..6].copy_from_slice(&<i8>::to_le_byte_vec(stallguard_threshold_value));
1239 payload[6..7].copy_from_slice(&<u8>::to_le_byte_vec(stallguard_mode));
1240
1241 self.device.set(u8::from(SilentStepperBrickFunction::SetCoolstepConfiguration), payload)
1242 }
1243
1244 pub fn get_coolstep_configuration(&self) -> ConvertingReceiver<CoolstepConfiguration> {
1260 let payload = vec![0; 0];
1261
1262 self.device.get(u8::from(SilentStepperBrickFunction::GetCoolstepConfiguration), payload)
1263 }
1264
1265 pub fn set_misc_configuration(
1279 &self,
1280 disable_short_to_ground_protection: bool,
1281 synchronize_phase_frequency: u8,
1282 ) -> ConvertingReceiver<()> {
1283 let mut payload = vec![0; 2];
1284 payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(disable_short_to_ground_protection));
1285 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(synchronize_phase_frequency));
1286
1287 self.device.set(u8::from(SilentStepperBrickFunction::SetMiscConfiguration), payload)
1288 }
1289
1290 pub fn get_misc_configuration(&self) -> ConvertingReceiver<MiscConfiguration> {
1292 let payload = vec![0; 0];
1293
1294 self.device.get(u8::from(SilentStepperBrickFunction::GetMiscConfiguration), payload)
1295 }
1296
1297 pub fn get_driver_status(&self) -> ConvertingReceiver<DriverStatus> {
1338 let payload = vec![0; 0];
1339
1340 self.device.get(u8::from(SilentStepperBrickFunction::GetDriverStatus), payload)
1341 }
1342
1343 pub fn set_minimum_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
1350 let mut payload = vec![0; 2];
1351 payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(voltage));
1352
1353 self.device.set(u8::from(SilentStepperBrickFunction::SetMinimumVoltage), payload)
1354 }
1355
1356 pub fn get_minimum_voltage(&self) -> ConvertingReceiver<u16> {
1358 let payload = vec![0; 0];
1359
1360 self.device.get(u8::from(SilentStepperBrickFunction::GetMinimumVoltage), payload)
1361 }
1362
1363 pub fn set_time_base(&self, time_base: u32) -> ConvertingReceiver<()> {
1370 let mut payload = vec![0; 4];
1371 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(time_base));
1372
1373 self.device.set(u8::from(SilentStepperBrickFunction::SetTimeBase), payload)
1374 }
1375
1376 pub fn get_time_base(&self) -> ConvertingReceiver<u32> {
1378 let payload = vec![0; 0];
1379
1380 self.device.get(u8::from(SilentStepperBrickFunction::GetTimeBase), payload)
1381 }
1382
1383 pub fn get_all_data(&self) -> ConvertingReceiver<AllData> {
1397 let payload = vec![0; 0];
1398
1399 self.device.get(u8::from(SilentStepperBrickFunction::GetAllData), payload)
1400 }
1401
1402 pub fn set_all_data_period(&self, period: u32) -> ConvertingReceiver<()> {
1405 let mut payload = vec![0; 4];
1406 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
1407
1408 self.device.set(u8::from(SilentStepperBrickFunction::SetAllDataPeriod), payload)
1409 }
1410
1411 pub fn get_all_data_period(&self) -> ConvertingReceiver<u32> {
1413 let payload = vec![0; 0];
1414
1415 self.device.get(u8::from(SilentStepperBrickFunction::GetAllDataPeriod), payload)
1416 }
1417
1418 pub fn set_spitfp_baudrate_config(&self, enable_dynamic_baudrate: bool, minimum_dynamic_baudrate: u32) -> ConvertingReceiver<()> {
1440 let mut payload = vec![0; 5];
1441 payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable_dynamic_baudrate));
1442 payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(minimum_dynamic_baudrate));
1443
1444 self.device.set(u8::from(SilentStepperBrickFunction::SetSpitfpBaudrateConfig), payload)
1445 }
1446
1447 pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
1452 let payload = vec![0; 0];
1453
1454 self.device.get(u8::from(SilentStepperBrickFunction::GetSpitfpBaudrateConfig), payload)
1455 }
1456
1457 pub fn get_send_timeout_count(&self, communication_method: u8) -> ConvertingReceiver<u32> {
1474 let mut payload = vec![0; 1];
1475 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(communication_method));
1476
1477 self.device.get(u8::from(SilentStepperBrickFunction::GetSendTimeoutCount), payload)
1478 }
1479
1480 pub fn set_spitfp_baudrate(&self, bricklet_port: char, baudrate: u32) -> ConvertingReceiver<()> {
1494 let mut payload = vec![0; 5];
1495 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
1496 payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(baudrate));
1497
1498 self.device.set(u8::from(SilentStepperBrickFunction::SetSpitfpBaudrate), payload)
1499 }
1500
1501 pub fn get_spitfp_baudrate(&self, bricklet_port: char) -> ConvertingReceiver<u32> {
1503 let mut payload = vec![0; 1];
1504 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
1505
1506 self.device.get(u8::from(SilentStepperBrickFunction::GetSpitfpBaudrate), payload)
1507 }
1508
1509 pub fn get_spitfp_error_count(&self, bricklet_port: char) -> ConvertingReceiver<SpitfpErrorCount> {
1521 let mut payload = vec![0; 1];
1522 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
1523
1524 self.device.get(u8::from(SilentStepperBrickFunction::GetSpitfpErrorCount), payload)
1525 }
1526
1527 pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
1534 let payload = vec![0; 0];
1535
1536 self.device.set(u8::from(SilentStepperBrickFunction::EnableStatusLed), payload)
1537 }
1538
1539 pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
1546 let payload = vec![0; 0];
1547
1548 self.device.set(u8::from(SilentStepperBrickFunction::DisableStatusLed), payload)
1549 }
1550
1551 pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
1553 let payload = vec![0; 0];
1554
1555 self.device.get(u8::from(SilentStepperBrickFunction::IsStatusLedEnabled), payload)
1556 }
1557
1558 pub fn get_protocol1_bricklet_name(&self, port: char) -> ConvertingReceiver<Protocol1BrickletName> {
1564 let mut payload = vec![0; 1];
1565 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
1566
1567 self.device.get(u8::from(SilentStepperBrickFunction::GetProtocol1BrickletName), payload)
1568 }
1569
1570 pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
1577 let payload = vec![0; 0];
1578
1579 self.device.get(u8::from(SilentStepperBrickFunction::GetChipTemperature), payload)
1580 }
1581
1582 pub fn reset(&self) -> ConvertingReceiver<()> {
1589 let payload = vec![0; 0];
1590
1591 self.device.set(u8::from(SilentStepperBrickFunction::Reset), payload)
1592 }
1593
1594 pub fn write_bricklet_plugin(&self, port: char, offset: u8, chunk: [u8; 32]) -> ConvertingReceiver<()> {
1600 let mut payload = vec![0; 34];
1601 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
1602 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
1603 payload[2..34].copy_from_slice(&<[u8; 32]>::to_le_byte_vec(chunk));
1604
1605 self.device.set(u8::from(SilentStepperBrickFunction::WriteBrickletPlugin), payload)
1606 }
1607
1608 pub fn read_bricklet_plugin(&self, port: char, offset: u8) -> ConvertingReceiver<[u8; 32]> {
1614 let mut payload = vec![0; 2];
1615 payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
1616 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
1617
1618 self.device.get(u8::from(SilentStepperBrickFunction::ReadBrickletPlugin), payload)
1619 }
1620
1621 pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
1630 let payload = vec![0; 0];
1631
1632 self.device.get(u8::from(SilentStepperBrickFunction::GetIdentity), payload)
1633 }
1634}