Skip to content

Commit 5796501

Browse files
author
broxigarchen
committed
Added code for emulator, tested with Linux
1 parent c7f0848 commit 5796501

22 files changed

+1073
-265
lines changed

actors/defaultActor/defaultActor.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2020 Brox Chen [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/

actors/defaultActor/defaultActor.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2020 Brox Chen [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
26+
#ifndef DEFAULTACTOR_H_
27+
#define DEFAULTACTOR_H_
28+
29+
class defaultActor: public actor
30+
{
31+
32+
};
33+
34+
35+
36+
#endif

config/rule.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
#Define your key combos with format "ComboName = key1 + key 2 +...". Each combo takes a new line.
2525
#An callback entry will be created with the "ComboName"(case sensitive). Use this name to link your callback function in the key actor class. This name has to be unique among all combonames.
2626

27-
#key Combination with order
27+
#key Combination(with order)
2828
keyComboWithOrder = {
2929
ActivePCSet1 = OS + F1
3030
ActivePCSet2 = OS + F2
3131
ActivePCSet3 = OS + F3
3232
}
3333

34-
#key Combination without order
35-
keyComboWithoutOrder = {
36-
37-
}
38-
3934
#Reserved key combos. Reserved key combos invoke keyboardbox's own callback functions
4035
#Customized callback are also allowed with these reserved key combos.
4136
#Invoke order: customized callback -> system callback

emulator/ghid/mkghid.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo 0x0100 > bcdDevice # v1.0.0
1313
echo 0x0200 > bcdUSB # USB2
1414
echo 0x03 > bDeviceClass #hid
1515
echo 0x00 > bDeviceSubClass
16-
echo 0x00 > bDeviceProtocol
16+
echo 0x01 > bDeviceProtocol
1717

1818
#USB strings
1919
mkdir -p strings/0x409
@@ -28,7 +28,7 @@ echo 250 > configs/c.1/MaxPower
2828

2929
#USB kbd function
3030
mkdir -p functions/hid.usb0
31-
echo 0 > functions/hid.usb0/protocol
31+
echo 1 > functions/hid.usb0/protocol
3232
echo 0 > functions/hid.usb0/subclass
3333
echo 8 > functions/hid.usb0/report_length
3434
echo 63 > functions/hid.usb0/report_desc_length

emulator/hidEmu.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,43 @@ SOFTWARE.
2525
#ifndef HIDEMU_H_
2626
#define HIDEMU_H_
2727

28+
#include <fstream>
29+
#include <errno.h>
2830

29-
class hidEmu
31+
#include "nonCopyable.h"
32+
class hidEmu: public nonCopyable
3033
{
3134
public:
3235
hidEmu(const char* dev)
3336
{
37+
fs.open(dev, std::fstream::out | std::fstream::in | std::fstream::binary);
38+
if(fs.fail())
39+
{
40+
perror("hidEmu");
41+
exit(EXIT_FAILURE);
42+
}
3443
}
3544

36-
virtual ~hidEmu();
45+
virtual ~hidEmu()
46+
{
47+
fs.close();
48+
}
49+
50+
protected:
51+
52+
void send(const char* buf, size_t n)
53+
{
54+
if(fs.fail())
55+
{
56+
perror("KbdEmu write");
57+
exit(EXIT_FAILURE);
58+
}
59+
60+
fs.write(buf, n);
61+
fs.flush();
62+
}
3763

38-
private:
39-
int fd;
64+
std::fstream fs;
4065
};
4166

4267

emulator/kbdEmu.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2020 Brox Chen [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
#include "kbdEmu.h"
26+
#include "PosixHelper.h"
27+
#include <iostream>
28+
29+
const std::map<uint8_t, uint8_t> kbdReport::kmodmap = {
30+
{224, KBD_LCTRL},
31+
{225, KBD_LSHFT},
32+
{226, KBD_LALT},
33+
{227, KBD_LGUI},
34+
{228, KBD_RCTRL},
35+
{229, KBD_RSHFT},
36+
{230, KBD_RALT},
37+
{231, KBD_RGUI},
38+
};
39+
40+
kbdEmu::kbdEmu(const char* dev, size_t size): hidEmu(dev)
41+
{
42+
queue = new circleBuf<kbdReport>(size);
43+
this->worker = std::thread(&kbdEmu::sender, this);
44+
}
45+
46+
kbdEmu::~kbdEmu()
47+
{
48+
delete queue;
49+
}
50+
51+
int kbdEmu::addKbdReport(kbdReport report)
52+
{
53+
return queue->push_back(report);
54+
}
55+
56+
void kbdEmu::sender(void)
57+
{
58+
kbdReport r;
59+
while(1)
60+
{
61+
r = queue->pop_front();
62+
63+
std::cout<< PosixHelper::getTimeStamp()
64+
<< " send report: "
65+
<< r.getString()
66+
<< std::endl;
67+
68+
send((const char*)&(r.report), sizeof(r.report));
69+
}
70+
}
71+

0 commit comments

Comments
 (0)