36#include <SoftwareSerial.h>
45constexpr uint8_t kDebugSerialRxPin = 6;
46constexpr uint8_t kDebugSerialTxPin = 5;
51constexpr uint8_t kAxisThreshold = 2;
55const String kBluetoothDeviceAddress =
"0C:3D:5E:9D:80:99";
60constexpr uint32_t kBluetoothModuleSerialBaudRate = 115200;
82SoftwareSerial g_debug_serial(kDebugSerialRxPin, kDebugSerialTxPin);
110 return "Triangle(Y)";
172void Connect(Stream &bluetooth_stream,
const String &bluetooth_device_address) {
173 if (bluetooth_device_address.length() != 17 || bluetooth_device_address[2] !=
':' || bluetooth_device_address[5] !=
':' ||
174 bluetooth_device_address[8] !=
':' || bluetooth_device_address[11] !=
':' || bluetooth_device_address[14] !=
':') {
175 g_debug_serial.println(
"Error: Invalid MAC address format. Expected: XX:XX:XX:XX:XX:XX");
179 g_debug_serial.print(
"Start to connect ");
180 g_debug_serial.println(kBluetoothDeviceAddress);
184 bluetooth_stream.println(
"AT+DISCON");
189 bluetooth_stream.println(
"AT+RESET");
194 bluetooth_stream.println(
"AT+ECHO=0");
199 bluetooth_stream.println(
"AT+ROLE=0");
204 bluetooth_stream.println(
"AT+AUTOCON=0");
209 bluetooth_stream.print(
"AT+CON=");
210 bluetooth_stream.println(bluetooth_device_address);
213 g_debug_serial.println(
"Connected");
218 g_debug_serial.begin(115200);
220 Serial.begin(kBluetoothModuleSerialBaudRate);
222 Connect(Serial, kBluetoothDeviceAddress);
232 g_codex_pad_frame_decoder.Update();
234 for (
auto button : kAllButtons) {
237 if (g_codex_pad_frame_decoder.pressed(button)) {
238 g_debug_serial.print(
"Button ");
239 g_debug_serial.print(ButtonToString(button));
240 g_debug_serial.println(
": pressed");
245 else if (g_codex_pad_frame_decoder.released(button)) {
246 g_debug_serial.print(
"Button ");
247 g_debug_serial.print(ButtonToString(button));
248 g_debug_serial.println(
": released");
253 else if (g_codex_pad_frame_decoder.holding(button)) {
254 g_debug_serial.print(
"Button ");
255 g_debug_serial.print(ButtonToString(button));
256 g_debug_serial.println(
": holding");
268 g_debug_serial.print(
"L(X:");
269 g_debug_serial.print(
271 g_debug_serial.print(
", Y:");
272 g_debug_serial.print(
274 g_debug_serial.print(
"), R(X:");
275 g_debug_serial.print(
277 g_debug_serial.print(
", Y:");
278 g_debug_serial.print(
280 g_debug_serial.println(
")");