-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
93 lines (77 loc) · 1.92 KB
/
function.c
File metadata and controls
93 lines (77 loc) · 1.92 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
/*
* start_buffer.c
*
* Created on: 26 gen 2018
* Author: marco.cossali
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include "search_device.h"
#include "function.h"
// Calculate the frequency of acquisition
int calc_freq(int n_device){
FILE *file;
char path[100];
char str[100];
double d = 0.0f;
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;
}
// Set the length passed like parametr of buffer
void set_buffer_length(int n_device, int length){
FILE *file;
char path[100];
char str[100];
sprintf(str, "%d", length);
sprintf(path, "/sys/bus/iio/devices/iio:device%d/buffer/length", n_device);
file = fopen(path, "w");
fprintf(file, "%s", str);
fclose(file);
}
// Set the watermark passed like parametr of buffer
void set_buffer_watermark(int n_device, int watermark){
FILE *file;
char path[100];
char str[100];
sprintf(str, "%d", watermark);
sprintf(path, "/sys/bus/iio/devices/iio:device%d/buffer/watermark", n_device);
file = fopen(path, "w");
fprintf(file,"%s", str);
fclose(file);
}
// Set enable passed like parametr of buffer to 1 or 0
void set_buffer_enable(int n_device, int enable){
FILE *file;
char path[100];
char str[100];
if(enable == 0 || enable == 1){
sprintf(str, "%d", enable);
sprintf(path, "/sys/bus/iio/devices/iio:device%d/buffer/enable", n_device);
file = fopen(path, "w");
fprintf(file,"%s", str);
fclose(file);
}
else
printf("Insert 1 or 0");
}
// Get length of buffer
int get_buffer_enable(int n_device){
FILE *file;
double d = 0;
char str[1000];
char path[100];
sprintf(path, "/sys/bus/iio/devices/iio:device%d/buffer/enable", n_device);
file = fopen(path, "r");
fscanf(file, "%[^\n]", str);
sscanf(str, "%lf", &d);
fclose(file);
return d;
}