Bonjour,

je cherche à créer une interface graphique qui affiche une réticule en temps réel comme étant le centre de gravité d'une personne debout sur la wii balance board. J'ai commencé à modifier le code source et j'ai réussi à obtenir une réticule bouge en fonction de la souris. J'ai ensuite continué à modifier le code pour que cela soit en fonction des coordonnées x et y des infos envoyés par la wiiboard. Mais c'est là que je bloque. Voici une partie du code modifié :
et là le lien de wiiuse-0.14.0-vc9.zip : https://github.com/downloads/rpavlik...0.14.0-vc9.zip
et là la bibliothèque : http://public.vrac.iastate.edu/~rpav...annotated.html

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
	wiimote** wiimotes;
int found, connected;
 
	/*
	 *	Initialize an array of wiimote objects.
	 *
	 *	The parameter is the number of wiimotes I want to create.
	 */
	wiimotes =  wiiuse_init(MAX_WIIMOTES);
 
	found = wiiuse_find(wiimotes, MAX_WIIMOTES, TIME_OUT);
 
    if (found)
        fprintf(stdout,"Wii Balance Board trouvee.\n");
 
    else
    {
        fprintf(stderr, "Aucune Wii Balance Board trouvee.\n");
        return 0;
    }
 
	/*
	 *	Connect to the wiimotes
	 *
	 *	Now that we found some wiimotes, connect to them.
	 *	Give the function the wiimote array and the number
	 *	of wiimote devices we found.
	 *
	 *	This will return the number of established connections to the found wiimotes.
	 */
	connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
	if (connected)
		fprintf(stdout, "Connected to %i wiimotes (of %i found).\n", connected, found);
    else {
		fprintf(stderr, "Echec de la connexion a la Wii Balance Board.\n");
		return 0;
	}
 
 
	/*
	 *	Maybe I'm interested in the battery power of the 0th
	 *	wiimote.  This should be WIIMOTE_ID_1 but to be sure
	 *	you can get the wiimote assoicated with WIIMOTE_ID_1
	 *	using the wiiuse_get_by_id() function.
	 *
	 *	A status request will return other things too, like
	 *	if any expansions are plugged into the wiimote or
	 *	what LEDs are lit.
	 */
	//wiiuse_status(wiimotes[0]);
 
	/*
	 *	This is the main loop
	 *
	 *	wiiuse_poll() needs to be called with the wiimote array
	 *	and the number of wiimote structures in that array
	 *	(it doesn't matter if some of those wiimotes are not used
	 *	or are not connected).
	 *
	 *	This function will set the event flag for each wiimote
	 *	when the wiimote has things to report.
	 */
 
    int go =1;
    while (go) {
		if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
			/*
			 *	This happens if something happened on any wiimote.
			 *	So go through each one and check if anything happened.
			 */
			int i = 0;
			for (; i < MAX_WIIMOTES; ++i) {
				switch (wiimotes[i]->event) {
					case WIIUSE_EVENT:
						/* a generic event occured */
						handle_event(wiimotes[i]);
						break;
 
					case WIIUSE_STATUS:
						/* a status event occured */
						handle_ctrl_status(wiimotes[i]);
						break;
 
					case WIIUSE_DISCONNECT:
					case WIIUSE_UNEXPECTED_DISCONNECT:
						/* the wiimote disconnected */
						handle_disconnect(wiimotes[i]);
						break;
 
					case WIIUSE_READ_DATA:
						/*
						 *	Data we requested to read was returned.
						 *	Take a look at wiimotes[i]->read_req
						 *	for the data.
						 */
						break;
 
					case WIIUSE_WII_BOARD_CTRL_INSERTED:
						printf("Wii Balance Board inseree.\n");
						//go=0;
						break;
 
					case WIIUSE_WII_BOARD_CTRL_REMOVED:
						/* some expansion was removed */
						handle_ctrl_status(wiimotes[i]);
						printf("Une Wii Balance Board a ete retiree.\n");
						//go=0;
						break;
 
					default:
						break;
				}
			}
		}
	}
 
 
	/*
	 *	Disconnect the wiimotes
	 */
	wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
 
	return 0;
}
 
 
/**
 *      @brief Callback that handles an event.
 *
 *      @param wm               Pointer to a wiimote_t structure.
 *
 *      This function is called automatically by the wiiuse library when an
 *      event occurs on the specified wiimote.
 */
