-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gamepad.cpp
66 lines (53 loc) · 1.54 KB
/
gamepad.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
/**
* Bill Siever
* 2021-11-20 Initial Version
*
* Development environment specifics:
* Written in Microsoft PXT
*
* This code is released under the [MIT License](http://opensource.org/licenses/MIT).
* Please review the LICENSE.md file included with this example. If you have any questions
* or concerns with licensing, please contact [email protected].
* Distributed as-is; no warranty is given.
*/
#include "pxt.h"
#include "MicroBit.h"
#include "GamepadReporter.h"
#include "debug.h"
static GamepadReporter *reporter = NULL;
using namespace pxt;
namespace gamepad {
bool isInitialized() {
if(reporter == NULL) {
uBit.display.scroll("Gamepad not started");
return false;
} else {
return true;
}
}
//%
void startGamepadService() {
if(reporter == NULL) {
reporter = GamepadReporter::getInstance();
}
}
//%
void _send(uint16_t buttons, uint32_t xyzrx, uint8_t dpad) {
if(!isInitialized()) return;
uint8_t x = (xyzrx >> 24)&0xFF;
uint8_t y = (xyzrx >> 16)&0xFF;
uint8_t z = (xyzrx >> 8)&0xFF;
uint8_t rx = (xyzrx >> 0)&0xFF;
//DEBUG("x %d, y %d rx %d, ry %d, dpad: 0x%02x\n",x,y,rx,ry, dpad);
reporter->send(buttons, x, y, z, rx, dpad);
}
//%
bool isEnabled() {
return reporter ? reporter->isEnabled() : false;
}
//%
void setStatusChangeHandler(Action action) {
if(!reporter) return;
reporter->setStatusChangeHandler(action);
}
}