forked from ironandstee1/pkmn-auto-hatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchInput.c
104 lines (86 loc) · 2.01 KB
/
SwitchInput.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
#include "SwitchInput.h"
bool _isInit = false;
void MainInputLoop()
{
//this will be run a single time, initialize whatever is needed here
if (_isInit == false)
{
_isInit = true;
// Sleep(1000);
// ButtonDown(SWITCH_R);
// ButtonDown(SWITCH_L);
// Sleep(100);
// ButtonUp(SWITCH_R);
// ButtonUp(SWITCH_L);
// Sleep(500);
// ButtonDown(SWITCH_R);
// ButtonDown(SWITCH_L);
// Sleep(100);
// ButtonUp(SWITCH_R);
// ButtonUp(SWITCH_L);
Sleep(2000);
}
// int16_t data = serial_popshort();
// if (data >= 0)
// {
// #ifdef DEBUG
// printf("Command: %c - Arg: %c\n", (char)(data >> 8), (char)(data));
// #endif
// char command = (char)(data >> 8);
// char arg = (char)data;
// //react to command and arg
// switch (command)
// {
// case 1:
// ButtonDown(1 << (arg - 1));
// break;
// case 2:
// ButtonUp(1 << (arg - 1));
// break;
// default:
// break;
// }
// }
PressButton(SWITCH_A, 1000);
//printf("Pressing A");
//make sure we're handling USB
//HandleUSB();
}
void HoldButton(uint16_t button, int duration, int delay)
{
unsigned long start = millis();
ButtonDown(button);
while ((millis() - start) < duration)
{
HandleUSB();
}
ButtonUp(button);
if (delay > 0)
{
Sleep(delay);
}
}
void PressButton(uint16_t button, int delay)
{
HoldButton(button, 100, delay);
}
void ButtonDown(int button)
{
ReportData.Button |= button;
}
void ButtonUp(int button)
{
ReportData.Button &= ~button;
}
void Sleep(int delay)
{
unsigned long start = millis();
while ((millis() - start) < delay)
{
// ReportData.LX = STICK_CENTER;
// ReportData.LY = STICK_CENTER;
// ReportData.RX = STICK_CENTER;
// ReportData.RY = STICK_CENTER;
HandleUSB();
}
}