@@ -89,7 +89,7 @@ static void qenc_emulate_stop(void)
89
89
}
90
90
91
91
static void qenc_emulate_verify_reading (int emulator_period_ms , int emulation_duration_ms ,
92
- bool forward , bool overflow_possible )
92
+ bool forward , bool overflow_expected )
93
93
{
94
94
int rc ;
95
95
struct sensor_value val = {0 };
@@ -107,13 +107,17 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du
107
107
k_msleep (emulation_duration_ms );
108
108
109
109
rc = sensor_sample_fetch (qdec_dev );
110
- zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
110
+
111
+ if (!overflow_expected ) {
112
+ zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
113
+ } else {
114
+ zassert_true (rc == - EOVERFLOW , "Failed to detect overflow" );
115
+ }
111
116
112
117
rc = sensor_channel_get (qdec_dev , SENSOR_CHAN_ROTATION , & val );
113
118
zassert_true (rc == 0 , "Failed to get sample (%d)" , rc );
114
119
115
- TC_PRINT ("QDEC reading: %d\n" , val .val1 );
116
- if (!overflow_possible ) {
120
+ if (!overflow_expected ) {
117
121
zassert_within (val .val1 , expected_reading , delta ,
118
122
"Expected reading: %d, but got: %d" , expected_reading , val .val1 );
119
123
}
@@ -197,6 +201,9 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
197
201
rc = k_sem_take (& sem , K_MSEC (200 ));
198
202
zassert_true (rc == 0 , "qdec handler should be triggered (%d)" , rc );
199
203
204
+ rc = sensor_sample_fetch (qdec_dev );
205
+ zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
206
+
200
207
rc = sensor_channel_get (qdec_dev , SENSOR_CHAN_ROTATION , & val );
201
208
zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
202
209
@@ -241,7 +248,6 @@ ZTEST(qdec_sensor, test_qdec_readings)
241
248
qenc_emulate_verify_reading (10 , 100 , true, false);
242
249
qenc_emulate_verify_reading (2 , 500 , true, false);
243
250
qenc_emulate_verify_reading (10 , 200 , false, false);
244
- /* may lead to overflows but currently driver does not detects that */
245
251
qenc_emulate_verify_reading (1 , 1000 , false, true);
246
252
qenc_emulate_verify_reading (1 , 1000 , true, true);
247
253
}
@@ -313,18 +319,15 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
313
319
/* subsequent calls of sensor_channel_get without calling sensor_sample_fetch
314
320
* should yield the same value
315
321
*/
316
- /* zassert_true(val_first.val1 == val_second.val1,
317
- * "Expected the same readings: %d vs %d",
318
- * val_first.val1,
319
- * val_second.val1);
320
- */
321
- TC_PRINT ("Expected the same readings: %d vs %d - ignore!\n" , val_first .val1 ,
322
- val_second .val1 );
323
- /* zassert_true(val_first.val2 == val_second.val2, "Expected the same readings: %d vs %d",
324
- * val_first.val2, val_second.val2);
325
- */
326
- TC_PRINT ("Expected the same readings: %d vs %d - ignore!\n" , val_first .val2 ,
327
- val_second .val2 );
322
+ zassert_true (val_first .val1 == val_second .val1 ,
323
+ "Expected the same readings: %d vs %d" ,
324
+ val_first .val1 ,
325
+ val_second .val1 );
326
+
327
+ zassert_true (val_first .val2 == val_second .val2 ,
328
+ "Expected the same readings: %d vs %d" ,
329
+ val_first .val2 ,
330
+ val_second .val2 );
328
331
}
329
332
330
333
/**
0 commit comments