From 6c4dd3e14a09d8b86cb435ae504961c8d366ff83 Mon Sep 17 00:00:00 2001 From: h3ndrik Date: Thu, 22 Mar 2012 02:10:56 +0100 Subject: [PATCH] all ready and working. inkl leds --- sdljpd | Bin 40675 -> 40675 bytes sdljpd.c | 18 +- sdljpd.c~ | 888 +++++++++++++++++++++++++++++++++++++++++++++++++++++ set_led | Bin 7825 -> 7817 bytes set_led.c | 29 +- set_led.c~ | 60 ++++ 6 files changed, 969 insertions(+), 26 deletions(-) create mode 100644 sdljpd.c~ create mode 100644 set_led.c~ diff --git a/sdljpd b/sdljpd index 4ab58203ed8b1bbdc07bc66245f03adcd75c4c22..c0115ff0c62ac96774ce7890d147a79f70023973 100755 GIT binary patch delta 7725 zcmZWu3tUuH{=avIBWNO{GV)MxKvaBzkisH9#w~K%^soNYM6=|jVOqLAqB6a@ggV}Z zz*A~zExop_eC3p&8xO5z)@>`@KGvFTVOCy3H%v=R*V*syoO=gwuOILEJ-@&2`JHp_ z<-*xI+u1r>aHZcXOAJ)<4Z9<3;@ znY`r}U!Kh!s(O4ccKTuW>q7mp*d^58NblL@Qq7iX&lIVSlpB&D=nT|J?;S<6#&r;joV|KVBu55tbU4M$x$c}Q>act11xUQfeh zSQSD_8&xmc455jYKj2anoqfEAfNZN*nLveb>f!mkAUb(YEm-L+-O3v#^3rAA0J64+ ztc&rpaENs2%x;DLG6E=UhQPM3USnc^LDulk`I+ccEnQ&00*m0Z6G9W)y$DD;t01ey z)*#ZQv(;AUQV3=rH=M78@9-(Ku-1LF2owI4T9zTZNx5kCqcoH?MwI2LigKtKu`sGj zcx6mv--(E983((kJg3s*Jz5))!E0iMsTurCOr)(}2EP(BEb3?MDjVvw{24bZFfM~< z#tu^t^8DC-p{IWd1nP%m@O7~h$0lcp0;$7Yh@JhE$NLc|)gluMh_KT3!0Ip~8cW$a ztn$zZ8EoShWBY0k!%aM&zah@WSHpmS*-W__2pkjprXdC4Mij!ZSK4WF>+B*8*hneH zvUai`J>-^{e@dqGj^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|DmM zkB*O0S=bv-R9>%XdNATr=CJUXsLpBO!(F0O7CsWlUAA2foY$t?)m40CdA~M8@n;yi zhVtjjv*UcGI8Km?ykVD)r)K@-cyzRRE1BdT&wQq7jaMFPp|n> z_3<%lAF|y^;Oo}bsiy-Is=BHmdb;|W+Q6r;yQankCU88N#s~cCSE@K8aj#4Q?c7(& Q@O-_9dtsnp!|K-m4~UPT>;M1& diff --git a/sdljpd.c b/sdljpd.c index d4e9bc1..cffc33a 100644 --- a/sdljpd.c +++ b/sdljpd.c @@ -125,6 +125,8 @@ void Quit( int returnCode ) Mix_FreeMusic(music); music = NULL; + system("./set_led 0 0 0 0"); + SDL_JoystickClose(joystick); SDL_FreeSurface(panel); @@ -325,7 +327,7 @@ void get_buz (void) { plselect = 0; lockbz = TRUE; - system("./set_led 1"); + system("./set_led 1 0 0 0"); Mix_PlayMusic(buzz_sound, 0); } @@ -333,7 +335,7 @@ void get_buz (void) { plselect = 1; lockbz = TRUE; - system("./set_led 2"); + system("./set_led 0 1 0 0"); Mix_PlayMusic(buzz_sound, 0); } @@ -341,7 +343,7 @@ void get_buz (void) { plselect = 2; lockbz = TRUE; - system("./set_led 3"); + system("./set_led 0 0 1 0"); Mix_PlayMusic(buzz_sound, 0); } } @@ -666,7 +668,7 @@ int main( int argc, char **argv ) printf ( "%s\n", SDL_JoystickName ( 0 ) ); - system("./set_led 0"); + system("./set_led 1 1 1 0"); SDL_WM_SetCaption(wmcapt, NULL); /*SDL_WM_SetIcon(SDL_LoadBMP("glpong.bmp"),NULL);*/ @@ -777,7 +779,7 @@ int main( int argc, char **argv ) case SDLK_RETURN: lockbz = FALSE; enp = TRUE; - system("./set_led 0"); + system("./set_led 1 1 1 0"); break; case SDLK_LEFT: @@ -830,7 +832,7 @@ int main( int argc, char **argv ) case SDLK_DELETE: score[plselect]=score[plselect]-pkt[ypos]; lockbz = FALSE; - system("./set_led 0"); + system("./set_led 1 1 1 0"); inp = FALSE; enp = TRUE; break; @@ -852,13 +854,13 @@ int main( int argc, char **argv ) /* Unlock Buzzers */ case SDLK_u: lockbz = FALSE; - system("./set_led 0"); + system("./set_led 1 1 1 0"); break; /* Reset playing field */ case SDLK_r: lockbz = FALSE; - system("./set_led 0"); + system("./set_led 1 1 1 0"); inp = FALSE; enp = FALSE; break; diff --git a/sdljpd.c~ b/sdljpd.c~ new file mode 100644 index 0000000..a936e63 --- /dev/null +++ b/sdljpd.c~ @@ -0,0 +1,888 @@ +/*************************************************************************** + sdljpd.c - Jeopardy on steroids + ------------------- + begin : So 15 Mai 2005 + copyright : (C) 2004 by Frederick Bullik + email : Frederick.Bullik@web.de +***************************************************************************/ +/*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +***************************************************************************/ + +#include +#include +#include +#include /*include datei die das Komandozeilen handling vereinfacht*/ +#include +#include +#include + +#include "SDL.h" +#include "SDL_image.h" +#include "SDL_ttf.h" +#include "SDL_mixer.h" + +/* Define our booleans */ + #define TRUE 1 + #define FALSE 0 + +#define RENDER_MODE 2 //0=solid 1=shaded 2=blended + +/* screen width, height, and bit depth */ +/** \brief Die Bildschirmbreite fuer den Fenstermodus */ +#define SCREEN_WIDTH 1024 +/** \brief Die Bildschirmhohe fuer den Fenstermodus */ +#define SCREEN_HEIGHT 768 +/** \brief Farbtiefe des Bildschirmes */ +#define SCREEN_BPP 24 + +/* make prototype of getopt because of "implicit declaration" */ +int getopt(int argc, char * const argv[], const char *optstring); +extern char *optarg; +extern int optind, opterr, optopt; + +char xpfp[1000]; +char buf[10000]; +char pl1[1000]; +char pl2[1000]; +char pl3[1000]; +char blub[1000]; + +int enp = FALSE; +int inp = FALSE; +signed int score[3] ={0,0,0}; +int scorebuf; +int plselect = 0; +int lockbz = FALSE; +int xpos = 0, ypos = 0; +int solved[5][5] = {{0,0,0,0,0}, + {0,0,0,0,0}, + {0,0,0,0,0}, + {0,0,0,0,0}, + {0,0,0,0,0}}; +int pkt[5] = {100,200,300,400,500}; +int artype; +int countxa = 0; +int countya = 0; +int countxf = 0; +int countyf = 0; +int countxt = 0; + +FILE *file; + +typedef struct s_block{ +char frage[10000]; +char antwort[1000]; +} t_block; + +typedef struct { +char katname[1000]; +} t_kat; + +t_block myblock[5][5]; +t_kat mykat[5]; + +Mix_Music *music = NULL; + +Mix_Music *buzz_sound = NULL; + + +/** \brief This is our SDL surface +* +* Unser Haupt SDL Surface +*/ +SDL_Surface *surface; /*Display Surface*/ +SDL_Surface *kachel; /*hintergrund fuer die Fragefelder*/ +SDL_Surface *bgrnd; /*makriert blockierte Felder */ +SDL_Surface *nfield; /*Score, Namensfekder der Spieler*/ +SDL_Surface *plac; /*kenzeichnung acktiver Spierler*/ +SDL_Surface *afr; /*kenzeichnung des aktives fragen feldes */ +SDL_Surface *text; +SDL_Surface *panel; + +SDL_Rect drect; + +SDL_Color color={255,125,0}; + +TTF_Font *font; + +SDL_Joystick *joystick; + +/** \brief Hier Raeumen wir nach Programablauf auf. +* +* \param returnCode Der Zurueckzugebende Return Code +* \return Gibt den Uebergebenen Code aus +*/ +/* function to release/destroy our resources and restoring the old desktop */ +void Quit( int returnCode ) +{ + Mix_HaltMusic(); + Mix_FreeMusic(music); + music = NULL; + + SDL_JoystickClose(joystick); + + SDL_FreeSurface(panel); + SDL_FreeSurface(text); + SDL_FreeSurface(afr); + SDL_FreeSurface(plac); + SDL_FreeSurface(nfield); + SDL_FreeSurface(kachel); + SDL_FreeSurface(bgrnd); + SDL_FreeSurface(surface); + + TTF_CloseFont(font); + + TTF_Quit(); + + /* clean up the window */ + SDL_Quit( ); + + /*fclose(file);*/ + + + printf("\033[33m sdljpd:\033[m So long, and thanks for all the fish <;))>< \n"); + + /* and exit appropriately */ + exit( returnCode ); +} + +void musicDone(void){ +Mix_HaltMusic(); + Mix_FreeMusic(music); + music = NULL; + music = Mix_LoadMUS("bgmusic-loop.wav"); + Mix_PlayMusic(music, -1); +} + +void music_init(void){ +if(music == NULL) { +music = Mix_LoadMUS("bgmusic-intro.wav"); +Mix_PlayMusic(music, 0); +Mix_HookMusicFinished(musicDone); +} + +} + +void filefill(void) +{ + + if(artype == 1) + { + strcpy(mykat[countxt].katname,blub); + countxt ++; + blub[0] = '\0'; + + } + + if(artype == 2) + { + strcpy(myblock[countxf][countyf].frage,blub); + countyf ++; + blub[0] = '\0'; + + if(countyf >4) + { + countyf = 0; + countxf ++; + } + } + + if(artype == 3) + { + strcpy(myblock[countxa][countya].antwort,blub); + countya ++; + blub[0] = '\0'; + + if(countya >4) + { + countya = 0; + countxa ++; + } + } + +} + +void filefoo (void) +{ + + char ch[100]; + char ach; + + file = fopen(xpfp,"r"); + + if(file == NULL) + { + fprintf(stderr, "Folgende Datei konnte nicht geladen werden:%s\n",xpfp ); + } + + + while (fscanf(file,"%s",ch) ) + { + + if (strcmp(ch,"Topic:") == 0){ + filefill(); + artype = 1; + continue; + } + + if (strcmp(ch,"Frage:")== 0){ + filefill(); + artype = 2; + continue; + } + + if (strcmp(ch,"Antwort:") == 0){ + filefill(); + artype = 3; + continue; + } + + strcat(blub, ch); + strcat(blub, " "); + + if (fscanf(file,"%c",&ach) == EOF){ + filefill(); + break; + } + } + +fclose(file); + +} + +void loadtex( void ) +{ + kachel = IMG_Load("kachel100.jpg"); + + if (kachel == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } + + bgrnd = IMG_Load("bgrnd100.jpg"); + + if (bgrnd == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } + + nfield = IMG_Load("nfield.jpg"); + + if (nfield == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } + + + plac = IMG_Load("sp.jpg"); + + if (plac == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } + + afr = IMG_Load("aq.jpg"); + + if (afr == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } + + panel = IMG_Load("panel1.jpg"); + + if (panel == NULL) + { + fprintf(stderr, "Das Bild konnte nicht geladen werden:%s\n", SDL_GetError()); + exit(-1); + } +} + +void get_buz (void) +{ + int i,n; + + SDL_JoystickUpdate (); + + if(lockbz == FALSE ) + { + for ( i=0; i < SDL_JoystickNumButtons ( joystick ); ++i ) + { + n = SDL_JoystickGetButton ( joystick, i ); + if ( n != 0 ) { + printf ( "found you pressed button %i\n", i ); + if(i == 0) + { + plselect = 0; + lockbz = TRUE; + system("./set_led 1 0 0 0"); + Mix_PlayMusic(buzz_sound, 0); + } + + if(i == 5) + { + plselect = 1; + lockbz = TRUE; + system("./set_led 0 1 0 0"); + Mix_PlayMusic(buzz_sound, 0); + } + + if(i == 10) + { + plselect = 2; + lockbz = TRUE; + system("./set_led 0 0 1 0"); + Mix_PlayMusic(buzz_sound, 0); + } + } + } + } +} + +void draw_sdl (void) +{ + int countx =0; + int county =0; + + int i=0; + + /* Spielfeld geschlumpfe*/ + drect.w = kachel -> w; + drect.h = kachel -> h; + + SDL_SetAlpha(bgrnd, SDL_SRCALPHA | SDL_RLEACCEL, 128); + SDL_SetAlpha(afr, SDL_SRCALPHA | SDL_RLEACCEL, 128); + SDL_SetAlpha(plac, SDL_SRCALPHA | SDL_RLEACCEL, 128); + + get_buz(); + + SDL_FillRect(surface, NULL, 0); + + for(county=0;county<=4;county++) + { + drect.y = (county*100) + 100; + + for(countx=0;countx<=4;countx++) + { + drect.x = (countx*200) + 65; + + SDL_BlitSurface(kachel, NULL, surface, &drect ); + + if(solved[countx][county] == 0){ + SDL_FreeSurface(text); + sprintf(buf,"%i",pkt[county]); + /*if(pkt[county]==100){buf = "100";} + if(pkt[county]==200){buf = "200";} + if(pkt[county]==300){buf = "300";} + f(pkt[county]==400){buf = "400";} + if(pkt[county]==500){buf = "500";}*/ + text = TTF_RenderText_Blended(font, buf,color); + drect.x = drect.x + 23; + SDL_BlitSurface(text,NULL,surface,&drect); + } + + if(solved[countx][county] >=1){ + SDL_BlitSurface(bgrnd, NULL, surface, &drect ); + if(solved[countx][county] == 1) strcpy(buf,pl1); + if(solved[countx][county] == 2) strcpy(buf,pl2); + if(solved[countx][county] == 3) strcpy(buf,pl3); + + drect.x = (countx*200) + 65; + drect.y = drect.y + 23; + + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, buf , color); + drect.w = text -> w; + drect.h = text -> h; + SDL_BlitSurface(text,NULL,surface,&drect); + + drect.y = drect.y - 23; + } + + + } + + for(countx=0;countx<=5;countx++) + { + drect.x = (countx*200) + 65; + drect.y = 45; + strcpy(buf,mykat[countx].katname); + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, buf , color); + SDL_BlitSurface(text,NULL,surface,&drect); + } + + /* The Code for the Panle Drawing goes here */ + if(enp == TRUE){ + drect.w = panel -> w; + drect.h = panel -> h; + drect.x = 185; + drect.y = 100; + SDL_BlitSurface(panel, NULL, surface, &drect ); + drect.x = drect.x + 23; + drect.y = drect.y + 23; + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, "Antwort:" , color); + SDL_BlitSurface(text,NULL,surface,&drect); + + for (i=0; i<=100; i++) + buf[i] = 0; + for (i=0; i w; + drect.h = panel -> h; + drect.x = 185; + drect.y = 100; + SDL_BlitSurface(panel, NULL, surface, &drect); + drect.x = drect.x + 23; + drect.y = drect.y + 23; + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, "Frage:" , color); + SDL_BlitSurface(text,NULL,surface,&drect); + + for (i=0; i<=100; i++) + buf[i] = 0; + for (i=0; i h; + drect.h = nfield -> w; + drect.y = 650; + + for(countx=0;countx<=2;countx++) + { + drect.x = (countx*365) + 50; + SDL_BlitSurface(nfield, NULL, surface, &drect ); + } + + drect.x = (plselect*365) + 50; + SDL_BlitSurface(plac,NULL,surface,&drect); + + drect.y = drect.y + 23; + + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, pl1,color); + drect.x = 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, pl2,color); + drect.x = (365) + 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + SDL_FreeSurface(text); + text = TTF_RenderText_Blended(font, pl3,color); + drect.x = (2*365) + 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + drect.y = drect.y + 30; + + SDL_FreeSurface(text); + scorebuf = score[0]; + sprintf(buf,"%i",scorebuf); + text = TTF_RenderText_Blended(font,buf,color); + drect.x = 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + SDL_FreeSurface(text); + scorebuf = score[1]; + sprintf(buf,"%i",scorebuf); + text = TTF_RenderText_Blended(font,buf,color); + drect.x = (365) + 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + SDL_FreeSurface(text); + scorebuf = score[2]; + sprintf(buf,"%i",scorebuf); + text = TTF_RenderText_Blended(font,buf,color); + drect.x = (2*365) + 65; + SDL_BlitSurface(text,NULL,surface,&drect); + + SDL_Flip(surface); +} + + +int main( int argc, char **argv ) +{ + /** \brief Zählt argc*/ + int option; + + /** \brief Flags zur Übergabe an den Video mode */ + int videoFlags; + + /** \brief Variable der Hauptschleife */ + int done = FALSE; + + /** \brief sammelt Events */ + SDL_Event event; + + /** \brief Display Informationen */ + const SDL_VideoInfo *videoInfo; + + /** \brief Ist unser Fenster Acti? */ + int isActive = TRUE; + + /** \brief String für den Fenstertitel */ + char *wmcapt ="SdlJPD " ; + + int audio_rate = 22050; + Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */ + int audio_channels = 2; + int audio_buffers = 4096; + + strcpy(pl1,"Jessy"); + strcpy(pl2,"Micha"); + strcpy(pl3,"Pierre"); + + strcpy(xpfp,"level.txt"); + + while (( option = getopt(argc, argv, "hf:a:b:c:")) >= 0) + switch (option) + { + case 'h': { + printf("Usage: %s [Optionen] \n Optionen: \n -h print this help Text \n-f jeopardy file\n",argv[0]); + Quit(0); + } + break; + + case 'f': + strcpy(xpfp,optarg); + break; + + case 'a': + strcpy(pl1,optarg); + break; + + case 'b': + strcpy(pl2,optarg); + break; + + case 'c': + strcpy(pl3,optarg); + break; + } + + printf("\n \033[36m sdljpd -- jeopady on steroids \n Copyright (c) 2005 Frederick Bullik \n\n This program is free software; you can redistribute it and/or\n modify it under the terms of the GNU General Public License\n as published by the Free Software Foundation; either version 2\n of the License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program; if not, write to the Free Software \n Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\033[m \n\n"); + + printf("========================================================================\n"); + + filefoo(); + + if(TTF_Init()==-1) { + printf("TTF_Init: %s\n", TTF_GetError()); + exit(2); + } + + font=TTF_OpenFont("subfont.ttf", 26); + + if(!font) { + printf("TTF_OpenFont: %s\n", TTF_GetError()); + /* handle error*/ + } + + /* sprintf(wmcapt,"glpong - %s vs ", player_a );*/ + /* initialize SDL */ + if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0 ) + { + fprintf( stderr, "SDL initialization failed: %s\n", + SDL_GetError( ) ); + Quit( 1 ); + } + + if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { + printf("Unable to open audio!\n"); + exit(1); + } + + Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); + + /* Fetch the video info */ + videoInfo = SDL_GetVideoInfo( ); + + music_init(); + + buzz_sound = Mix_LoadMUS("buzzer.wav"); + + if ( !videoInfo ) + { + fprintf( stderr, "Video query failed: %s\n", + SDL_GetError( ) ); + Quit( 1 ); + } + + printf ( "%i joysticks found: ", SDL_NumJoysticks () ); + + joystick = SDL_JoystickOpen (0); + if(joystick == NULL) { + printf("Unable to open joystick!\n"); + exit(1); + } + + SDL_JoystickEventState ( SDL_QUERY ); + + SDL_JoystickUpdate (); + + printf ( "%s\n", SDL_JoystickName ( 0 ) ); + + system("./set_led 1 1 1 0"); + + SDL_WM_SetCaption(wmcapt, NULL); + /*SDL_WM_SetIcon(SDL_LoadBMP("glpong.bmp"),NULL);*/ + + /* the flags to pass to SDL_SetVideoMode */ + videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */ + videoFlags |= SDL_DOUBLEBUF; + videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ + videoFlags |= SDL_HWSURFACE; + videoFlags |= SDL_HWACCEL; + + SDL_ShowCursor( SDL_DISABLE); + + /* get a SDL surface */ + surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, + videoFlags ); + /* Verify there is a surface */ + if ( !surface ) + { + fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); + Quit( 1 ); + } + + loadtex(); + + /* wait for events */ + while ( !done ) + { + /* handle the events in the queue */ + + while ( SDL_PollEvent( &event ) ) + { + switch( event.type ) + { + + case SDL_ACTIVEEVENT: + /* Something's happend with our focus + * If we lost focus or we are iconified, we + * shouldn't draw the screen + */ + if ( event.active.gain == 0 ) + isActive = FALSE; + else + isActive = TRUE; + break; + + case SDL_VIDEORESIZE: + /* handle resize event */ + surface = SDL_SetVideoMode( event.resize.w, + event.resize.h, + 16, videoFlags ); + if ( !surface ) + { + fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) ); + Quit( 1 ); + } + break; + + case SDL_KEYDOWN: + /* handle key presses */ + switch (event.key.keysym.sym){ + + case SDLK_ESCAPE: + Quit( 0 ); + break; + + case SDLK_q: + Quit( 0 ); + break; + + case SDLK_F1: + /* F1 key was pressed + * this toggles fullscreen mode + */ + SDL_WM_ToggleFullScreen( surface ); + break; + + /* Player left */ + case SDLK_a: + if(plselect >0){ + plselect --;} + enp = FALSE; + inp = FALSE; + break; + + /* Player right */ + case SDLK_d: + if(plselect <2){ + plselect ++;} + enp = FALSE; + inp = FALSE; + break; + + /* Score Add 100 */ + case SDLK_w: + score[plselect] = score[plselect] + 100; + enp = FALSE; + inp = FALSE; + break; + + /* Score Subtract 100 */ + case SDLK_s: + score[plselect] = score[plselect] - 100; + enp = FALSE; + inp = FALSE; + break; + + case SDLK_RETURN: + lockbz = FALSE; + enp = TRUE; + system("./set_led 1 1 1 0"); + break; + + case SDLK_LEFT: + if(enp == FALSE){ + if(xpos >0){ + xpos --; + } + inp = FALSE; + } + break; + + case SDLK_RIGHT: + if(enp == FALSE){ + if(xpos <4){ + xpos ++; + } + inp = FALSE; + } + break; + + case SDLK_UP: + if(enp == FALSE){ + if(ypos >0){ + ypos --; + } + inp = FALSE; + } + break; + + case SDLK_DOWN: + if(enp== FALSE) + { + if(ypos <4){ + ypos ++; + } + inp = FALSE; + } + break; + + /* Right Answer */ + case SDLK_INSERT: + score[plselect]=score[plselect]+pkt[ypos]; + solved[xpos][ypos] = (plselect + 1); + lockbz = TRUE; + enp = FALSE; + inp = TRUE; + break; + + /* Wrong Answer */ + case SDLK_DELETE: + score[plselect]=score[plselect]-pkt[ypos]; + lockbz = FALSE; + system("./set_led 1 1 1 0"); + inp = FALSE; + enp = TRUE; + break; + + /* Mark solved */ + case SDLK_PAGEUP: + solved[xpos][ypos] = (plselect + 1); + break; + + /* Mark unsolved */ + case SDLK_PAGEDOWN: + solved[xpos][ypos] = 0; + + /* Lock Buzzers */ + case SDLK_l: + lockbz = TRUE; + break; + + /* Unlock Buzzers */ + case SDLK_u: + lockbz = FALSE; + system("./set_led 1 1 1 0"); + break; + + /* Reset playing field */ + case SDLK_r: + lockbz = FALSE; + system("./set_led 1 1 1 0"); + inp = FALSE; + enp = FALSE; + break; + + default: + break; + } + break; + + case SDL_QUIT: + /* handle quit requests */ + done = TRUE; + break; + } + break; + } + draw_sdl(); + /*Mix_CloseAudio();*/ + } + + /* clean ourselves up and exit */ + Quit( 0 ); + + /* Should never get here */ + return( 0 ); +} + diff --git a/set_led b/set_led index 0b26e1771486f0f82ea62358aed6e2eb876c7762..5ec15afe9b0e01b8174afd14bb3274864c34d821 100755 GIT binary patch delta 1628 zcmZ8hZ%kWN6u-BBUu%IrD0_WWZQZEUm_RW)U_$oh#`cz(2u2rRnLLsfyVxm~GT9=s zrK0O_3ElZ1&KUnDb2^hDiJ}An!I6C%#uz@#NES>$wm9ZYnhf_m_wu?iZ*tGMzu)iN zd(S=h=4R^Bbps)KKJ&<#%33GkE$0ada7@wKuq%eHI5o~IKxvs6GuW8H#-N6_ig5=I zA#sPo2XQz{KlQZi)gSEL8M#(=Lp?O~^L#k**Vwninkh?V!KLvywvU~U)=UUqwMcnk zLuHBydMpy0v$*nY^IR)`xpfnh8-;)52742mOg3Z2_VO zr_mPp6&x`fWAf6xjxG2-!>j^JmpJ~KVH3j>9Dl(uE=!iqbNmUz7KT6K_%y>-h6nV$ z$OKO@f*o_|C=WQnu$|!!#Ff`}r)OVK(^u5g!u5vdcF#8@Hp25JI z0|RR6s-X5;SHNQ{>#fFRNY|dxCcFkDA48}fTW(-z@|IamEmO5-uCuhgz`uiF4JN3X zw&r1w?)ixa^;>l-PN|toT)ALf#vx^e+P8nIy}iA>!2c#D$mZ3Jm~o%y)$||9!VymO zO(cc=<5=KPTWC*e?CNb@w<-@y#gknTzL8P1k2rJy~+t zGrpZoID2Qp3W)Z~*4oN0`-Q$6$m(i;-#mIu-L3YMf^W#0_V>M-cfEG=UM;X*`-f?8 z!oKO5_y1*StfqQa$>HGQK}7xTk!H*${i~XuSxfb8WXB^c!!f4UXVWu_DI9V2;?%&p z2G{KmIF@OEJbf~_Kw*RMDE$(i5?Wjua%w88C*@HEJ{N)^KQ3UrMoLViGn#CTM%PtTPQW5N7jAySq z*Gh5lI`+_Q*yucD5*%>a`37}^e4kEZ&?XhZJhcpmT_LL}WQG>8+$ms{Si{g$;%3on zK(Fy3JPXbFe#nY$$K9_%EUa=28gYZri0JMYlR?BDC~FNci%2t&24Yba2t{saDhfMt zABX@MWRD{|hiuIF3}PU9svO-0>V`(oR@x02v_mk9wgbfCt<*c*So|)f0#r)HW;gM2 zFOoR-g=7%DL=`-BvDt&kv?06A_ zrW!jX#YBT+-U>`<$ScvKaM8PqsvydeT-5gH1lVE0fPYHEX;TF@Q^t#v)9ElH89 zC&rbS9DOkw|DrXqwQ6GJ51}M*NDIZ7X#X+9)C7r5?t)FAAIUYPUEhqm0beq2-tYH* zGduHUcGUWj`cyd`A9?I-b+dzTGkQWKjwyN@Hd)Whjt#i`xf>vm5zk+mH+&wN$XdcJk6!<3_WE@ubVvG3Snz~YA!7H8hm zI%`MP1m7Y1Ewb_^)&hSbdkxw4O{@*_tbTA>owOT*)<*}QH{eW|eby-gSz1p@nI-g#(HxhY%h6t>izhrA9nX@Ro zol42ce*}5hdKbL5vcX22h8%r%vIEPHWF12JEIw^e6L5{_H`eJ;% zil@%(CB1)5@88t>KE0>K=Is@zvtV1ghwCB5gzUwIDM%!+OeySB*q_6mz^CFCtki^9 zR(EY((<<08H08TKH0{i@nailtE)XwL2eD;v4!$RhnU!KYfo!#ju+j{L+0rx69v`^-TccNI~BA$Z_#1tI7XAIHflo<%!!2K@MM^#>}0#_YLP>0iQ7*USI_ diff --git a/set_led.c b/set_led.c index 88546ae..cf8255d 100644 --- a/set_led.c +++ b/set_led.c @@ -17,6 +17,11 @@ int main(int argc, char **argv) int res = 0; char buf[256]; + if (argc != 5) { + printf("set_led takes 4 arguments\n"); + return 1; + } + /* Open the Device with non-blocking reads. In real life, don't use a hard coded path; use libudev instead. */ fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK); @@ -28,24 +33,12 @@ int main(int argc, char **argv) memset(buf, 0x0, sizeof(buf)); - switch (argv[1][0]) { - case '0': - break; - case '1': - buf[2] = 0xff; - break; - case '2': - buf[3] = 0xff; - break; - case '3': - buf[4] = 0xff; - break; - case '4': - buf[5] = 0xff; - break; - default: - printf("Please specify 0 ... 4 as single argument.\n"); - } + + + if (argv[1][0] == '1') buf[2] = 0xff; + if (argv[2][0] == '1') buf[3] = 0xff; + if (argv[3][0] == '1') buf[4] = 0xff; + if (argv[4][0] == '1') buf[5] = 0xff; /* Send a Report to the Device */ buf[0] = 0x00; /* Report Number */ diff --git a/set_led.c~ b/set_led.c~ new file mode 100644 index 0000000..2c6b1ca --- /dev/null +++ b/set_led.c~ @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int fd; + int res = 0; + char buf[256]; + + if (argc != 5) { + printf("set_led takes 4 arguments\n"); + return 1; + } + + /* Open the Device with non-blocking reads. In real life, + don't use a hard coded path; use libudev instead. */ + fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK); + + if (fd < 0) { + perror("Unable to open device"); + return 1; + } + + memset(buf, 0x0, sizeof(buf)); + + + + if (argv[1][0] == '1') buf[2] = 0xff; + if (argv[1][1] == '1') buf[3] = 0xff; + if (argv[1][2] == '1') buf[2] = 0xff; + if (argv[1][3] == '1') buf[5] = 0xff; + + /* Send a Report to the Device */ + buf[0] = 0x00; /* Report Number */ + buf[1] = 0x00; /* Report ID */ + /*buf[2] = 0x00; Buzzer 1 */ + /*buf[3] = 0x00; Buzzer 2 */ + /*buf[4] = 0x00; Buzzer 3 */ + /*buf[5] = 0x00; Buzzer 4 */ + res = write(fd, buf, 6); + if (res < 0) { + printf("Error: %d\n", errno); + perror("write"); + } else { + /*printf("write() wrote %d bytes\n", res); */ + } + + close(fd); + return 0; +}