-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (48 loc) · 1.37 KB
/
main.cpp
File metadata and controls
59 lines (48 loc) · 1.37 KB
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
/* * Project: Sim-Universal-Interface-STM32
* Author: customsmtr (CustomSimEchoSystem)
* License: MIT
*/
#include <Arduino.h>
#include <USBComposite.h>
// Initialize the composite device with HID and Serial
USBHID HID;
HIDJoystick Joystick(HID);
HIDKeyboard Keyboard(HID);
USBCompositeSerial CompositeSerial;
const int BUTTON_PIN = PA0;
void setup() {
USBComposite.setVendorId(0x1209);
USBComposite.setProductId(0x8989);
USBComposite.setManufacturerString("CustomSimEchoSystem");
USBComposite.setProductString("Universal Sim-Controller");
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initializing interfaces
HID.begin();
Keyboard.begin();
Joystick.begin();
CompositeSerial.begin();
USBComposite.begin();
}
void loop() {
// HID Joystick Logic
if (digitalRead(BUTTON_PIN) == LOW) {
Joystick.button(1, true);
} else {
Joystick.button(1, false);
}
// CDC Serial & Keyboard Logic
if (CompositeSerial.available()) {
String msg = CompositeSerial.readStringUntil('\n');
msg.trim();
if (msg == "GET_ID") {
CompositeSerial.println("ID:SIM_UNIVERSAL_V1");
}
else if (msg == "PING") {
CompositeSerial.println("PONG");
Keyboard.press(KEY_TAB);
delay(50);
Keyboard.release(KEY_TAB);
}
}
delay(10);
}