/
demo.c
52 lines (40 loc) · 1.37 KB
/
demo.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
#include <stdlib.h>
#include <stdio.h>
#include <forza.h>
// Optional callback for new telemetry data
void on_new_telemetry(ForzaTelemetry *telemetry)
{
printf("\nCallback received new telemetry!\nGear is %d\n", telemetry->gear);
}
int main(void)
{
// Initialize sockets for each game (required)
const int init_error = forza_init();
// Check for initialization error
if (init_error != 0) {
perror("An error occurred during initialization!");
exit(1);
}
// Optionally register the callback
notify_on_new_telemetry(on_new_telemetry);
puts("Initialization Complete");
// Continuously poll, consider moving to another thread
while (1) {
// Poll for new data (should be around 60hz)
const int telemetry_ready = forza_poll();
// If there is new telemetry, callback will be notified
// Check if new telemetry is ready
if (telemetry_ready) {
// Latest telemetry can be retrieved on demand
ForzaTelemetry *telemetry = get_latest_telemetry();
puts("\nRetrieved new telemetry!");
printf("Number of Cylinders is %d\n", telemetry->num_cylinders);
}
}
const int cleanup_error = forza_cleanup();
// Check for cleanup error
if (cleanup_error != 0) {
perror("An error occurred during initialization!");
}
return 0;
}