Commit 0ed3f14864fcd819a7f8ee61d54636e5c904a9c9

Authored by root
1 parent 0d065eeb

terminé !

Showing 34 changed files with 63 additions and 34 deletions   Show diff stats
games/ninvaders/ninvaders-0.1.1/ChangeLog renamed to games/ninvaders/ChangeLog
games/ninvaders/ninvaders-0.1.1/README renamed to games/ninvaders/README
games/ninvaders/ninvaders-0.1.1/aliens.c renamed to games/ninvaders/aliens.c
games/ninvaders/ninvaders-0.1.1/aliens.h renamed to games/ninvaders/aliens.h
games/ninvaders/ninvaders-0.1.1/arduino.c renamed to games/ninvaders/arduino.c
... ... @@ -118,13 +118,11 @@ void stop(struct libusb_config_descriptor *config_desc, libusb_device_handle *ha
118 118  
119 119 void sendData(int endpoint_id, uint8_t data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list){
120 120 if(endpoint_id < 0 || endpoint_id > 1){ printf("(sendData) Wrong endpoint !\nMust be 0 or 1\n"); return; }
121   - int status = libusb_interrupt_transfer(handle, endpoint_desc_list[endpoint_id].bEndpointAddress, (unsigned char *) &data, 1, NULL, TIMEOUT);
122   - if(status!=0 && status!=LIBUSB_ERROR_TIMEOUT){ perror("libusb_interrupt_transfer"); exit(-1); }
  121 + libusb_interrupt_transfer(handle, endpoint_desc_list[endpoint_id].bEndpointAddress, (unsigned char *) &data, 1, NULL, TIMEOUT);
  122 +
123 123 }
124 124  
125   -int receiveData(int endpoint_id, uint8_t *data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list){
126   - if(endpoint_id < 2 || endpoint_id > 3){ printf("(sendData) Wrong endpoint !\nMust be 2 or 3\n"); return -1; }
127   - int status = libusb_interrupt_transfer(handle, endpoint_desc_list[endpoint_id].bEndpointAddress, (unsigned char *) data, 1, NULL, TIMEOUT);
128   - if(status!=0 && status!=LIBUSB_ERROR_TIMEOUT){ perror("libusb_interrupt_transfer"); exit(-1); }
129   - return status;
  125 +void receiveData(int endpoint_id, uint8_t *data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list){
  126 + if(endpoint_id < 2 || endpoint_id > 3){ printf("(sendData) Wrong endpoint !\nMust be 2 or 3\n"); return; }
  127 + libusb_interrupt_transfer(handle, endpoint_desc_list[endpoint_id].bEndpointAddress, (unsigned char *) data, 1, NULL, TIMEOUT);
130 128 }
... ...
games/ninvaders/ninvaders-0.1.1/arduino.h renamed to games/ninvaders/arduino.h
1 1 #ifndef ARDUINO
2 2 #define ARDUINO
3 3  
  4 +#include <libusb-1.0/libusb.h>
  5 +#include <stdio.h>
  6 +#include <stdlib.h>
  7 +#include <signal.h>
  8 +#include <unistd.h>
  9 +
4 10 #define ID_VENDOR 0x2341
5 11 #define ID_PRODUCT 0x01
6 12 #define ENDPOINTS_NUMBER 4
7   -#define TIMEOUT 50
  13 +#define TIMEOUT 10
8 14 #define MAX_DATA 50
9 15  
10 16 void init(libusb_context **context, libusb_device ***devices, ssize_t *devices_count);
... ... @@ -14,6 +20,6 @@ void getEndpoints(struct libusb_config_descriptor *config_desc, struct libusb_en
14 20 void start(libusb_context **context, libusb_device ***devices, libusb_device_handle **handle, struct libusb_config_descriptor **config_desc, struct libusb_endpoint_descriptor *endpoint_desc_list);
15 21 void stop(struct libusb_config_descriptor *config_desc, libusb_device_handle *handle, libusb_device **devices, libusb_context *context);
16 22 void sendData(int endpoint_id, uint8_t data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list);
17   -int receiveData(int endpoint_id, uint8_t *data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list);
  23 +void receiveData(int endpoint_id, uint8_t *data, libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list);
18 24  
19 25 #endif
... ...
games/ninvaders/ninvaders-0.1.1/debian/changelog renamed to games/ninvaders/debian/changelog
games/ninvaders/ninvaders-0.1.1/debian/compat renamed to games/ninvaders/debian/compat
games/ninvaders/ninvaders-0.1.1/debian/control renamed to games/ninvaders/debian/control
games/ninvaders/ninvaders-0.1.1/debian/copyright renamed to games/ninvaders/debian/copyright
games/ninvaders/ninvaders-0.1.1/debian/dirs renamed to games/ninvaders/debian/dirs
games/ninvaders/ninvaders-0.1.1/debian/docs renamed to games/ninvaders/debian/docs
games/ninvaders/ninvaders-0.1.1/debian/links renamed to games/ninvaders/debian/links
games/ninvaders/ninvaders-0.1.1/debian/menu renamed to games/ninvaders/debian/menu
games/ninvaders/ninvaders-0.1.1/debian/ninvaders.1 renamed to games/ninvaders/debian/ninvaders.1
games/ninvaders/ninvaders-0.1.1/debian/rules renamed to games/ninvaders/debian/rules
games/ninvaders/ninvaders-0.1.1/globals.c renamed to games/ninvaders/globals.c
games/ninvaders/ninvaders-0.1.1/globals.h renamed to games/ninvaders/globals.h
games/ninvaders/ninvaders-0.1.1/gpl.txt renamed to games/ninvaders/gpl.txt
games/ninvaders/ninvaders-0.1.1/ind.html renamed to games/ninvaders/ind.html
games/ninvaders/ninvaders-0.1.1/makefile renamed to games/ninvaders/makefile
1 1 CC=gcc
2 2 CFLAGS=-O3 -Wall
3   -LIBS=-l ncurses usb-1.0
  3 +LIBS=-l ncurses -l usb-1.0
4 4  
5   -CFILES=globals.c view.c aliens.c ufo.c player.c ardunio.c nInvaders.c
6   -HFILES=globals.h view.h aliens.h ufo.h player.h ardunio.h nInvaders.h
7   -OFILES=globals.o view.o aliens.o ufo.o player.o ardunio.o nInvaders.o
  5 +CFILES=arduino.c globals.c view.c aliens.c ufo.c player.c nInvaders.c
  6 +HFILES=arduino.h globals.h view.h aliens.h ufo.h player.h nInvaders.h
  7 +OFILES=arduino.o globals.o view.o aliens.o ufo.o player.o nInvaders.o
8 8 all: nInvaders
9 9 rm -f $(OFILES)
10 10  
... ...
games/ninvaders/ninvaders-0.1.1/nInvaders.c renamed to games/ninvaders/nInvaders.c
... ... @@ -48,8 +48,25 @@ int status; // status handled in timer
48 48 #define GAME_EXIT 5
49 49 #define GAME_HIGHSCORE 6
50 50  
51   -
52   -
  51 +libusb_device_handle *handle;
  52 +struct libusb_endpoint_descriptor endpoint_desc_list[ENDPOINTS_NUMBER];
  53 +int waitUSB = 0;
  54 +
  55 +void sendLives(){
  56 + uint8_t toSend = 0x00;
  57 + if(lives == 5) toSend = 0x1F;
  58 + else if(lives == 4) toSend = 0x0F;
  59 + else if(lives == 3) toSend = 0x07;
  60 + else if(lives == 2) toSend = 0x03;
  61 + else if(lives == 1) toSend = 0x01;
  62 + else if(lives == 0) toSend = 0x00;
  63 + if(handle != NULL && endpoint_desc_list != NULL && waitUSB == 0){
  64 + waitUSB = 1;
  65 + usleep(100000); // wait for endpoints to be free (100 ms)
  66 + sendData(0, toSend, handle, endpoint_desc_list);
  67 + waitUSB = 0;
  68 + }
  69 +}
53 70  
54 71 /**
55 72 * initialize level: reset attributes of most units
... ... @@ -64,7 +81,6 @@ static void initLevel()
64 81 drawscore();
65 82 }
66 83  
67   -
68 84 /**
69 85 * evaluate command line parameters
70 86 */
... ... @@ -136,21 +152,26 @@ void drawscore()
136 152 /**
137 153 * reads input from keyboard and do action
138 154 */
139   -void readInput(libusb_device_handle *handle, struct libusb_endpoint_descriptor *endpoint_desc_list)
  155 +void readInput()
140 156 {
141 157 int ch;
142 158 static int lastmove;
143 159  
144 160 timeout(100);
145 161 ch = getch(); // get key pressed
146   - if(ch == -1){
147   - uint8_t data;
148   - int status = receiveData(2, &data, handle, endpoint_desc_list);
149   - if(status == 0){
150   - if(data & 0x10 == 0x10) ch = KEY_LEFT;
151   - else if(data & 0x08 == 0x08) ch = ' ';
152   - else if(data & 0x04 == 0x04) ch = KEY_RIGHT;
  162 +
  163 + static uint8_t data = 0;
  164 + if(ch == -1){ // keyboard first
  165 + usleep(1000000); // slow down inputs (100 ms)
  166 + if(handle != NULL && endpoint_desc_list != NULL && waitUSB == 0)
  167 + receiveData(2, &data, handle, endpoint_desc_list);
  168 + if(data != 0){
  169 + if((data & 0x10) == 0x10) ch = KEY_LEFT;
  170 + else if((data & 0x04) == 0x04) ch = KEY_RIGHT;
  171 + else if((data & 0x08) == 0x08) ch = ' ';
  172 + else return;
153 173 }
  174 + else return;
154 175 }
155 176  
156 177 switch (status) {
... ... @@ -169,6 +190,7 @@ void readInput(libusb_device_handle *handle, struct libusb_endpoint_descriptor *
169 190 level = 0; // reset level
170 191 score = 0; // reset score
171 192 lives = 3; // restore lives
  193 + sendLives();
172 194 status = GAME_NEXTLEVEL;
173 195 } else if (ch == 'q') { // quit game
174 196 status = GAME_EXIT;
... ... @@ -205,6 +227,7 @@ void readInput(libusb_device_handle *handle, struct libusb_endpoint_descriptor *
205 227 status = GAME_NEXTLEVEL;
206 228 } else if (ch == 'L') { // cheat: one more live
207 229 lives++;
  230 + sendLives();
208 231 drawscore();
209 232 } else if (ch == 'q') { // quit game
210 233 status = GAME_EXIT;
... ... @@ -258,6 +281,7 @@ void handleTimer()
258 281 if (aliens_move_counter == 0 && aliensMove() == 1) {
259 282 // aliens reached player
260 283 lives = 0;
  284 + sendLives();
261 285 status = GAME_OVER;
262 286 }
263 287  
... ... @@ -271,6 +295,7 @@ void handleTimer()
271 295 if (aliens_shot_counter == 0 && aliensMissileMove() == 1) {
272 296 // player was hit
273 297 lives--; // player looses one life
  298 + sendLives();
274 299 drawscore(); // draw score
275 300 playerExplode(); // display some explosion graphics
276 301 if (lives == 0) { // if no lives left ...
... ... @@ -342,31 +367,30 @@ void setUpTimer()
342 367  
343 368  
344 369 int go = 1;
345   -void signalINT(int sig){
  370 +/*void signalINT(int sig){
346 371 if(sig == SIGINT){
347 372 go = 0;
348 373 }
349   -}
  374 +}*/
350 375 int main(int argc, char **argv)
351 376 {
352 377 libusb_context *context;
353 378 libusb_device **devices;
354   - libusb_device_handle *handle;
355 379 struct libusb_config_descriptor *config_desc;
356   - struct libusb_endpoint_descriptor endpoint_desc_list[ENDPOINTS_NUMBER];
357 380  
358 381 // start
359 382 start(&context, &devices, &handle, &config_desc, endpoint_desc_list);
360 383  
361 384 // singals
362   - struct sigaction action;
  385 + /*struct sigaction action;
363 386 action.sa_handler = signalINT;
364   - sigaction(SIGINT, &action, NULL);
  387 + sigaction(SIGINT, &action, NULL);*/
365 388  
366   - // nInvaders
367   - weite = 0;
368   - score = 0;
  389 + // nInvaders
  390 + weite = 0;
  391 + score = 0;
369 392 lives = 3;
  393 + sendLives();
370 394 level = 0;
371 395 skill_level = 1;
372 396  
... ... @@ -380,7 +404,7 @@ int main(int argc, char **argv)
380 404 // read keyboard input
381 405 do {
382 406 // do movements and key-checking
383   - readInput(handler, endpoint_desc_list);
  407 + readInput(handle, endpoint_desc_list);
384 408 } while (go);
385 409  
386 410 // stop
... ... @@ -399,6 +423,7 @@ void doScoring(int alienType)
399 423 // every 6000 pts player gets a new live
400 424 if (score % 6000 == 0){
401 425 lives++;
  426 + sendLives();
402 427 }
403 428  
404 429 drawscore(); // display score
... ...
games/ninvaders/ninvaders-0.1.1/nInvaders.h renamed to games/ninvaders/nInvaders.h
games/ninvaders/ninvaders-0.1.1/aliens.o deleted
No preview for this file type
games/ninvaders/ninvaders-0.1.1/globals.o deleted
No preview for this file type
games/ninvaders/ninvaders-0.1.1/player.o deleted
No preview for this file type
games/ninvaders/ninvaders-0.1.1/ufo.o deleted
No preview for this file type
games/ninvaders/ninvaders-0.1.1/view.o deleted
No preview for this file type
games/ninvaders/ninvaders-0.1.1/player.c renamed to games/ninvaders/player.c
games/ninvaders/ninvaders-0.1.1/player.h renamed to games/ninvaders/player.h
games/ninvaders/ninvaders-0.1.1/ufo.c renamed to games/ninvaders/ufo.c
games/ninvaders/ninvaders-0.1.1/ufo.h renamed to games/ninvaders/ufo.h
games/ninvaders/ninvaders-0.1.1/view.c renamed to games/ninvaders/view.c
games/ninvaders/ninvaders-0.1.1/view.h renamed to games/ninvaders/view.h