Code for left-hand controller for Clash. Orientation control and d-pad control corresponding to relative mouse position and WASD movement keys for the game Chivalry: Medieval Warfare.

Dependencies:   DebounceIn MMA8451Q TSI USBDevice_modified mbed

Files at this revision

API Documentation at this revision

Comitter:
fil
Date:
Mon Sep 29 01:52:18 2014 +0000
Child:
1:73f8b2e70728
Commit message:
final commit

Changed in this revision

DebounceIn.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIn.lib	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/DebounceIn/#31ae5cfb44a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#52eb548396ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,94 @@
+#include "mbed.h"
+//#include "USBMouse.h"
+#include "USBMouseKeyboard.h"
+#include "USBKeyboard.h"
+#include "MMA8451Q.h"
+#include "TSISensor.h"
+#include "math.h"
+#include "DebounceIn.h"
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+//USBMouse mouse(ABS_MOUSE);
+USBMouseKeyboard mouse;
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+TSISensor tsi;
+//Serial pc(USBTX, USBRX);
+
+DebounceIn wkey(D4);
+DebounceIn akey(D5);
+DebounceIn skey(D6);
+DebounceIn dkey(D7);
+
+main (void)
+{
+    int16_t x_mouse = 0;
+    int16_t y_mouse = 0;
+    int t = 0;
+    float x = 0; float x_cal = 0;
+    float y = 0; float y_cal = 0;
+    int calib_cnt = 0;
+    int walks = 0, walka = 0, walkd = 0, walkw = 0;
+    
+    while (calib_cnt < 100) {
+        x_cal += acc.getAccX();
+        y_cal += acc.getAccY();
+        calib_cnt++;
+        wait(0.01);
+    }
+    x_cal = x_cal/calib_cnt;
+    y_cal = y_cal/calib_cnt;
+    
+    while(1) {
+        x = acc.getAccX();
+        y = acc.getAccY();
+        x_mouse = floor(-(x-x_cal)*10);
+        y_mouse = floor(-(y-y_cal)*6);
+        mouse.move(x_mouse,y_mouse);
+        t = tsi.readDistance();
+        
+        if (skey == 0) {
+            mouse.printf("s");
+            walks = 1;
+        }
+        if (dkey == 0) {
+            mouse.printf("d");
+            walkd = 1;
+        }
+        if (akey == 0){
+            mouse.printf("a");
+            walka = 1;
+        }
+        if (wkey == 0) {
+            mouse.printf("w");
+            walkw = 1;
+        }
+            
+        if (walks == 1 && skey == 1) {
+            mouse.releaseKey('s',0);
+            walks = 0;
+        }
+        if (walka == 1 && akey == 1) {
+            mouse.releaseKey('a',0);
+            walka = 0;
+        }
+        if (walkd == 1 && dkey == 1) {
+            mouse.releaseKey('d',0);
+            walkd = 0;
+        }
+        if (walkw == 1 && wkey == 1) {
+            mouse.releaseKey('w',0);
+            walkw = 0;
+        }
+        
+                
+        if (t != 0) {
+            mouse.press(1);
+            mouse.release(0);
+        }
+        else {
+            mouse.release(1);
+            mouse.press(0);
+        }
+        wait(0.001);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 29 01:52:18 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec
\ No newline at end of file