-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
56 lines (44 loc) · 1.4 KB
/
main.c
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
#include <stdio.h>
#include <linux/input.h>
#include <linux/joystick.h>
#include <pthread.h>
#include "JoystickRead.h"
#include "SpiBus.h"
#define DEBUG 0
pthread_mutex_t mutex;
pthread_mutexattr_t mutexAttr;
static XpadReport_Data_t lastReport;
static XpadRumble_t *lastRumble;
void onReadJoy(struct js_event *event) {
if (DEBUG) {
printf("value: %d, type: %d, number:%d\n", event->value, event->type, event->number);
}
pthread_mutex_lock(&mutex);
convertEventToReport(&lastReport, event);
pthread_mutex_unlock(&mutex);
}
XpadReport_Data_t getLastReport(void) {
return lastReport;
}
void handleRumble(XpadRumble_t *rumble) {
if (DEBUG) {
if (rumble->left | rumble->right) {
printf("Rumble! 0x%x 0x%x\n", rumble->left, rumble->right);
}
}
lastRumble = rumble;
}
int main(int argc, char *argv[]) {
printf("HID to SPI redirect - (c) 2018 Jesenko Mehmedbasic\n\n");
if (argc < 2 || argc > 3) {
printf("Wrong number of arguments, usage:\n");
printf("hidspi <path_to_joystick> <path_to_spi> (optional <path_to_joystick_rumble>) \n");
return -1;
}
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex, &mutexAttr);
startJoystickReadThread(argv[1], &onReadJoy);
startSpiThread(argv[2], getLastReport, handleRumble);
return 0;
}