forked from NeroReflex/ROGueENEMY
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplatform.c
77 lines (59 loc) · 2.47 KB
/
platform.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
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
#include <asm-generic/errno-base.h>
#include <stdlib.h>
#define PLATFORM_FILE
#include "platform.h"
static const char* const platform_input_path = "/sys/devices/platform/asus-mcu.0/input/mode";
int init_platform(rc71l_platform_t *const platform) {
// if (access(platform_input_path, F_OK) != 0) {
// fprintf(stderr, "Unable to find the MCU platform mode file %s: modes cannot be switched.\n", platform_input_path);
// return -ENOENT;
// }
// FILE* mode_file = fopen(platform_input_path, "r");
// if (mode_file == NULL) {
// fprintf(stderr, "Unable to open the MCU platform mode file %s: modes cannot be switched.\n", platform_input_path);
// return -EINVAL;
// }
// char mode_str[12];
// unsigned long read_bytes = fread((void*)&mode_str[0], 1, sizeof(mode_str), mode_file);
// if (read_bytes < 1) {
// fprintf(stderr, "Unable to read the MCU platform mode file %s: no bytes.\n", platform_input_path);
// fclose(mode_file);
// }
// platform->mode = strtoul(&mode_str[0], NULL, 10);
// fclose(mode_file);
// printf("Asus MCU platform found: current mode %lu\n", platform->mode);
// platform->modes_count = 3;
return 0;
}
int cycle_mode(rc71l_platform_t *const platform) {
char new_mode_str[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
unsigned long new_mode = (platform->mode + 1) % platform->modes_count;
sprintf(new_mode_str, "%lu\n", new_mode);
FILE* mode_file = fopen(platform_input_path, "w");
if (mode_file == NULL) {
fprintf(stderr, "Unable to open the MCU platform mode file %s: modes cannot be switched.\n", platform_input_path);
return -1;
}
size_t len = strlen(new_mode_str);
const int write_bytes = fwrite((void*)&new_mode_str[0], 1, len, mode_file);
if (write_bytes < len) {
fprintf(stderr, "Error writing new mode: expected to write %d bytes, %d written.\n", (int)len, (int)write_bytes);
return -2;
}
platform->mode = new_mode;
fclose(mode_file);
return platform->mode;
}
int is_gamepad_mode(rc71l_platform_t *const platform) {
return platform != NULL ? platform->mode == 0 : 0;
}
int is_mouse_mode(rc71l_platform_t *const platform) {
return platform != NULL ? platform->mode == 1 : 0;
}
int is_macro_mode(rc71l_platform_t *const platform) {
return platform != NULL ? platform->mode == 2 : 0;
}