Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LeapTV controller code (reversed by is0-mick 2015)
- #include <dlfcn.h>
- #include "SDL.h"
- typedef int boolean;
- enum {false,true};
- struct LFController {char Abutton;char Bbutton; char HomeButton; char QuestionButton; char WandShape; char VShape; char StickX; char StickY;char AccelX; char unknown; char AccelY; char unknown1; char AccelZ; char Counter; char Batt; char unknown2;};
- boolean leftpressed = false;
- boolean rightpressed = false;
- boolean uppressed = false;
- boolean downpressed = false;
- boolean buttonapressed = false;
- boolean buttonbpressed = false;
- boolean buttonhomepressed = false;
- boolean buttonquestionpressed = false;
- boolean debug = false;
- void CallbackFunction(void* a,char* data,int length)
- {
- printf("This is our callback1!\n");
- }
- void GATMCallbackFunction(void* a,struct LFController* LFC,int length)
- {
- //struct LFController LFC;
- //printf("%p %p %d \n",a,data,length);
- //int i=0;
- //char* temp = (char*)b;
- /*
- for(i=0;i<length;i++)
- {
- printf("%0x, ",data[i]);
- }
- */
- if (debug)
- {
- printf("is0-micks callback! \n");
- printf("BUTTON A %0x\r\n",LFC->Abutton);
- printf("BUTTON B %0x\r\n",LFC->Bbutton);
- printf("BUTTON HOME %0x\r\n",LFC->HomeButton);
- printf("BUTTON QUESTION %0x\r\n",LFC->QuestionButton);
- printf("BUTTON Wand Shape %0x\r\n",LFC->WandShape);
- printf("BUTTON V Shape %0x\r\n",LFC->VShape);
- printf("BUTTON Stick X %0x\r\n",LFC->StickX);
- printf("BUTTON Stick Y %0x\r\n",LFC->StickY);
- printf("Accel X %0x\r\n",LFC->AccelX);
- printf("Accel Y %0x\r\n",LFC->AccelY);
- printf("Accel Z %0x\r\n",LFC->AccelZ);
- printf("Batt Level %0x\r\n",LFC->Batt);
- }
- if ((LFC->StickY > 0xC0) && (uppressed == false))
- {
- printf("UP\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_UP;
- SDL_PushEvent(&sdlevent);
- uppressed = true;
- }
- else
- {
- if ((LFC->StickY < 0xC0) &&(uppressed == true))
- {
- uppressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_UP;
- SDL_PushEvent(&sdlevent);
- }
- }
- if (LFC->StickY < 0x3F && downpressed == false)
- {
- printf("DOWN\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_DOWN;
- SDL_PushEvent(&sdlevent);
- downpressed = true;
- }
- else
- {
- if (LFC->StickY > 0x3F && downpressed == true)
- {
- downpressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_DOWN;
- SDL_PushEvent(&sdlevent);
- }
- }
- if (LFC->StickX > 0xC0 && rightpressed == false)
- {
- printf("RIGHT\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_RIGHT;
- SDL_PushEvent(&sdlevent);
- rightpressed = true;
- }
- else
- {
- if (LFC->StickX < 0xC0 && rightpressed == true)
- {
- rightpressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_RIGHT;
- SDL_PushEvent(&sdlevent);
- }
- }
- if (LFC->StickX < 0x3F && leftpressed == false)
- {
- printf("LEFT\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_LEFT;
- SDL_PushEvent(&sdlevent);
- leftpressed = true;
- }
- else
- {
- if (LFC->StickX > 0x3F && leftpressed == true)
- {
- leftpressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_LEFT;
- SDL_PushEvent(&sdlevent);
- }
- }
- if ((LFC->Abutton == 0x01) && (buttonapressed == false))
- {
- printf("BUTTONA\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_LCTRL;
- SDL_PushEvent(&sdlevent);
- buttonapressed = true;
- }
- else
- {
- if ((LFC->Abutton == 0x00) && (buttonapressed == true))
- {
- buttonapressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_LCTRL;
- SDL_PushEvent(&sdlevent);
- }
- }
- if ((LFC->Bbutton == 0x01) && (buttonbpressed == false))
- {
- printf("BUTTONB\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_LALT;
- SDL_PushEvent(&sdlevent);
- buttonbpressed = true;
- }
- else
- {
- if ((LFC->Bbutton == 0x00) && (buttonbpressed == true))
- {
- buttonbpressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_LALT;
- SDL_PushEvent(&sdlevent);
- }
- }
- if (LFC->HomeButton == 0x01 && buttonhomepressed == false)
- {
- printf("HomeButton\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_ESCAPE;
- SDL_PushEvent(&sdlevent);
- buttonhomepressed = true;
- }
- else
- {
- if (buttonhomepressed == true && LFC->HomeButton == 0x00)
- {
- buttonhomepressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_ESCAPE;
- SDL_PushEvent(&sdlevent);
- }
- }
- if (LFC->QuestionButton == 0x01 && buttonquestionpressed == false)
- {
- printf("BUTTONQuestion\n");
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_5;
- SDL_PushEvent(&sdlevent);
- sdlevent.type=SDL_KEYDOWN;
- sdlevent.key.keysym.sym=SDLK_1;
- SDL_PushEvent(&sdlevent);
- buttonquestionpressed = true;
- }
- else
- {
- if (buttonquestionpressed == true && LFC->QuestionButton == 0x00)
- {
- buttonquestionpressed = false;
- SDL_Event sdlevent;
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_5;
- SDL_PushEvent(&sdlevent);
- sdlevent.type=SDL_KEYUP;
- sdlevent.key.keysym.sym=SDLK_1;
- SDL_PushEvent(&sdlevent);
- }
- }
- }
- void* handle;
- typedef char* (*tdBTIO_GetLocalAddress)();
- typedef int* (*tdBTIO_QueryStatus)();
- typedef int* (*tdBTIO_WriteValue)(int, int, void* ,int, char*);
- typedef int* (*tdBTIO_SendCommand)(void*, int, void*, int);
- typedef int* (*tdBTIO_ConnectToDevice)(int, char *);
- typedef int* (*tdBTIO_Init)(void*);
- typedef int* (*tdBTIO_ScanForDevices)(int,int);
- typedef int* (*tdBTIO_Exit)(void);
- int StartControls() {
- // Declare Functions
- //arbitrary BTIO_DisconnectDevice;
- char *error;
- // Open libBRIO.so
- void* handle = dlopen ("/usr/lib/libBTIO.so", RTLD_LAZY);
- if (!handle) {
- fputs (dlerror(), stderr);
- return(1);
- }
- tdBTIO_SendCommand BTIO_SendCommand = (tdBTIO_SendCommand)dlsym(handle, "BTIO_SendCommand");
- if ((error = dlerror()) != NULL) {
- fputs(error, stderr);
- fputs(" @ BTIO_SendCommand\n", stderr);
- return(1);
- }
- tdBTIO_Init BTIO_Init =
- (tdBTIO_Init)dlsym(handle, "BTIO_Init");
- if ((error = dlerror()) != NULL) {
- fputs(error, stderr);
- fputs(" @ BTIO_Init\n", stderr);
- return(1);
- }
- int* ControllerNum = BTIO_Init((void*)&CallbackFunction);//param seems to be *void callback pointer?
- printf("BTIO_Init returned val of %d \n", ControllerNum);
- //sleep(5);
- int* SendComRet = 0;
- void* data = (void*)&GATMCallbackFunction;
- SendComRet = BTIO_SendCommand(ControllerNum,1,data,4);
- printf("Send Command returned val of %d \n", SendComRet);
- SendComRet = BTIO_SendCommand(ControllerNum,2,data,4);
- printf("call back pointer = %p\n",&GATMCallbackFunction);
- SendComRet = BTIO_SendCommand(ControllerNum,9,(void*)&GATMCallbackFunction,4);
- printf("Send Command returned val of %d \n", SendComRet);
- return 0;
- }
- void StopControls()
- {
- char *error;
- tdBTIO_Exit BTIO_Exit = (tdBTIO_Exit)dlsym(handle, "BTIO_Exit");
- if ((error = dlerror()) != NULL) {
- fputs(error, stderr);
- fputs(" @ BTIO_Exit\n", stderr);
- }
- BTIO_Exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement