summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2014-09-07 01:53:10 +0200
committerFlorian Jung <flo@windfisch.org>2014-09-07 01:53:10 +0200
commitf498d6e01a79ef9509d4b3e39e9ef354d0f7428a (patch)
treeff0cf6556471f187c11a4f0a96312540eb9fedd4
parent8bb8a119cf0bfea388e499f2d1bbcdbdd18d9db0 (diff)
use JOYSTICK_{UINPUT,PATCHEDINPUTPLUGIN} #defines instead of FREEBSD/LINUX
-rw-r--r--joystick.cpp14
-rw-r--r--joystick.h8
-rw-r--r--mariokart.cpp8
-rw-r--r--os.h6
4 files changed, 22 insertions, 14 deletions
diff --git a/joystick.cpp b/joystick.cpp
index 4f2029b..6729023 100644
--- a/joystick.cpp
+++ b/joystick.cpp
@@ -29,7 +29,7 @@
#include <iostream>
#include <fcntl.h>
-#ifdef LINUX
+#ifdef JOYSTICK_UINPUT
#include <linux/input.h>
#include <linux/uinput.h>
#endif
@@ -43,7 +43,7 @@ using namespace std;
#define THROTTLE_CNT_MAX 10
-#ifdef FREEBSD
+#ifdef JOYSTICK_PATCHEDINPUTPLUGIN
static char* pack(const BUTTONS* buttons, char* buf)
{
buf[0]= (buttons->A_BUTTON ? 1 : 0) +
@@ -76,7 +76,7 @@ static char* pack(const BUTTONS* buttons, char* buf)
-#ifdef FREEBSD
+#ifdef JOYSTICK_PATCHEDINPUTPLUGIN
Joystick::Joystick()
{
if ((fifo_fd=open("/var/tmp/mupen64plus_ctl", O_WRONLY )) == -1) {throw string(strerror(errno));}
@@ -127,8 +127,8 @@ Joystick::~Joystick()
{
close(fifo_fd);
}
-#endif // FREEBSD
-#ifdef LINUX
+#endif // JOYSTICK_PATCHEDINPUTPLUGIN
+#ifdef JOYSTICK_UINPUT
Joystick::Joystick()
{
fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
@@ -185,6 +185,8 @@ void Joystick::steer(float dir, float dead_zone)
ev.code=ABS_X;
ev.value=5000+dir*5000;
write(fd, &ev, sizeof(ev));
+
+ cout << "steering" << dir << endl;
}
@@ -218,7 +220,7 @@ void Joystick::reset()
cout << "A zeroed" << endl;
}
-#endif // LINUX
+#endif // JOYSTICK_UINPUT
void Joystick::throttle(float t)
diff --git a/joystick.h b/joystick.h
index 50844a7..5b1325d 100644
--- a/joystick.h
+++ b/joystick.h
@@ -24,7 +24,7 @@
#include "os.h"
-#ifdef FREEBSD
+#ifdef JOYSTICK_PATCHEDINPUTPLUGIN
typedef union {
unsigned int Value;
struct {
@@ -51,7 +51,7 @@ typedef union {
};
} BUTTONS;
-#endif // FREEBSD
+#endif // JOYSTICK_PATCHEDINPUTPLUGIN
class Joystick
@@ -68,12 +68,12 @@ class Joystick
void reset();
private:
-#ifdef FREEBSD
+#ifdef JOYSTICK_PATCHEDINPUTPLUGIN
BUTTONS buttons;
void send_data();
int fifo_fd;
#endif
-#ifdef LINUX
+#ifdef JOYSTICK_UINPUT
int fd;
#endif
diff --git a/mariokart.cpp b/mariokart.cpp
index d0903b2..414a9cd 100644
--- a/mariokart.cpp
+++ b/mariokart.cpp
@@ -203,7 +203,7 @@ int main(int argc, char* argv[])
string tmp;
-#ifdef LINUX
+#ifdef JOYSTICK_UINPUT
Joystick joystick;
cout << "joystick initalized, now starting mupen." << endl;
#endif
@@ -211,7 +211,7 @@ int main(int argc, char* argv[])
// for mupen 1.x if (fork()==0) { system("mupen64plus --nogui --noask ~/MarioKart64.rom"); exit(0); }
if (fork()==0) { system("mupen64plus --windowed --resolution 640x480 ~/konsolenspiele/N64/MarioKart64.rom"); exit(0); }
-#ifdef FREEBSD
+#ifdef JOYSTICK_PATCHEDINPUTPLUGIN
sleep(2);
Joystick joystick;
#endif
@@ -221,7 +221,7 @@ int main(int argc, char* argv[])
joystick.reset();
cout << "successfully reset joystick." << endl;
-/* cout << "press enter to steer left" << endl;
+ cout << "press enter to steer left" << endl;
getchar();
@@ -247,7 +247,7 @@ int main(int argc, char* argv[])
cout << "A released." << endl;
joystick.press_a(false);
- getchar();*/
+ getchar();
cout << "waiting for game to start, press enter when started." << endl;
joystick.press_a(false);
diff --git a/os.h b/os.h
index 0b50040..abd90c1 100644
--- a/os.h
+++ b/os.h
@@ -1,2 +1,8 @@
//#define FREEBSD
#define LINUX
+
+#ifdef FREEBSD
+#define JOYSTICK_PATCHEDINPUTPLUGIN
+#else
+#define JOYSTICK_UINPUT
+#endif