Repository navigation
Expand file tree
/
Copy pathlsm303agr_accel.c
More file actions
151 lines (120 loc) · 3.03 KB
/
Copy pathlsm303agr_accel.c
File metadata and controls
151 lines (120 loc) · 3.03 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* lsm303agr_accel.c
*
* Created on: 23 gen 2018
* Author: marco.cossali
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include "lsm303agr_accel.h"
#include "search_device.h"
void get_name_lsm303agr(int n_device){
FILE *file;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/name", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
printf("Name sensor: %s\n", str);
fclose(file);
}
double get_in_accel_x_raw_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_x_raw", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
double get_in_accel_x_scale_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_x_scale", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
double get_in_accel_y_raw_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_y_raw", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
double get_in_accel_y_scale_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_y_scale", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
double get_in_accel_z_raw_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_z_raw", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
double get_in_accel_z_scale_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/in_accel_z_scale", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
int get_sampling_frequency_lsm303agr(int n_device){
FILE *file;
double d = 0.0f;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/sampling_frequency", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}
void set_sampling_frequency_lsm303agr(int n_device, int val_frequenza){
FILE *file;
char str[1000];
char path[100];
sprintf(str, "%d", val_frequenza);
sprintf(path, "/sys/bus/iio/devices/iio:device%d/sampling_frequency", n_device);
file = fopen(path, "w");
fprintf(file,"%s", str);
printf("The new frequency value is: %s\n", str);
fclose(file);
}
void getLIST_sampling_frequency_lsm303agr(){
printf("Values: 1 10 25 50 100 200 400 1600\n");
}