Skip to content

Commit

Permalink
Added basic input support - events are logged but probably not proces…
Browse files Browse the repository at this point in the history
…sed correctly.
  • Loading branch information
j005u committed Mar 2, 2022
1 parent 4d4c226 commit 5c73649
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 11 deletions.
7 changes: 4 additions & 3 deletions jni/debug.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
ndk-build -j8
adb push ../obj/local/armeabi-v7a/fbdoom /blackbox/
#something about $HOME not being defined if we don't pipe the input in but provide as an arg
ndk-build -j8 && \
adb push ../obj/local/armeabi-v7a/fbdoom /blackbox/ && \
echo "setprop dji.glasses_wm150_service 0 && cd /blackbox && chmod o+x fbdoom && ./fbdoom" | adb shell

#something about $HOME not being defined if we don't pipe the input in but provide as an arg
2 changes: 1 addition & 1 deletion jni/fbdoom/src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void IdentifyVersion (void)
home = getenv("HOME");
if (!home)
I_Error("Please set $HOME to your home directory");
sprintf(basedefault, "%s/Library/Application support/", home);
sprintf(basedefault, "%s/.doomrc", home);
#endif

if (M_CheckParm ("-shdev"))
Expand Down
121 changes: 116 additions & 5 deletions jni/fbdoom/src/device/i_fb_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <stdint.h>
#include "v_video.h"
#include "m_argv.h"
#include "d_event.h"


//static FILE* fbfd = 0;
//static struct fb_var_screeninfo vinfo;
Expand All @@ -29,7 +31,12 @@ static IDirectFBSurface *primary;
static IDirectFBPalette *palette;

/* Input interfaces: device and its buffer */
static IDirectFBEventBuffer *events;
static IDirectFBEventBuffer *eventsbuffer;

IDirectFBInputDevice *keyboard;
IDirectFBEventBuffer *keybuffer;
DFBInputEvent devt;


static int screen_width, screen_height;

Expand All @@ -49,15 +56,17 @@ void I_InitGraphics (void)
DFBResult err;
DFBSurfaceDescription sdsc;
DFBSurfaceDescription pdsc;



DFBCHECK(DirectFBInit( &myargc, &myargv ));

/* create the super interface */
DFBCHECK(DirectFBCreate( &dfb ));

/* create an event buffer for all devices */
DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
DFB_FALSE, &events ));
/*DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
DFB_FALSE, &eventsbuffer ));*/

/* set our cooperative level to DFSCL_FULLSCREEN
for exclusive access to the primary layer */
Expand Down Expand Up @@ -85,14 +94,116 @@ void I_InitGraphics (void)
/* Figure out the size of the screen in bytes */
screensize = screen_width * screen_height * 32 / 8;
printf("Screen width is %d, height is %d size is %d\n",screen_width, screen_height,screensize);


DFBCHECK(dfb->GetInputDevice( dfb, DIDID_ANY, &keyboard ));
DFBCHECK(keyboard->CreateEventBuffer( keyboard, &keybuffer ));


}


//
// Translates the key currently in dfbinputevent
//

int dlatekey(void)
{

int rc;

switch(rc = devt.key_symbol)
{
case DIKS_CURSOR_LEFT: rc = KEY_LEFTARROW; break;
case DIKS_CURSOR_RIGHT: rc = KEY_RIGHTARROW; break;
case DIKS_CURSOR_DOWN: rc = KEY_DOWNARROW; break;
case DIKS_CURSOR_UP: rc = KEY_UPARROW; break;
case DIKS_ESCAPE: rc = KEY_ESCAPE; break;
case DIKS_RETURN: rc = KEY_ENTER; break;
case DIKS_TAB: rc = KEY_TAB; break;
case DIKS_F1: rc = KEY_F1; break;
case DIKS_F2: rc = KEY_F2; break;
case DIKS_F3: rc = KEY_F3; break;
case DIKS_F4: rc = KEY_F4; break;
case DIKS_F5: rc = KEY_F5; break;
case DIKS_F6: rc = KEY_F6; break;
case DIKS_F7: rc = KEY_F7; break;
case DIKS_F8: rc = KEY_F8; break;
case DIKS_F9: rc = KEY_F9; break;
case DIKS_F10: rc = KEY_F10; break;
case DIKS_F11: rc = KEY_F11; break;
case DIKS_F12: rc = KEY_F12; break;

case DIKS_BACKSPACE:
case DIKS_DELETE: rc = KEY_BACKSPACE; break;

case DIKS_PAUSE: rc = KEY_PAUSE; break;

case DIKS_EQUALS_SIGN: rc = KEY_EQUALS; break;

case DIKS_MINUS_SIGN: rc = KEY_MINUS; break;

case DIKS_SHIFT:
rc = KEY_RSHIFT;
break;

case DIKS_CONTROL:
rc = KEY_RCTRL;
break;

case DIKS_ALT:
case DIKS_ALTGR:
rc = KEY_RALT;
break;

default:
if (rc >= DIKS_SPACE && rc <= DIKS_TILDE)
rc = rc - DIKS_SPACE + ' ';
if (rc >= 'A' && rc <= 'Z')
rc = rc - 'A' + 'a';
break;
}

return rc;

}


void I_StartTic (void)
{

event_t event;
while(keybuffer->GetEvent( keybuffer, DFB_EVENT(&devt)) == DFB_OK) {
printf("Key event type %d code %d id %d symbol %d\n", devt.type, devt.key_code, devt.key_id, devt.key_symbol);

switch (devt.type)
{
case DIET_KEYPRESS:

event.type = ev_keydown;
event.data1 = dlatekey();
D_PostEvent(&event);
// fprintf(stderr, "k");
break;
case DIET_KEYRELEASE:
//printf("Key up %d\n",devt.key_symbol);

event.type = ev_keyup;
event.data1 = dlatekey();
D_PostEvent(&event);
// fprintf(stderr, "ku");
break;
}

}
}


void I_ShutdownGraphics(void)
{
events->Release( events );
dfb->Release( dfb );
eventsbuffer->Release( eventsbuffer );
keyboard->Release( keyboard );
dfb->Release( dfb );

}

Expand Down
8 changes: 6 additions & 2 deletions jni/fbdoom/src/device/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "m_argv.h"
#include "d_main.h"


int main(int argc, const char** argv)
{
myargc = argc;
Expand All @@ -22,14 +23,17 @@ int main(int argc, const char** argv)

// tcsetattr(0, TCSANOW, &new_settings);

/* get an interface to the primary keyboard and create an
input buffer for it */

D_DoomMain();

// tcsetattr(0, TCSANOW, &initial_settings);

return 0;
}

void I_StartTic (void)
/*void I_StartTic (void)
{
// event_t event = {0,0,0,0};
// char key = getchar();
Expand All @@ -48,4 +52,4 @@ void I_StartTic (void)
// event.data1 = key;
// D_PostEvent(&event);
// }
}
}*/

0 comments on commit 5c73649

Please sign in to comment.