-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
138 lines (118 loc) · 3.91 KB
/
tests.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdint.h>
//proof of concept for the algorithm to read the data from the eeprom
//this is a simple version of the code that reads a file simulating the eeprom data
//not needed to compile with the main code
enum KeyType
{
KEYBOARD = 0,
CONSUMER = 1,
MACRO = 2
};
struct key
{
enum KeyType type;
uint8_t mod;
uint8_t ammount;
char code[10];
uint8_t last;
};
int main()
{
printf("reading file\n");
//FILE *file = fopen("flashdata.bin", "rb"); // Open file for reading in binary mode
FILE *file = fopen("Consumer.bin", "rb"); // Open file for reading in binary mode
//FILE *file = fopen("Keyboard.bin", "rb"); // Open file for reading in binary mode
//FILE *file = fopen("Macros.bin", "rb"); // Open file for reading in binary mode
if (!file)
{
printf("Error opening file\n");
return 1;
}
struct key keys[8];
int i, j;
int index = 0;
int incremental = 12; // Assuming 12 bytes per record
printf("starting first for\n");
for (i = 0; i < 8; i++)
{
uint8_t type_byte;
fread(&type_byte, sizeof(uint8_t), 1, file); // Read the type byte
if (type_byte == 0)
{
keys[i].type = KEYBOARD;
fread(&keys[i].mod, sizeof(uint8_t), 1, file); // Read the mod byte
fread(&keys[i].code[0], sizeof(char), 1, file); // Read the code byte
keys[i].last = 0;
}
else if (type_byte == 1)
{
printf("\n");
printf("Before\n");
printf("index: %d\n", i);
printf("Type: %X\n", keys[i].type);
printf("Mod: %X\n", keys[i].mod);
printf("Ammount: %X\n", keys[i].ammount);
printf("Code: %X\n", (unsigned char)keys[i].code[0]);
printf("Last: %X\n", keys[i].last);
keys[i].type = CONSUMER;
fread(&keys[i].code[0], sizeof(char), 1, file); // Read the code byte
keys[i].last = 0;
printf("\n");
printf("After\n");
printf("index: %d\n", i);
printf("Type: %X\n", keys[i].type);
printf("Mod: %X\n", keys[i].mod);
printf("Ammount: %X\n", keys[i].ammount);
printf("Code: %X\n", (unsigned char)keys[i].code[0]);
printf("Last: %X\n", keys[i].last);
printf("\n");
}
else if (type_byte == 2)
{
keys[i].type = MACRO;
fread(&keys[i].ammount, sizeof(uint8_t), 1, file); // Read the amount byte
for (j = 0; j < keys[i].ammount; j++)
{
fread(&keys[i].code[j], sizeof(char), 1, file); // Read the code bytes
}
keys[i].last = 0;
}
index += incremental;
fseek(file, index, SEEK_SET); // Move file pointer to next record
}
fclose(file);
// Now keys array contains the data read from the file
// You can use it as needed
// next step is to print the data
for (i = 0; i < 8; i++)
{
printf("Index: %d\n", i);
printf("Type byte: %d\n", keys[i].type);
if (keys[i].type == KEYBOARD)
{
printf("Type: KEYBOARD\n");
printf("Mod: %X\n", keys[i].mod);
printf("Code: %X\n", keys[i].code[0]);
printf("Last: %X\n", keys[i].last);
}
else if (keys[i].type == CONSUMER)
{
printf("Type: CONSUMER\n");
printf("Code: %X\n", (unsigned char)keys[i].code[0]);
printf("Last: %X\n", keys[i].last);
}
else if (keys[i].type == MACRO)
{
printf("Type: MACRO\n");
printf("Ammount: %X\n", keys[i].ammount);
for (j = 0; j < keys[i].ammount; j++)
{
printf("Code: %X\n", keys[i].code[j]);
}
printf("Last: %X\n", keys[i].last);
}
printf("\n");
}
return 0;
}