forked from Sucareto/Arduino-Chunithm-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchuniio.c
144 lines (116 loc) · 2.94 KB
/
chuniio.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
139
140
141
142
143
144
#include <windows.h>
#include <process.h>
#include <stdbool.h>
#include <stdint.h>
#include "chuniio/chuniio.h"
#include "chuniio/config.h"
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx);
static bool chuni_io_coin;
static uint16_t chuni_io_coins;
// static uint8_t chuni_io_hand_pos;
static HANDLE chuni_io_slider_thread;
static bool chuni_io_slider_stop_flag;
static struct chuni_io_config chuni_io_cfg;
static const int chuni_io_default_cells[] = {
'I', VK_OEM_COMMA, '8', 'K', 'U', 'M', '7', 'J',
'Y', 'N', '6', 'H', 'T', 'B', '5', 'G',
'R', 'V', '4', 'F', 'E', 'C', '3', 'D',
'W', 'X', '2', 'S', 'Q', 'Z', '1', 'A',
};
static const int chuni_io_default_irs[] = {
VK_OEM_PERIOD, VK_OEM_2, VK_OEM_1, VK_OEM_7, VK_OEM_4, VK_OEM_6,
};
uint16_t chuni_io_get_api_version(void)
{
return 0x0101;
}
HRESULT chuni_io_jvs_init(void)
{
chuni_io_config_load(&chuni_io_cfg, L".\\segatools.ini");
return S_OK;
}
void chuni_io_jvs_read_coin_counter(uint16_t *out)
{
if (out == NULL) {
return;
}
if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) {
if (!chuni_io_coin) {
chuni_io_coin = true;
chuni_io_coins++;
}
} else {
chuni_io_coin = false;
}
*out = chuni_io_coins;
}
void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams)
{
size_t i;
if (GetAsyncKeyState(chuni_io_cfg.vk_test)) {
*opbtn |= 0x01; /* Test */
}
if (GetAsyncKeyState(chuni_io_cfg.vk_service)) {
*opbtn |= 0x02; /* Service */
}
for (i = 0; i < 6; i++){
if (GetAsyncKeyState(chuni_io_default_irs[i]) & 0x8000)
{
*beams |= (1 << i);
}
else
{
*beams &= ~(1 << i);
}
}
}
HRESULT chuni_io_slider_init(void)
{
return S_OK;
}
void chuni_io_slider_start(chuni_io_slider_callback_t callback)
{
if (chuni_io_slider_thread != NULL) {
return;
}
chuni_io_slider_thread = (HANDLE) _beginthreadex(
NULL,
0,
chuni_io_slider_thread_proc,
callback,
0,
NULL);
}
void chuni_io_slider_stop(void)
{
if (chuni_io_slider_thread == NULL) {
return;
}
chuni_io_slider_stop_flag = true;
WaitForSingleObject(chuni_io_slider_thread, INFINITE);
CloseHandle(chuni_io_slider_thread);
chuni_io_slider_thread = NULL;
chuni_io_slider_stop_flag = false;
}
void chuni_io_slider_set_leds(const uint8_t *rgb)
{
}
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx)
{
chuni_io_slider_callback_t callback;
uint8_t pressure[32];
size_t i;
callback = ctx;
while (!chuni_io_slider_stop_flag) {
for (i = 0 ; i < _countof(pressure) ; i++) {
if (GetAsyncKeyState(chuni_io_default_cells[i]) & 0x8000) {
pressure[i] = 128;
} else {
pressure[i] = 0;
}
}
callback(pressure);
Sleep(1);
}
return 0;
}