From f0cf51e49512195ad4372d8c117a60179e2873d7 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 9 Oct 2020 18:35:57 -0500 Subject: forgot the wiimote files --- src/hackvr_xdiewii.c | 1 + src/mouse_wii.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 120000 src/hackvr_xdiewii.c create mode 100644 src/mouse_wii.c diff --git a/src/hackvr_xdiewii.c b/src/hackvr_xdiewii.c new file mode 120000 index 0000000..e4c9ddd --- /dev/null +++ b/src/hackvr_xdiewii.c @@ -0,0 +1 @@ +hackvr.c \ No newline at end of file diff --git a/src/mouse_wii.c b/src/mouse_wii.c new file mode 100644 index 0000000..863e4e2 --- /dev/null +++ b/src/mouse_wii.c @@ -0,0 +1,143 @@ +#include +#include +#include +#include +#include + +#include "graphics_c3.h" +#include "mouse.h" + +extern struct hvr_global global; +extern struct gra_global gra_global; + +//#define MOUSEDEV "/dev/input/mouse0" //just one of the many possibly connected mice. (just in case you want to use one mouse for one thing and another mouse for something else) +#define MOUSEDEV "/dev/input/event19" + +int mfd = -1; + +//#define "mouse.h" //I guess + +struct wtf {//totals to 24 + struct timeval time; + unsigned short type; + unsigned short code; + unsigned int state; +}; + +int mouse_init() { + if((mfd=open(MOUSEDEV,O_RDWR)) == -1) { + fprintf(stderr,"# failed to open mouse: %d\n",mfd); + } + return mfd; +} + +//buttons are: +//0 for left click, 1 for right click, 2 is middle-click + +//in the hackvr mouse map, right is 2, left is 0 and center is 1? +#define DIE_MOUSE_LEFT 0 +#define DIE_MOUSE_RIGHT 1 +#define DIE_MOUSE_CENTER 2 +//it doesn't care if you have X11 buttons swapped around ofc. +char die2map(char d) {//edit this function if you want to change your primary and secondary mouse button. + switch(d) { + case DIE_MOUSE_LEFT: return MOUSE_PRIMARY; + case DIE_MOUSE_RIGHT: return MOUSE_SECONDARY; + case DIE_MOUSE_CENTER: return MOUSE_TERTIARY; + default: return -1; + } +} + +int mouse_event_handler() { + struct wtf ie; + int butt; + int l; + int i;//this is a DIE_MOUSE value + unsigned char m;//this is a hackvr mouse map value. + int redrawplzkthx=0; + memset(&ie,0,sizeof(ie)); + if(mfd == -1) { + mfd=open(MOUSEDEV,O_RDWR); + //probably don't need nonblock anymore. + //fcntl(mfd,F_SETFL,O_NONBLOCK); + } + if(mfd == -1) { + fprintf(stderr,"# mouse shit fucked up.\n"); + return 1; + } + if((l=read(mfd,&ie,sizeof(ie))) > 0) { + if(ie.code == 3) global.camera.r.x.d=ie.state; + if(ie.code == 4) global.camera.r.y.d=ie.state; + if(ie.code == 5) global.camera.r.z.d=ie.state; +/* + for(i=0;i<3;i++) {//we need to loop over all buttons each event. :/ + butt=ie.type & 0x07 & (1< RIGHT) gra_global.mouse.x = RIGHT; + gra_global.mouse.y+=ie.dy; + if(gra_global.mouse.y < BOTTOM) gra_global.mouse.y = BOTTOM; + if(gra_global.mouse.y > TOP) gra_global.mouse.y = TOP; + fprintf(stderr,"# mouse: x:%F y:%F\n",gra_global.mouse.x,gra_global.mouse.y); + if(gra_global.mousemap[MOUSE_SECONDARY] == 1) {//if "right" click is held down... this is somehow primary click + global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[MOUSE_SECONDARY].y); + global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[MOUSE_SECONDARY].x); + } + redrawplzkthx=1; + } +*/ + } + if(redrawplzkthx) { + redraw(); + return 1; + } + return 0; +} +/* +#include +#include + + +int main(int argc,char *argv[]) { + int i; + struct input_event ie; + int x,y,z; + while(!feof(stdin)) { + read(0,&ie,sizeof(struct input_event)); + printf("type: %d :: ",ie.type); + if(ie.code == 3) x=ie.state; + if(ie.code == 4) y=ie.state; + if(ie.code == 5) z=ie.state; + printf("%15d %15d %15d",x,y,z); + //for(i=0;i<16;i++) { + // printf(" %02x",(unsigned char)ae.derp[i]); + //} + printf("\n"); + } +} +*/ -- cgit v1.2.3