246
246
EXPECT_FLOAT_EQ(reading->z(), -0.5);
249
TESTP_F(SimBackendTest, OrientationEvents, {
250
/* test some "parallel to coordinate axes" conditions, as well as some
251
* ~ 45 degrees angles; we want a hysteresis there, i. e. it should not
252
* flip back and forth when wiggling around the diagonals but only when
253
* it's mostly pointing towards an axis
255
* http://qt-project.org/doc/qt-5.1/qtsensors/qaccelerometerreading.html
257
set_data("create accel -500 500 0.1\n"
258
"10 accel 0 9.8 0\n" // TopUp
259
"100 accel 6.9 6.9 0\n" // turning left
260
"150 accel 8.1 2.3 0\n" // almost turned left, should trigger RightUp
261
"50 accel -7.1 6.9 0\n" // turn right, wiggle around diagonal several times
262
"30 accel -6.5 7.1 0\n"
263
"30 accel -7.0 6.0 0\n"
264
"30 accel -7.0 6.0 0\n"
265
"30 accel -8.0 3.0 0\n" // finally turn right enough to trigger LeftUp
266
"30 accel 0 -9.8 0\n" // TopDown
267
"30 accel 0 0 9.8\n" // FaceUp
268
"30 accel 0 0 -9.8\n" // FaceDown
271
orientation_sensor->setIdentifier("core.orientation");
273
QObject::connect(orientation_sensor, &QOrientationSensor::readingChanged, [=]() {
274
auto r = orientation_sensor->reading();
275
orientation_events.push({r->orientation(), chrono::system_clock::now()});
278
EXPECT_EQ(orientation_sensor->start(), true);
280
start_time = chrono::system_clock::now();
281
run_events(550); // must be long enough to catch all events
283
EXPECT_EQ(orientation_events.size(), 6);
285
check_orientation_event(QOrientationReading::TopUp, 10);
286
check_orientation_event(QOrientationReading::RightUp, 260);
287
check_orientation_event(QOrientationReading::LeftUp, 430);
288
check_orientation_event(QOrientationReading::TopDown, 460);
289
check_orientation_event(QOrientationReading::FaceUp, 490);
290
check_orientation_event(QOrientationReading::FaceDown, 520);
293
249
TESTP_F(SimBackendTest, OrientationReading, {
294
set_data("create accel -500 500 0.1\n"
295
"10 accel 0 9.8 0\n" // TopUp
296
"20 accel 6.9 6.9 0\n" // turning left
297
"20 accel 8.1 2.3 0\n" // almost turned left, should trigger RightUp
250
set_data("create accel -500 500 0.001\n"
251
"70 accel 0.347 9.768 0.162\n"
252
"70 accel -0.600 9.947 0.174\n"
253
"70 accel -0.885 11.061 -0.177\n"
254
"70 accel -2.121 10.397 -0.468\n"
255
"70 accel -4.242 8.664 -0.023\n"
256
"70 accel -5.882 7.633 0.169\n"
257
"70 accel -7.031 5.822 -0.268\n"
258
"70 accel -8.138 3.775 0.564\n"
259
"70 accel -9.616 1.854 1.981\n"
260
"70 accel -9.562 -0.195 1.138\n"
261
"70 accel -10.373 -0.597 1.802\n"
300
265
orientation_sensor->setIdentifier("core.orientation");
302
267
EXPECT_EQ(orientation_sensor->start(), true);
305
270
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::Undefined);
307
// TopUp after first event
309
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::TopUp);
311
// not changed for "turning left" yet
313
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::TopUp);
315
// but changed after "almost turned left"
317
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::RightUp);
272
// Right up after stream of svents
274
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::LeftUp);