-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblt_hid.cpp
109 lines (98 loc) · 1.65 KB
/
blt_hid.cpp
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
105
106
107
108
109
/*
* blt_hid.cpp
*
* Created on: 16/08/2016
* Author: joao
*/
#include "blt_hid.h"
void delayMS(unsigned long msec)
{
while(msec--)
{
__delay_cycles(1000);
}
}
void printByte(uint8_t *array, uint8_t len)
{
for (uint8_t var = 0; var < len; ++var)
{
cio_printc((char)array[var]);
}
}
void setBLTHIDMouse(void)
{
cio_print((char *)"$$$");
delayMS(10000);
cio_print((char *)"SN,JMoteS_Mouse\r\n");
delayMS(1000);
cio_print((char *)"SH,0220\r\n");
delayMS(1000);
cio_print((char *)"R,1\r\n");
delayMS(10000);
for (int var = 0; var < BLINK_TIMES; ++var)
{
RED_LED_BLINK
delayMS(1000);
}
}
void setBLTHIDJoypad(void)
{
cio_print((char *)"$$$");
delayMS(10000);
cio_print((char *)"SN,JMoteS_JoyPad\r\n");
delayMS(1000);
cio_print((char *)"SH,0240\r\n");
delayMS(1000);
cio_print((char *)"R,1\r\n");
delayMS(10000);
for (int var = 0; var < BLINK_TIMES; ++var)
{
GREEN_LED_BLINK
delayMS(1000);
}
}
void sendRawMouse(RC_remote r)
{
uint8_t msg[7];
int8_t an;
msg[0] = 0xFD;
msg[1] = 0x05;
msg[2] = 0x02;
msg[3] = r.buttons & 0x0F;
an = r.steer & 0xFF;
msg[4] = an;
an = -r.linear & 0xFF;
msg[5] = an;
msg[6] = 0;
printByte(msg, 7);
}
void sendRawJoypad(RC_remote r)
{
uint8_t msg[8];
int8_t an;
msg[0] = 0xFD;
msg[1] = 0x06;
an = r.steer & 0xFF;
msg[2] = an;
an = -r.linear & 0xFF;
msg[3] = an;
an = r.steer & 0xFF;
msg[4] = an;
an = -r.linear & 0xFF;
msg[5] = an;
msg[6] = r.buttons & 0x0F;
msg[7] = 0;
printByte(msg, 8);
}
PadType getPadType(void)
{
if((~P2IN & L1_BUTTON) == L1_BUTTON)
{
return BLT_JOYPAD;
}
else if((~P2IN & R1_BUTTON) == R1_BUTTON)
{
return BLT_MOUSE;
}
return RF24_ONLY;
}