-
Notifications
You must be signed in to change notification settings - Fork 18
/
ArduinoBTPS2.ino
100 lines (82 loc) · 2.28 KB
/
ArduinoBTPS2.ino
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
/*
* Copyright (c) 2015 Evan Kale
* Email: [email protected]
* Website: www.ISeeDeadPixel.com
* www.evankale.blogspot.ca
*
* This file is part of ArduinoBTPS2.
*
* ArduinoBTPS2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PS2Mouse.h"
#include "PS2Keyboard.h"
#include "Bluetooth.h"
#define MOUSE_CLOCK 2
#define MOUSE_DATA 3
#define KEYBOARD_CLOCK 4
#define KEYBOARD_DATA 5
#define _DEBUG 0
#if _DEBUG
#define HARDWARE_SERIAL_RATE 38400
#else
#define HARDWARE_SERIAL_RATE 115200
#endif
PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA);
PS2Keyboard keyboard(KEYBOARD_CLOCK, KEYBOARD_DATA);
#if _DEBUG
#define BLUETOOTH_DEBUG_RX 7
#define BLUETOOTH_DEBUG_TX 8
#define BLUETOOTH_DEBUG_BAUD 9600
Bluetooth bluetooth(BLUETOOTH_DEBUG_BAUD, true, BLUETOOTH_DEBUG_RX, BLUETOOTH_DEBUG_TX);
#else
Bluetooth bluetooth(HARDWARE_SERIAL_RATE, false, 0, 0);
#endif
void setup()
{
#if _DEBUG
Serial.begin(HARDWARE_SERIAL_RATE);
Serial.println("Setup started");
#endif
delay(250);
#if _DEBUG
Serial.println("Initializing mouse...");
#endif
bool mouseStatus = mouse.init();
#if _DEBUG
if (mouseStatus)
Serial.println("Mouse detected!");
else
Serial.println("No mouse detected.");
Serial.println("Initializing keyboard...");
#endif
bool keyboardStatus = keyboard.init();
#if _DEBUG
if (keyboardStatus)
Serial.println("Keyboard detected!");
else
Serial.println("No keyboard detected.");
Serial.println("Setup complete");
#endif
}
void loop()
{
if (mouse.available())
{
bluetooth.sendMouseState(mouse.getBtnState(), mouse.getDeltaX(), -mouse.getDeltaY(), -mouse.getDeltaZ());
}
if (keyboard.available())
{
bluetooth.sendKeyboardState(keyboard.getKeyModifiers(), keyboard.getKeysPressed());
}
}