eeze/sensor: Be more failure tolerant in example.

If the sensor does not exist we should not ask for its properties.

SVN revision: 76918
This commit is contained in:
Stefan Schmidt 2012-09-20 15:46:36 +00:00
parent 63c3e6cc3c
commit 33e20cf2a0
1 changed files with 59 additions and 35 deletions

View File

@ -59,51 +59,75 @@ main(void)
printf("=== Test sync reads: ===\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
if (!sens) printf("can't find an magnetic sensor!\n");
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
}
else
printf("Could not find a magnetic sensor!\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
if (!sens) printf("can't find an accelerometer sensor!\n");
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Accel output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Acceleromter output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
}
else
printf("Could not find an accelerometer sensor!\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
if (!sens) printf("can't find an orientation sensor!\n");
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
}
else
printf("Could not find an orientation sensor!\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
if (!sens) printf("can't find an gyroscope sensor!\n");
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
eeze_sensor_free(sens);
}
else
printf("Could not find a gyroscope sensor!\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
if (!sens) printf("can't find an proximity sensor!\n");
if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp);
eeze_sensor_free(sens);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp);
eeze_sensor_free(sens);
}
else
printf("Could not find a proximity sensor!\n");
sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
if (!sens) printf("can't find an light sensor!\n");
if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
if (sens)
{
if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
}
else
printf("Could not find a light sensor!\n");
sleep(1);