projets:acheves:arcade

Arcade

L'objectif est de réaliser une borne d'arcade complète (joystick/boutons + interface pc + système de jeu). Pour plus d'informations sur ce projet, contacter louis.

J'ai déjà — en mon nom (louis) propre — acheté des composants (arduino + joysticks + arduino).

J'ai « volé » des fils en cave ainsi que du sapin.

La planche avec les boutons (dont joysticks) sont montés.

Code PC pour lancer des event X11

    include <stdio.h>
    include <stdlib.h>
    include <unistd.h>
    include <strings.h>
    include <string.h>
    include <time.h>
    include <X11/Xutil.h>
    include <X11/Xresource.h>
    include <X11/Xlib.h>
    include <X11/extensions/XTest.h> 
    
    Display *dpy;
    
    const int nb_convert = 20 ; const int convert[20][2] =
    {
        // R stick
        {11,XK_Up} ,
        {7,XK_Down} ,
        {8,XK_Right} ,
        {12,XK_Left} ,
    
        //button R
        {4,XK_z} ,
        {6,XK_x} ,
        {3,XK_c} ,
        {2,XK_Control_L} ,
        {1,XK_Shift_L} ,
        {5,XK_Return} ,
    
        // L stick
        {11,XK_w} ,
        {7,XK_s} ,
        {8,XK_d} ,
        {12,XK_a} ,

        //button L
        {17,XK_i} ,
        {18,XK_o} ,
        {13,XK_p} ,
        {16,XK_j} ,
        {14,XK_k} ,
        {15,XK_l}    
    };
    
    int main(int argc, char **argv) {
        Window agresseur, victime;
        XKeyEvent esend;
        if (! (dpy = XOpenDisplay(":0.0"))) {
            fprintf(stderr, "s\n", argv[0], XDisplayName(NULL));
            return -1;
        }
        freopen("/dev/ttyUSB0","r",stdin);
        char last[100];
        char in[100] ;
        int decal = 0 ;
    
        while(1)
        {
            if(scanf("%s",in+decal))
            {
                decal = strlen(in);
                if(in[decal-1] == '>')
                { 
                    if(strcmp(in,last))
                    {
                        printf("%s\n",in);	   
    
                        for(unsigned int a = 0 ; a < strlen(in) ; a++ )
                            if( in[a] != last[a] && (in[a] == 'H' || in[a] == 'L') )
                            {
                                XTestFakeKeyEvent(dpy,  XKeysymToKeycode( dpy , a>=26?XK_a+a-26:XK_A+a),in[a]=='H' , 0);
                                /*
                                for( int i = 0 ; i < nb_convert ; i++ )
                                if( a == convert[i][0] )
                                XTestFakeKeyEvent(dpy,  XKeysymToKeycode( dpy , convert[i][1]),in[a]=='H' , 0);		  
                                */
                            }
    
                        XFlush(dpy);
                        strcpy(last,in) ;
                    }
                    decal = 0 ;
                    in[0] = '\0' ;
                }
            }
        }
    }

Code arduino correspondant

    const int nb_power = 4 ; const int nb_read = 6 ; const int pin_power[nb_power] = {9,10,11,12}; const int pin_read[nb_read] = {2,3,4,5,6,7} ; const int aff = 13 ; int cur = 2 ;
    
    void setup() {
        //set every free to follow 
        for( int x = 0 ; x < nb_power ; x++ )
            pinMode(pin_power[x], INPUT);
        for( int y = 0 ; y < nb_read ; y++ )   
            pinMode(pin_read[y], INPUT);      
        Serial.begin(9600);
    }
    
    void loop() {
        Serial.print("<");
        digitalWrite(aff,LOW);
        for( int x = 0 ; x < nb_power ; x++ )
        {
            pinMode(pin_power[x], OUTPUT);
            digitalWrite(pin_power[x], HIGH);
    
            cur = (cur+1)%(nb_read); 
            for( int y = 0 ; y < nb_read ; y++ )
            {
                //  Serial.print(" ");
                switch(digitalRead(pin_read[y]))
                {
                    case HIGH:
                        digitalWrite(aff,HIGH);
                        Serial.print("H");
                        break;
                    case LOW:
                        Serial.print("L");
                        break;
                    default:
                        Serial.print("d");
                        break;
                }  
            }
            pinMode(pin_power[x], INPUT);
        }
        Serial.println(">");
    }
  • projets/acheves/arcade.txt
  • Dernière modification : 2022/05/05 20:18
  • de hackens