-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathBluetooth.cpp
More file actions
96 lines (87 loc) · 2.66 KB
/
Bluetooth.cpp
File metadata and controls
96 lines (87 loc) · 2.66 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
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
/*
* Copyright (c) 2015 Evan Kale
* Email: EvanKale91@gmail.com
* 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 <SoftwareSerial.h>
#include "Bluetooth.h"
#include "PS2Keyboard.h"
Bluetooth::Bluetooth(uint32_t baudRate, bool useSoftwareSerial, uint8_t softwareRXPin, uint8_t softwareTXPin)
{
_useSoftwareSerial = useSoftwareSerial;
if (_useSoftwareSerial)
{
_serialStream = new SoftwareSerial(softwareRXPin, softwareTXPin);
((SoftwareSerial*)_serialStream)->begin(baudRate);
}
else
{
_serialStream = &Serial;
((HardwareSerial*)_serialStream)->begin(baudRate);
}
}
Bluetooth::~Bluetooth()
{
if (_useSoftwareSerial)
{
delete(_serialStream);
_serialStream = 0;
}
}
void Bluetooth::sendMouseState(uint8_t btnState, uint8_t deltaX, uint8_t deltaY, uint8_t deltaZ)
{
_serialStream->write((uint8_t)0xFD);
_serialStream->write((uint8_t)0x05);
_serialStream->write((uint8_t)0x02);
_serialStream->write(btnState);
_serialStream->write(deltaX);
_serialStream->write(deltaY);
_serialStream->write(deltaZ);
}
void Bluetooth::sendKeyboardState(uint8_t modifiers, uint8_t * keysPressed)
{
_serialStream->write((uint8_t)0xFD);
_serialStream->write((uint8_t)0x09);
_serialStream->write((uint8_t)0x01);
_serialStream->write(modifiers);
_serialStream->write((uint8_t)0x00);
for (uint8_t i = 0; i < MAX_KEYS_PRESSED; ++i)
{
_serialStream->write(keysPressed[i]);
}
}
void Bluetooth::sendConsumerReport(uint16_t consumerKeys)
{
_serialStream->write((uint8_t)0xFD);
_serialStream->write((uint8_t)0x00);
_serialStream->write((uint8_t)0x02);
_serialStream->write((uint8_t)((consumerKeys >> 8) & 0xFF));
_serialStream->write((uint8_t)(consumerKeys & 0xFF));
_serialStream->write((uint8_t)0x00);
_serialStream->write((uint8_t)0x00);
_serialStream->write((uint8_t)0x00);
_serialStream->write((uint8_t)0x00);
}
void Bluetooth::getKeyboardLEDState()
{
_serialStream->write((uint8_t)0xFF);
_serialStream->write((uint8_t)0x02);
//TODO
//what to read from BT device?
}