-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualisationT.c
executable file
·51 lines (40 loc) · 1.26 KB
/
visualisationT.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
#include "visualisationT.h"
/**
* visualisationT
* Send temperatures to external GUI via a file
*/
void visualisationT(temp_t t)
{
FILE *fTemp = NULL;
//Checking for lockfile
if (access(DATA_LOCK_PATH, F_OK) != -1)
{
printf("[ERROR] File %s locked\n", DATA_PATH);
}
else
{
FILE *lock = fopen(DATA_LOCK_PATH, "w"); // Crée le verrou d'accès
if (access(DATA_PATH, F_OK) == -1) {
fTemp = fopen(DATA_PATH, "w+"); // Create the data file
fputs("0.0\n0.0\ntrue\n", fTemp);
fclose(fTemp);
}
#ifdef __linux__
fTemp = fopen(DATA_PATH, "r+"); // Open the data file
#else
fTemp = fopen(DATA_PATH, "r+"); // Open the data file
#endif
if (!fTemp)
{
printf("[ERROR] Failed to open file 'data.txt'\n");
fclose(lock);
remove(DATA_LOCK_PATH);
return;
}
fseek(fTemp, 0, SEEK_SET); //Set cursor to file beginning
fprintf(fTemp, "%.1f\n%.1f\n", t.exterieure, t.interieure);
fclose(fTemp);
fclose(lock); // Remove the file pointer
remove(DATA_LOCK_PATH); // Delete the lock file
}
}