-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontroller.cpp
62 lines (45 loc) · 1.4 KB
/
controller.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
#include "controller.h"
#include <cstring>
using namespace Chaos;
Controller::Controller() {
memset(controllerState, 0, sizeof(controllerState));
}
int Controller::getState(int id, ButtonType type) {
return controllerState[ ((int)type<<8) + (int)id ];
}
void Controller::storeState(const DeviceEvent* event) {
int location = ((int)event->type<<8) + (int)event->id;
if (location < 1024) {
controllerState[ location ] = event->value;
}
// In GPIO, maybe nothing needs to be done.
// In RAW, the above state storage should get passed through
//writeToSpoofFile( controllerState );
//printf("State stored!\n");
}
void Controller::handleNewDeviceEvent(const DeviceEvent* event) {
// We have an event! Let's send it right away, but let's let chaos engine play around with the values
DeviceEvent updatedEvent;
bool validEvent = false;
if (dualShockInjector != NULL) {
validEvent = dualShockInjector->sniffify(event, &updatedEvent);
} else {
validEvent = true;
updatedEvent = *event;
}
// Is our event valid? If so, send the chaos modified data:
if (validEvent) {
applyEvent(&updatedEvent);
} else {
//printf("Event with id %d was NOT applied\n", event->id);
}
}
void Controller::applyEvent(const DeviceEvent* event) {
if (!applyHardware(event)) {
return;
}
storeState(event);
}
void Controller::addInjector(ControllerInjector* injector) {
this->dualShockInjector = injector;
}