Skip to content

Commit 7fe740d

Browse files
author
Tianli
committed
fixed the problem of duplicated hits & enriched debug info
1 parent 83767fa commit 7fe740d

File tree

1 file changed

+56
-39
lines changed

1 file changed

+56
-39
lines changed

taiko_controller.ino

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#include <Keyboard.h>
22

3+
//#define DEBUG_OUTPUT
4+
35
const int min_threshold = 20;
46
const long cd_length = 8000;
57
const long cd_antireso_length = 8000;
68
const float k_antireso = 0.85;
79
const float k_decay = 0.96;
810

11+
const int key_next[4] = {1, 3, 0, 2};
12+
913
const long cd_stageselect = 200000;
1014
bool stageselect = false;
1115
bool stageresult = false;
@@ -95,7 +99,9 @@ void loop() {
9599
if (cd[i] <= 0) {
96100
cd[i] = 0;
97101
if (pressed[i]) {
102+
#ifndef DEBUG_OUTPUT
98103
Keyboard.release(stageresult ? KEY_ESC : key[i]);
104+
#endif
99105
pressed[i] = false;
100106
}
101107
}
@@ -112,52 +118,63 @@ void loop() {
112118
}
113119
}
114120

115-
if (i_max == si && level_max > min_threshold) {
116-
if (!pressed[i_max]) {
117-
if (stageresult) {
118-
Keyboard.press(KEY_ESC);
119-
} else {
120-
Keyboard.press(key[i_max]);
121+
if (i_max == si && level_max >= min_threshold) {
122+
if (cd[i_max] == 0) {
123+
if (!pressed[i_max]) {
124+
#ifndef DEBUG_OUTPUT
125+
if (stageresult) {
126+
Keyboard.press(KEY_ESC);
127+
} else {
128+
Keyboard.press(key[i_max]);
129+
}
130+
#endif
131+
pressed[i_max] = true;
121132
}
122-
pressed[i_max] = true;
133+
for (int i = 0; i != 4; ++i)
134+
cd[i] = cd_antireso_length;
135+
cd[i_max] = (stageselect ? cd_stageselect : cd_length);
123136
}
137+
float level_antireso = level_max * k_antireso;
124138
for (int i = 0; i != 4; ++i)
125-
cd[i] = cd_antireso_length;
126-
cd[i_max] = (stageselect ? cd_stageselect : cd_length);
127-
for (int i = 0; i != 4; ++i)
128-
threshold[i] = max(threshold[i], level_max * k_antireso);
129-
threshold[i_max] = level_max;
139+
threshold[i] = max(threshold[i], level_antireso);
140+
threshold[i_max] = (cd[i_max] == 0 ? level_max : level_max * 1.5);
130141
sdt = 0;
131142
}
132-
133-
/*
134-
if (level[0]+level[1]+level[2]+level[3] > 10){
135-
Serial.print(level[0]);
136-
Serial.print("\t");
137-
Serial.print(level[1]);
138-
Serial.print("\t");
139-
Serial.print(level[2]);
140-
Serial.print("\t");
141-
Serial.print(level[3]);
142-
Serial.print("\t| ");
143-
Serial.print(cd[0] == 0 ? " " : "# ");
144-
Serial.print(cd[1] == 0 ? " " : "# ");
145-
Serial.print(cd[2] == 0 ? " " : "# ");
146-
Serial.print(cd[3] == 0 ? " " : "# ");
147-
Serial.print("|\t");
148-
Serial.print((int)threshold[0]);
149-
Serial.print("\t");
150-
Serial.print((int)threshold[1]);
151-
Serial.print("\t");
152-
Serial.print((int)threshold[2]);
153-
Serial.print("\t");
154-
Serial.print((int)threshold[3]);
155-
Serial.println();
143+
144+
#ifdef DEBUG_OUTPUT
145+
static bool printing = false;
146+
if (si == 0) {
147+
if (level[0]+level[1]+level[2]+level[3] >= min_threshold || cd[0] || cd[1] || cd[2] || cd[3]){
148+
Serial.print(level[0]);
149+
Serial.print("\t");
150+
Serial.print(level[1]);
151+
Serial.print("\t");
152+
Serial.print(level[2]);
153+
Serial.print("\t");
154+
Serial.print(level[3]);
155+
Serial.print("\t| ");
156+
Serial.print(cd[0] == 0 ? " " : pressed[0] ? "# " : "* ");
157+
Serial.print(cd[1] == 0 ? " " : pressed[1] ? "# " : "* ");
158+
Serial.print(cd[2] == 0 ? " " : pressed[2] ? "# " : "* ");
159+
Serial.print(cd[3] == 0 ? " " : pressed[3] ? "# " : "* ");
160+
Serial.print("|\t");
161+
Serial.print((int)threshold[0]);
162+
Serial.print("\t");
163+
Serial.print((int)threshold[1]);
164+
Serial.print("\t");
165+
Serial.print((int)threshold[2]);
166+
Serial.print("\t");
167+
Serial.print((int)threshold[3]);
168+
Serial.println();
169+
printing = true;
170+
}else if(printing){
171+
Serial.println("=============================================================================");
172+
printing = false;
173+
}
156174
}
157-
*/
175+
#endif
158176

159-
160177
sampleSingle(si);
161-
si = (si + 1) & 3;
178+
si = key_next[si];
162179

163180
}

0 commit comments

Comments
 (0)