-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate.h
86 lines (77 loc) · 1.88 KB
/
simulate.h
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
#include <math.h>
float simulateFuelLevel(float fuel)
{
if (fuel < 0)
{
return 0;
}
else
{
return fuel - 0.001;
}
}
void *simulateThreadExecute()
{
float a;
while (1)
{
systemStatus.dial.fuelLevel = simulateFuelLevel(systemStatus.dial.fuelLevel);
systemStatus.dial.enginePressure = simulateFlags.simulateOverPressure == 1 ? MAX_ENGINE_PRESSURE + 1 : rand() / (double)RAND_MAX * MAX_ENGINE_PRESSURE;
systemStatus.dial.engineTemperature = simulateFlags.simulateOverTemperature == 1 ? MAX_ENGINE_TEMPERATURE + 1 : rand() / (double)RAND_MAX * MAX_ENGINE_TEMPERATURE;
systemStatus.smoking1 = simulateFlags.simulateSmoke1;
systemStatus.smoking2 = simulateFlags.simulateSmoke2;
sleep(0.3);
}
}
_Bool simulateExecution(int msecs, int timeout_chance)
{
int random_number = rand() % 100 + 1; // 1 to 100
sleep(((float)msecs) / ((float)1000));
return random_number > timeout_chance;
}
void changeSimulateSmoke1()
{
if (simulateFlags.simulateSmoke1)
{
simulateFlags.simulateSmoke1 = 0;
}
else
{
simulateFlags.simulateSmoke1 = 1;
}
systemStatus.smoking1 = simulateFlags.simulateSmoke1;
}
void changeSimulateSmoke2()
{
if (simulateFlags.simulateSmoke2)
{
simulateFlags.simulateSmoke2 = 0;
}
else
{
simulateFlags.simulateSmoke2 = 1;
}
systemStatus.smoking2 = simulateFlags.simulateSmoke2;
}
void changeSimulateOverPressure()
{
if (simulateFlags.simulateOverPressure)
{
simulateFlags.simulateOverPressure = 0;
}
else
{
simulateFlags.simulateOverPressure = 1;
}
}
void changeSimulateOverTemperature()
{
if (simulateFlags.simulateOverTemperature)
{
simulateFlags.simulateOverTemperature = 0;
}
else
{
simulateFlags.simulateOverTemperature = 1;
}
}