Space invaders with a nRF2401A wireless joypad

Dependencies:   Gameduino mbed nRF2401A

Fork of Gameduino_Invaders_game by Chris Dick

Gameduino and an nRF2401A hooked up to an mbed on an mbeduino:

/media/uploads/TheChrisyd/2014-03-08_22.53.54.jpg

Revision:
4:bb78bedae411
Parent:
2:20a89dc286d5
--- a/joystick.cpp	Fri Dec 21 13:53:46 2012 +0000
+++ b/joystick.cpp	Sat Oct 26 22:34:08 2013 +0000
@@ -5,6 +5,7 @@
 ------------------------------------------------------------*/
 #include "joystick.h"
 #include "GD.h"
+//#include "nRF2401A.h"
 //#include <SPI.h>
 //#include <GD.h>
 
@@ -14,8 +15,11 @@
 // "0" = default (Sparkfun joystick)
 //
 #define CUSTOM_JOYSTICK 0
+#define WIRELESS
 extern GDClass GD;
-
+//extern nRF2401A    wireless_joypad;
+extern byte wireless_dpad;
+extern byte wireless_buttons;
 #if CUSTOM_JOYSTICK
 /*------------------------------------------------------------------
  Custom joystick configuration. This is what you need to
@@ -64,6 +68,9 @@
 //#define ANALOG_EMULATE_DIGITAL
 
 #else
+
+#ifndef WIRELESS
+
 /*------------------------------------------------------------------
   Default: Sparkfun joystick
 ------------------------------------------------------------------*/
@@ -92,19 +99,15 @@
 #define ANALOG_EMULATE_DIGITAL
 
 #endif
-
+#endif
 /*------------------------------------------------------
   Stop hacking now...!
   
   There are no user-servicable parts below this line
 ------------------------------------------------------*/
-#define STICK_LEFT_BIT    0x01
-#define STICK_RIGHT_BIT   0x02
-#define STICK_UP_BIT      0x04
-#define STICK_DOWN_BIT    0x08
-#define ANALOG_STICK_BIT  0x80
-#define STICK_INFO_MASK (ANALOG_STICK_BIT)
+
 
+#ifndef WIRELESS
 /*---------------------------------------------
   Joystick reader
 ---------------------------------------------*/
@@ -140,15 +143,26 @@
     STICK_DOWN_PIN
 #endif
 };
+#endif
+
+#ifdef WIRELESS
+
+#endif
 Joystick::Joystick()
 {
+#ifdef WIRELESS
+   // wireless_joypad.attachRXHandler(&nRF2401A_rx, 0);
+#else
   // set up digital pins for dpad and buttons
    // const prog_uchar *pin = joystickPinList;
   for (byte i=0; i<sizeof(joystickPinList); ++i) {
     byte p = pgm_read_byte(joystickPinList+i);
     //pinMode(p,INPUT);
     //digitalWrite(p,HIGH);
-  }
+    }
+#endif    
+    
+  
   stickX = stickY = 0;
   xCal = yCal = 0;
   buttons = prev = dpad = 0;
@@ -157,12 +171,15 @@
   dpad |= ANALOG_STICK_BIT;
 #endif
 }
+
 bool Joystick::hasAnalogStick()
 {
   return (dpad&ANALOG_STICK_BIT)!=0;
 }
+
 void Joystick::recalibrate()
 {
+ 
   read();
   xCal = stickX;
   yCal = stickY;
@@ -203,9 +220,14 @@
   #ifdef BUTTON_ST_PIN
   //  if (digitalRead(BUTTON_ST_PIN)==LOW){  buttons |= buttonStart;  }
   #endif
-
+  #ifndef WIRELESS
   // Digital joystick/dpad
   dpad &= STICK_INFO_MASK;   // The top bits are informational...preserve them
+  #else
+  dpad = wireless_dpad;
+  buttons = wireless_buttons;
+  #endif
+  
   #ifdef STICK_LEFT_PIN
   //  if (!digitalRead(STICK_LEFT_PIN))  { dpad |= STICK_LEFT_BIT;  }
   //  if (!digitalRead(STICK_RIGHT_PIN)) { dpad |= STICK_RIGHT_BIT; }