void handle_event(struct wiimote_t* wm) {
	printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
 
 
 
    if (SDL_Init(SDL_INIT_VIDEO) == -1) // Initialisation de la SDL (chargement du systeme video). Si erreur :
    {
        fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError()); // Écriture de l'erreur
        exit(EXIT_FAILURE); // On quitte le programme
    }
 
    SDL_Surface *ecran = NULL; // Le pointeur qui va stocker la surface de l'écran
 
    ecran = SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, BITS_COULEURS, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
 
    if (ecran == NULL) // Si l'ouverture a échoué, on le note et on arrête
    {
        fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }
 
    SDL_Event event; // activation de la gestion des évènements par la SDL
    SDL_WM_SetCaption("Votre centre de gravite sur Wii Balance Board", NULL);
    SDL_ShowCursor(SDL_DISABLE); // On cache le curseur
 
 
 
    Uint32 vertGazon = SDL_MapRGB(ecran->format, 41, 164, 23);
 
 
/*  SDL_Surface *forme = NULL;
    forme = SDL_CreateRGBSurface(SDL_HWSURFACE, 220, 180, 32, 0, 0, 0, 0);
    Uint32 blueCiel = SDL_MapRGB(ecran->format, 3, 129, 231);
    SDL_FillRect(forme, NULL, blueCiel);
 
    SDL_Rect pos_forme;
    int coord_x = LARGEUR_ECRAN/2, coord_y = HAUTEUR_ECRAN/2;
    pos_forme.x = coord_x - (forme->w)/2;
    pos_forme.y = coord_y - (forme->h)/2;
 
    int coord_x = LARGEUR_ECRAN/2, coord_y = HAUTEUR_ECRAN/2;
    position_reticule.x = coord_x - (reticule->w)/2;
    position_reticule.y = coord_y - (reticule->h)/2; */
 
 
    SDL_Surface *reticule = NULL;
    reticule = SDL_DisplayFormat(SDL_LoadBMP("reticule_croix.bmp"));
    SDL_SetColorKey(reticule, SDL_SRCCOLORKEY, SDL_MapRGB(reticule->format, 255, 255, 255));
 
    SDL_Rect position_reticule;
 
    int continuer = 1;
    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
                break;
 
            case EXP_WII_BOARD:
 
    	/* show events specific to supported expansions */
	if (wm->exp.type == EXP_WII_BOARD) {
		/* wii balance board */
		struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
		float total = wb->tl + wb->tr + wb->bl + wb->br;
		float x = ((wb->tr + wb->br) / total) * 2 - 1;
		float y = ((wb->tl + wb->tr) / total) * 2 - 1;
		printf("Weight: %f kg @ (%f, %f)\n", total, x, y);
		//printf("Interpolated weight: TL:%f  TR:%f  BL:%f  BR:%f\n", wb->tl, wb->tr, wb->bl, wb->br);
		//printf("Raw: TL:%d  TR:%d  BL:%d  BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr);
                //position_reticule.x = event.motion.x - (reticule->w / 2);
                //position_reticule.y = event.motion.y - (reticule->h / 2);
 
                    position_reticule.x = x*10;
    position_reticule.y = y*10;
                break;
        }
    SDL_FillRect(ecran, NULL, vertGazon);
    SDL_BlitSurface(reticule, NULL, ecran, &position_reticule); // Collage de la forme sur l ecran
    SDL_Flip(ecran); // Rafraîchissement de l'écran
    }

Merci de votre aide!