forked from theZiz/ev3c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sensor.c
76 lines (72 loc) · 2.58 KB
/
test_sensor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
The contents of this file are subject to the "do whatever you like"-license.
That means: Do, whatver you want, this file is under public domain. It is an
example for ev3c. Copy it and learn from it for your project and release
it under every license you want. ;-)
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , ziz_at_mailbox.org, http://github.com/theZiz
*/
#include "ev3c.h"
#include <stdio.h>
int main(int argc,char** argv)
{
int i;
//Loading all sensors
ev3_sensor_ptr sensors = ev3_load_sensors();
//I myself have a nxt sound sensor, which I detect here and set the
//correct driver. If you don't have an nxt analog sensor connected
//nothing should happen. If you have another than the sound sensor
//connected the values will be interpreted as sound values. Adjust
//this line in that case.
ev3_driver_sensor(
ev3_search_sensor_by_identifier( sensors, NXT_ANALOG, 0 ),
"lego-nxt-sound"
);
//Interating over the sensors and printing some interesting data
ev3_sensor_ptr sensor = sensors;
while (sensor)
{
printf("==== %s ====\n",sensor->driver_name);
printf("ident: %i\n",sensor->driver_identifier);
printf("sensor: %i\n",sensor->sensor_nr);
printf("port: %i\n",sensor->port);
printf("bin_fd: %i\n",sensor->bin_fd);
printf("data count: %i\n",sensor->data_count);
printf("data format: %i\n",sensor->bin_data_format);
printf("units: %s\n",sensor->units);
printf("decimals: %i\n",sensor->decimals);
printf("poll ms: %i\n",sensor->poll_ms);
printf("mode count: %i\n",sensor->mode_count);
for (i = 0; i < sensor->mode_count; i++)
printf("mode[%i]: %s\n",i,sensor->modes[i]);
printf("active mode: %i\n",sensor->mode);
//If there is more than one mode, let's choose the second one.
if (sensor->mode_count > 1)
ev3_mode_sensor(sensor,1);
//Let's open the sensors ;)
ev3_open_sensor(sensor);
sensor = sensor->next;
}
//Let's do this again, but this time we print the bin and val data
//values for every found sensor for the next 10 seconds
printf("Showing the sensor values for the next 10 seconds\n");
for (i = 0; i < 10; i++)
{
sensor = sensors;
while (sensor)
{
ev3_update_sensor_bin(sensor);
ev3_update_sensor_val(sensor);
printf("%s [%i]: \n",sensor->driver_name,sensor->port);
int j;
for (j = 0; j < sensor->data_count;j++)
printf("\tvalue %i: %i (raw) - %i (formated)\n",j,sensor->bin_data[0].s32,sensor->val_data[0].s32);
sensor = sensor->next;
}
sleep(1);
}
//Let's delete the list in the very end. It will also close the
//sensors
ev3_delete_sensors(sensors);
return 0;
}