Skip to content

Commit 188d880

Browse files
committed
woot, that wasnt too bad - updated debug for Serial1, works nicely
1 parent f41f197 commit 188d880

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

libraries/USBHost/examples/MouseController/MouseController.ino

+47-22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
// Require mouse control library
1616
#include <MouseController.h>
1717

18+
// on a zero with debug port, use debug port
19+
//#define SerialDebug Serial
20+
21+
// on a feather or non-debug Zero, use Serial1 (since USB is taken!)
22+
#define SerialDebug Serial1
23+
24+
uint32_t lastUSBstate = 0;
25+
1826
// Initialize USB Controller
1927
USBHost usb;
2028

@@ -28,70 +36,87 @@ boolean rightButton = false;
2836

2937
// This function intercepts mouse movements
3038
void mouseMoved() {
31-
SERIAL_PORT_MONITOR.print("Move: ");
32-
SERIAL_PORT_MONITOR.print(mouse.getXChange());
33-
SERIAL_PORT_MONITOR.print(", ");
34-
SERIAL_PORT_MONITOR.println(mouse.getYChange());
39+
SerialDebug.print("Move: ");
40+
SerialDebug.print(mouse.getXChange());
41+
SerialDebug.print(", ");
42+
SerialDebug.println(mouse.getYChange());
3543
}
3644

3745
// This function intercepts mouse movements while a button is pressed
3846
void mouseDragged() {
39-
SERIAL_PORT_MONITOR.print("DRAG: ");
40-
SERIAL_PORT_MONITOR.print(mouse.getXChange());
41-
SERIAL_PORT_MONITOR.print(", ");
42-
SERIAL_PORT_MONITOR.println(mouse.getYChange());
47+
SerialDebug.print("Drag: ");
48+
SerialDebug.print(mouse.getXChange());
49+
SerialDebug.print(", ");
50+
SerialDebug.println(mouse.getYChange());
4351
}
4452

4553
// This function intercepts mouse button press
4654
void mousePressed() {
47-
SERIAL_PORT_MONITOR.print("Pressed: ");
55+
SerialDebug.print("Pressed: ");
4856
if (mouse.getButton(LEFT_BUTTON)) {
49-
SERIAL_PORT_MONITOR.print("L");
57+
SerialDebug.print("L");
5058
leftButton = true;
5159
}
5260
if (mouse.getButton(MIDDLE_BUTTON)) {
53-
SERIAL_PORT_MONITOR.print("M");
61+
SerialDebug.print("M");
5462
middleButton = true;
5563
}
5664
if (mouse.getButton(RIGHT_BUTTON)) {
57-
SERIAL_PORT_MONITOR.print("R");
65+
SerialDebug.print("R");
5866
rightButton = true;
5967
}
60-
SERIAL_PORT_MONITOR.println();
68+
SerialDebug.println();
6169
}
6270

6371
// This function intercepts mouse button release
6472
void mouseReleased() {
65-
SERIAL_PORT_MONITOR.print("Released: ");
73+
SerialDebug.print("Released: ");
6674
if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
67-
SERIAL_PORT_MONITOR.print("L");
75+
SerialDebug.print("L");
6876
leftButton = false;
6977
}
7078
if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
71-
SERIAL_PORT_MONITOR.print("M");
79+
SerialDebug.print("M");
7280
middleButton = false;
7381
}
7482
if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
75-
SERIAL_PORT_MONITOR.print("R");
83+
SerialDebug.print("R");
7684
rightButton = false;
7785
}
78-
SERIAL_PORT_MONITOR.println();
86+
SerialDebug.println();
7987
}
8088

8189
void setup()
8290
{
83-
SERIAL_PORT_MONITOR.begin( 115200 );
84-
while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
85-
SERIAL_PORT_MONITOR.println("Mouse Controller Program started");
91+
SerialDebug.begin( 115200 );
92+
SerialDebug.println("USB Host Mouse Controller Program started");
8693

8794
if (usb.Init() == -1)
88-
SERIAL_PORT_MONITOR.println("OSC did not start.");
95+
SerialDebug.println("USB Host did not start.");
8996

97+
SerialDebug.println("USB Host started");
9098
delay( 20 );
9199
}
92100

93101
void loop()
94102
{
95103
// Process USB tasks
96104
usb.Task();
105+
106+
uint32_t currentUSBstate = usb.getUsbTaskState();
107+
if (lastUSBstate != currentUSBstate) {
108+
SerialDebug.print("USB state changed: 0x");
109+
SerialDebug.print(lastUSBstate, HEX);
110+
SerialDebug.print(" -> 0x");
111+
SerialDebug.println(currentUSBstate, HEX);
112+
switch (currentUSBstate) {
113+
case USB_ATTACHED_SUBSTATE_SETTLE: SerialDebug.println("Device Attached"); break;
114+
case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: SerialDebug.println("Detached, waiting for Device"); break;
115+
case USB_ATTACHED_SUBSTATE_RESET_DEVICE: SerialDebug.println("Resetting Device"); break;
116+
case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE: SerialDebug.println("Reset complete"); break;
117+
case USB_STATE_CONFIGURING: SerialDebug.println("USB Configuring"); break;
118+
case USB_STATE_RUNNING: SerialDebug.println("USB Running"); break;
119+
}
120+
lastUSBstate = currentUSBstate;
121+
}
97122
}

0 commit comments

Comments
 (0)