forked from Vegz78/micro-bit-game-pad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.cpp
44 lines (38 loc) · 1.19 KB
/
extension.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
#include "pxt.h"
#include "MicroBitConfig.h"
#include "ble/BLE.h"
#include "MicroBitThermometer.h"
#include "EventModel.h"
#include "JoystickService.h"
namespace bluetooth {
static JoystickService *_pService = nullptr;
static JoystickService *getJoystick(){
if (_pService == nullptr) {
_pService = new JoystickService(*uBit.ble);
}
return _pService;
}
/**
* A function to start bluetooth Joystick service
*/
//% blockId=bluetooth_startJoystickService block="bluetooth startJoystickService"
void startJoystickService() {
getJoystick();
}
/**
* A function to press joystick button
*/
//% blockId=bluetooth_pressJoystickButton block="bluetooth press joystick button %button"
void pressJoystickButton(JoystickButton button) {
JoystickService *joystick = getJoystick();
joystick->pressButton(button);
}
/**
* A function to sent joystick speed
*/
//% blockId=bluetooth_sendMovement block="bluetooth send joystick speed %x %y %z"
void sendMovement(int x, int y, int z) {
JoystickService *joystick = getJoystick();
joystick->setSpeed(x,y,z);
}
}