What about using the DS as an android gamepad

Discussion in 'NDS - Emulation and Homebrew' started by xXMortalKombatXx, Mar 4, 2014.

  1. xXMortalKombatXx
    OP

    xXMortalKombatXx Advanced Member

    Newcomer
    69
    11
    Apr 14, 2012
    Brazil
    Did anyone make it possible to use the DS as a gamepad for android already?
     
  2. Fyrus

    Fyrus Artilleur Carmin

    Member
    798
    127
    Jul 6, 2010
    France
    Marseille - France
    Not as far as I know of, such a thing wouldn't be possible anyway save on Wifi, and even then ...
     
  3. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,557
    21,533
    Sep 13, 2009
    Poland
    Gaming Grotto
    Android gamepads use Bluetooth which the DS is not equipped with. If there's a way to connect a gamepad via WiFi then perhaps it would be doable to code an app like that - I know there's one for PC.
     
  4. cracker

    cracker Nyah!

    Member
    3,155
    452
    Aug 24, 2005
    United States
    Though it is possible to do it would require a lot of work to program software on both the Android device and DS ends to connect. And then it would be only useful if there was AdHoc (direct connection without a router) mode for the wifi chip in the device. Which in turn on most devices you would lose your network connection since most wifi chips can only use one mode at once.

    You're better off getting a PS3 controller and using that.
     
  5. xXMortalKombatXx
    OP

    xXMortalKombatXx Advanced Member

    Newcomer
    69
    11
    Apr 14, 2012
    Brazil
    I didn't think about losing the internet access, but most people only use wi-fi for online gaming anyways (it would require a router). I was also thinking about making a simple ppjoy host only using the necessary stuff to get the DS keys working and on the DS side it would be done already, there's a homebrew application that sends ppjoy commands


    Plus most gamepads such as the Wii remote can't connect anymore, as Google changed the BT stack in a way it doesn't connect to pairless devices, it's been like that since 4.2, and on latest android builds (4.4.2) it still wasn't fixed

    *extra: I see no problem on the latency added by having a router in the middle?
     
  6. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,557
    21,533
    Sep 13, 2009
    Poland
    Gaming Grotto
    Honestly, the DS could do the complete barebones minimum of computing and the actuall button stroke interpreter could be on the Android side where there's more calculation power. All the DS has to do is read keystrokes, put them in a neat structure and send it through at regular intervals - I don't think that's beyond the scope of its capabilities. Actual gamepads are not powerhouses and work perfectly fine, the DS side of things wouldn't have to do a whole lot. Sounds like an interesting pet project, actually.
     
  7. xXMortalKombatXx
    OP

    xXMortalKombatXx Advanced Member

    Newcomer
    69
    11
    Apr 14, 2012
    Brazil
    I think we can dedicate more of the ds's CPU to interpret the keys, it's battery would still last more than the phone's anyways, and every tweak for extra battery is always good on smartphones these days
     
  8. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,557
    21,533
    Sep 13, 2009
    Poland
    Gaming Grotto
    This much is true, however the DS would have to connect with the phone in an AdHoc fashion - the latency introduced by the router could be pretty substantial in the long run, that's the issue more than anything.
     
  9. Yepi69

    Yepi69 Vivid and busy gamer

    Member
    2,421
    1,018
    Nov 29, 2010
    Portugal
    Behind you
    You can if you have a PC nearby with internet connection, I actually used my DS to play Megaman X on my Android Tablet.

    For the DS you need DS2KEY (Its homebrew, you need a flashcard to run it)
    For the PC you need DS2KEY (you need an internet connection)
    For your Android you need an app called Wi-Fi Keyboard

    Here's how it is, DS2KEY sets up whatever button you wanna use, my configuration is:

    DS2KEY:

    Press A button = Computer receives the keyboard key A (using Wi-Fi keyboard) Android receives the keyboard key Z
    Press B button = Computer receives the keyboard key (using Wi-Fi keyboard) Android receives the keyboard key X
    Press the Start button = Computer receives the keyboard key Enter (using Wi-Fi keyboard) Android receives the keyboard key Enter
    Press the Select button = Computer receives the keyboard key Backspace (using Wi-Fi keyboard) Android receives the keyboard key Backspace
    Press the L button = Computer receives the keyboard key L (using Wi-Fi keyboard) Android receives the keyboard key L
    Press the R button = Computer receives the keyboard key R (using Wi-Fi keyboard) Android receives the keyboard key R
    Press the D-PAD UP = Computer receives the keyboard key UP Arrow (using Wi-Fi keyboard) Android receives the keyboard key W
    Press the D-PAD DOWN = Computer receives the keyboard key DOWN Arrow (using Wi-Fi keyboard) Android receives the keyboard key S
    Press the D-PAD LEFT = Computer receives the keyboard key LEFT Arrow (using Wi-Fi keyboard) Android receives the keyboard key A
    Press the D-PAD RIGHT = Computer receives the keyboard key RIGHT Arrow (using Wi-Fi keyboard) Android receives the keyboard key D

    So basically, DS2KEY transfers the input to PC and your PC transfers it to your android with the help of a Wifi keyboard app.
    You can configure the key binds as you want, that was just my configuration.
     
  10. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,557
    21,533
    Sep 13, 2009
    Poland
    Gaming Grotto
    Wow... that's a super-convoluted setup. :P
     
  11. Yepi69

    Yepi69 Vivid and busy gamer

    Member
    2,421
    1,018
    Nov 29, 2010
    Portugal
    Behind you
    Hey I was bored, and I was short on money so I wanted to play retro games with a comfy D PAD and buttons :P
     
    Foxi4 likes this.
  12. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,557
    21,533
    Sep 13, 2009
    Poland
    Gaming Grotto
    I know what you mean. I wanted to play PSP games on an HD TV once - connected to it by using RemoteJoy Lite on the PC and passing the signal through to the TV via HDMI. T'was a lot of cables... but it worked. :yaypsp:
     
    Yepi69 likes this.
  13. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    I actually wrote an application which does exactly this (for DS to PC) quite recently. Here's some parts part of my code:

    Code:
    unsigned int keys;
    unsigned short delay = 1;
     
    void sendKeys(unsigned int keys, char keyMapping) {
        outBuf[0] = keyMapping;
        memcpy(outBuf + 1, &keys, 4);
        sendBuf(5);
    }
     
    while(1) {
        for(i = 0; i < delay; i++) swiWaitForVBlank();
        keys = keysHeld();
        swiWaitForVBlank();
        scanKeys();
        sendKeys(keys, KEYS1);
    }
    I went with the option of sending the keys which are held down every other frame (~30 times a second). The delay is used to make sure that not too many packets are being sent (without any delay this happens about every 5 minutes, the keys will lag behind by 2 seconds or so for about 5 seconds)

    Here's some parts of my server code:

    Code:
    #define newpress(key) ((currentKeys & key) && !(lastKeys & key))
    #define release(key) (!(currentKeys & key) && (lastKeys & key))
     
    #define handleKey(DSKey, PCKey) if(newpress(DSKey)) simulateKeyNewpress(PCKey);\
    if(release(DSKey)) simulateKeyRelease(PCKey)
     
    unsigned int lastKeys;
    unsigned int currentKeys;
     
    while(receiveBuffer(5) <= 0) {
        // Waiting
    }
     
    if(buffer[0] == KEYS1) {
        lastKeys = currentKeys;
        memcpy(&currentKeys, buffer + 1, 4);
     
        handleKey(KEY_A, 'A');
        handleKey(KEY_B, 'B');
        handleKey(KEY_SELECT, VK_BACK);
        handleKey(KEY_START, VK_RETURN);
        // ... cut out the rest
    }
    else {
        // Handle key mappings for player 2
    }
    It works reasonably well and you can even run two instances of the server at once on different ports and have 2 DSes connected at once, it'll work just as well. I've even had 7 connected at once and it still plays fine.

    It really shouldn't be hard to port the server to Android, it just needs to receive a 5 byte buffer (first byte for the control mapping, other 4 are an integer which represent all keys on the DS) continuously and simulate key presses.

    I hope this helps someone.
     
  14. cracker

    cracker Nyah!

    Member
    3,155
    452
    Aug 24, 2005
    United States
    Does this use an AdHoc connection like WifiMe?
     
  15. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    The code I posted yesterday doesn't actually include any specific wireless code to send and receive buffers; it's just some snippets of code for someone to use as a template if they want to make their own DS controller client and server.

    Since I don't have a PCI or PCMCIA wireless network card with the RT2500 or RT2560 chipset, I send data to my PC through my router first (using standard dswifi functions).