@@ -79,17 +79,22 @@ where
79
79
///
80
80
/// Usage example:
81
81
/// ```
82
- /// # use embedded_hal_mock::pin::Mock as PinMock;
83
- /// # use embedded_hal_mock::pin::Transaction as PinTransaction;
82
+ /// # use embedded_hal_mock::eh0:: pin::Mock as PinMock;
83
+ /// # use embedded_hal_mock::eh0:: pin::Transaction as PinTransaction;
84
84
/// # let motor_a_in1 = PinMock::new([]);
85
+ /// # let mut motor_a_in1_ = motor_a_in1.clone();
85
86
/// # let motor_a_in2 = PinMock::new([]);
86
- /// # let motor_a_pwm_expectations = [PinTransaction::enable()];
87
- /// # let motor_a_pwm = PinMock::new(&motor_a_pwm_expectations);
87
+ /// # let mut motor_a_in2_ = motor_a_in2.clone();
88
+ /// # let motor_a_pwm = PinMock::new(&[PinTransaction::enable()]);
89
+ /// # let mut motor_a_pwm_ = motor_a_pwm.clone();
88
90
/// # let motor_b_in1 = PinMock::new([]);
91
+ /// # let mut motor_b_in1_ = motor_b_in1.clone();
89
92
/// # let motor_b_in2 = PinMock::new([]);
90
- /// # let motor_b_pwm_expectations = [PinTransaction::enable()];
91
- /// # let motor_b_pwm = PinMock::new(&motor_a_pwm_expectations);
93
+ /// # let mut motor_b_in2_ = motor_b_in2.clone();
94
+ /// # let motor_b_pwm = PinMock::new(&[PinTransaction::enable()]);
95
+ /// # let mut motor_b_pwm_ = motor_b_pwm.clone();
92
96
/// # let standby = PinMock::new([]);
97
+ /// # let mut standby_ = standby.clone();
93
98
/// use tb6612fng::Tb6612fng;
94
99
///
95
100
/// let controller = Tb6612fng::new(
@@ -101,6 +106,14 @@ where
101
106
/// motor_b_pwm,
102
107
/// standby,
103
108
/// );
109
+ ///
110
+ /// # motor_a_in1_.done();
111
+ /// # motor_a_in2_.done();
112
+ /// # motor_a_pwm_.done();
113
+ /// # motor_b_in1_.done();
114
+ /// # motor_b_in2_.done();
115
+ /// # motor_b_pwm_.done();
116
+ /// # standby_.done();
104
117
/// ```
105
118
pub fn new (
106
119
motor_a_in1 : MAIN1 ,
@@ -156,19 +169,25 @@ where
156
169
///
157
170
/// Usage example:
158
171
/// ```
159
- /// # use embedded_hal_mock::pin::Mock as PinMock;
160
- /// # use embedded_hal_mock::pin::Transaction as PinTransaction;
172
+ /// # use embedded_hal_mock::eh0:: pin::Mock as PinMock;
173
+ /// # use embedded_hal_mock::eh0:: pin::Transaction as PinTransaction;
161
174
/// # let motor_in1 = PinMock::new([]);
175
+ /// # let mut motor_in1_ = motor_in1.clone();
162
176
/// # let motor_in2 = PinMock::new([]);
163
- /// # let motor_pwm_expectations = [PinTransaction::enable()];
164
- /// # let motor_pwm = PinMock::new(&motor_pwm_expectations);
177
+ /// # let mut motor_in2_ = motor_in2.clone();
178
+ /// # let motor_pwm = PinMock::new(&[PinTransaction::enable()]);
179
+ /// # let mut motor_pwm_ = motor_pwm.clone();
165
180
/// use tb6612fng::Motor;
166
181
///
167
182
/// let motor = Motor::new(
168
183
/// motor_in1,
169
184
/// motor_in2,
170
185
/// motor_pwm,
171
186
/// );
187
+ ///
188
+ /// # motor_in1_.done();
189
+ /// # motor_in2_.done();
190
+ /// # motor_pwm_.done();
172
191
/// ```
173
192
pub fn new ( in1 : IN1 , in2 : IN2 , mut pwm : PWM ) -> Motor < IN1 , IN2 , PWM > {
174
193
pwm. enable ( ) ;
@@ -275,9 +294,9 @@ where
275
294
#[ cfg( test) ]
276
295
mod tests {
277
296
use crate :: { DriveCommand , DriveError , Motor } ;
278
- use embedded_hal_mock:: pin:: State :: { High , Low } ;
279
- use embedded_hal_mock:: pin:: Transaction as PinTransaction ;
280
- use embedded_hal_mock:: pin:: { Mock as PinMock , PwmDuty } ;
297
+ use embedded_hal_mock:: eh0 :: pin:: State :: { High , Low } ;
298
+ use embedded_hal_mock:: eh0 :: pin:: Transaction as PinTransaction ;
299
+ use embedded_hal_mock:: eh0 :: pin:: { Mock as PinMock , PwmDuty } ;
281
300
282
301
#[ test]
283
302
fn test_motor_stop ( ) {
@@ -289,16 +308,20 @@ mod tests {
289
308
PinTransaction :: get_max_duty ( max_duty) ,
290
309
PinTransaction :: set_duty ( 0 ) ,
291
310
] ;
292
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
293
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
294
- let motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
311
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
312
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
313
+ let mut motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
295
314
296
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
315
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
297
316
298
317
motor. stop ( ) ;
299
318
300
319
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Stop ) ;
301
320
assert_eq ! ( motor. current_speed( ) , 0 ) ;
321
+
322
+ motor_in1. done ( ) ;
323
+ motor_in2. done ( ) ;
324
+ motor_pwm. done ( ) ;
302
325
}
303
326
304
327
#[ test]
@@ -311,16 +334,20 @@ mod tests {
311
334
PinTransaction :: get_max_duty ( max_duty) ,
312
335
PinTransaction :: set_duty ( 0 ) ,
313
336
] ;
314
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
315
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
316
- let motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
337
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
338
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
339
+ let mut motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
317
340
318
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
341
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
319
342
320
343
motor. brake ( ) ;
321
344
322
345
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Brake ) ;
323
346
assert_eq ! ( motor. current_speed( ) , 0 ) ;
347
+
348
+ motor_in1. done ( ) ;
349
+ motor_in2. done ( ) ;
350
+ motor_pwm. done ( ) ;
324
351
}
325
352
326
353
#[ test]
@@ -334,16 +361,20 @@ mod tests {
334
361
PinTransaction :: get_max_duty ( max_duty) ,
335
362
PinTransaction :: set_duty ( speed as PwmDuty ) ,
336
363
] ;
337
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
338
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
339
- let motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
364
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
365
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
366
+ let mut motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
340
367
341
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
368
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
342
369
343
370
motor. drive_forward ( speed) . expect ( "speed can be set" ) ;
344
371
345
372
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Forward ( 100 ) ) ;
346
373
assert_eq ! ( motor. current_speed( ) , speed as i8 ) ;
374
+
375
+ motor_in1. done ( ) ;
376
+ motor_in2. done ( ) ;
377
+ motor_pwm. done ( ) ;
347
378
}
348
379
349
380
#[ test]
@@ -357,33 +388,32 @@ mod tests {
357
388
PinTransaction :: get_max_duty ( max_duty) ,
358
389
PinTransaction :: set_duty ( speed as PwmDuty ) ,
359
390
] ;
360
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
361
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
362
- let motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
391
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
392
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
393
+ let mut motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
363
394
364
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
395
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
365
396
366
397
motor. drive_backwards ( speed) . expect ( "speed can be set" ) ;
367
398
368
399
assert_eq ! ( * motor. current_drive_command( ) , DriveCommand :: Backwards ( 100 ) ) ;
369
400
assert_eq ! ( motor. current_speed( ) , -( speed as i8 ) ) ;
401
+
402
+ motor_in1. done ( ) ;
403
+ motor_in2. done ( ) ;
404
+ motor_pwm. done ( ) ;
370
405
}
371
406
372
407
#[ test]
373
408
fn test_motor_drive_invalid_speed ( ) {
374
- let max_duty = 100 ;
375
- let motor_in1_expectations = [ PinTransaction :: set ( Low ) ] ;
376
- let motor_in2_expectations = [ PinTransaction :: set ( High ) ] ;
377
- let motor_pwm_expectations = [
378
- PinTransaction :: enable ( ) ,
379
- PinTransaction :: get_max_duty ( max_duty) ,
380
- PinTransaction :: set_duty ( 100 ) ,
381
- ] ;
382
- let motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
383
- let motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
384
- let motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
409
+ let motor_in1_expectations = [ ] ;
410
+ let motor_in2_expectations = [ ] ;
411
+ let motor_pwm_expectations = [ PinTransaction :: enable ( ) ] ;
412
+ let mut motor_in1 = PinMock :: new ( & motor_in1_expectations) ;
413
+ let mut motor_in2 = PinMock :: new ( & motor_in2_expectations) ;
414
+ let mut motor_pwm = PinMock :: new ( & motor_pwm_expectations) ;
385
415
386
- let mut motor = Motor :: new ( motor_in1, motor_in2, motor_pwm) ;
416
+ let mut motor = Motor :: new ( motor_in1. clone ( ) , motor_in2. clone ( ) , motor_pwm. clone ( ) ) ;
387
417
388
418
let current_drive_command = motor. current_drive_command ( ) . clone ( ) ;
389
419
let current_speed = motor. current_speed ( ) ;
@@ -398,5 +428,9 @@ mod tests {
398
428
// this should still be what was set before the invalid command
399
429
assert_eq ! ( * motor. current_drive_command( ) , current_drive_command) ;
400
430
assert_eq ! ( motor. current_speed( ) , current_speed) ;
431
+
432
+ motor_in1. done ( ) ;
433
+ motor_in2. done ( ) ;
434
+ motor_pwm. done ( ) ;
401
435
}
402
436
}
0 commit comments