summaryrefslogtreecommitdiff
path: root/legacy/eeze
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@datenfreihafen.org>2012-09-20 15:46:36 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2012-09-20 15:46:36 +0000
commit33e20cf2a0f830b42a8a6b8d0dbeedaae4c13086 (patch)
treebe8f5af9d428dc52f1f58cb6bef0495af0c3fcda /legacy/eeze
parent63c3e6cc3c0f7162d76d4ccb220a29c24c81f959 (diff)
eeze/sensor: Be more failure tolerant in example.
If the sensor does not exist we should not ask for its properties. SVN revision: 76918
Diffstat (limited to 'legacy/eeze')
-rw-r--r--legacy/eeze/src/bin/eeze_sensor_test.c94
1 files changed, 59 insertions, 35 deletions
diff --git a/legacy/eeze/src/bin/eeze_sensor_test.c b/legacy/eeze/src/bin/eeze_sensor_test.c
index c19b7dfa99..a996ef382e 100644
--- a/legacy/eeze/src/bin/eeze_sensor_test.c
+++ b/legacy/eeze/src/bin/eeze_sensor_test.c
@@ -59,51 +59,75 @@ main(void)
59 59
60 printf("=== Test sync reads: ===\n"); 60 printf("=== Test sync reads: ===\n");
61 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC); 61 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
62 if (!sens) printf("can't find an magnetic sensor!\n"); 62 if (sens)
63 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); 63 {
64 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 64 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
65 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 65 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
66 printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); 66 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
67 eeze_sensor_free(sens); 67 printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
68 eeze_sensor_free(sens);
69 }
70 else
71 printf("Could not find a magnetic sensor!\n");
68 72
69 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER); 73 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
70 if (!sens) printf("can't find an accelerometer sensor!\n"); 74 if (sens)
71 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); 75 {
72 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 76 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
73 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 77 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
74 printf("Accel output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); 78 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
75 eeze_sensor_free(sens); 79 printf("Acceleromter output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
80 eeze_sensor_free(sens);
81 }
82 else
83 printf("Could not find an accelerometer sensor!\n");
76 84
77 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION); 85 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
78 if (!sens) printf("can't find an orientation sensor!\n"); 86 if (sens)
79 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); 87 {
80 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 88 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
81 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 89 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
82 printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); 90 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
83 eeze_sensor_free(sens); 91 printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
92 eeze_sensor_free(sens);
93 }
94 else
95 printf("Could not find an orientation sensor!\n");
84 96
85 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE); 97 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
86 if (!sens) printf("can't find an gyroscope sensor!\n"); 98 if (sens)
87 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n"); 99 {
88 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 100 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
89 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 101 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
90 printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp); 102 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
91 eeze_sensor_free(sens); 103 printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
104 eeze_sensor_free(sens);
105 }
106 else
107 printf("Could not find a gyroscope sensor!\n");
92 108
93 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY); 109 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
94 if (!sens) printf("can't find an proximity sensor!\n"); 110 if (sens)
95 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); 111 {
96 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 112 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
97 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 113 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
98 printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp); 114 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
99 eeze_sensor_free(sens); 115 printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp);
116 eeze_sensor_free(sens);
117 }
118 else
119 printf("Could not find a proximity sensor!\n");
100 120
101 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT); 121 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
102 if (!sens) printf("can't find an light sensor!\n"); 122 if (sens)
103 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n"); 123 {
104 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n"); 124 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
105 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n"); 125 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
106 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp); 126 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
127 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
128 }
129 else
130 printf("Could not find a light sensor!\n");
107 131
108 sleep(1); 132 sleep(1);
109 133