Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/main.cpp
- Committer:
- clementdoreau
- Date:
- 2016-04-22
- Revision:
- 35:7aef0bbdf335
- Parent:
- 34:3f8df7ccfcbc
- Child:
- 36:f58a566595ad
File content as of revision 35:7aef0bbdf335:
#include "mbed.h" #include "cJeu.h" #include "glibr.h" #include "cmsis_os.h" glibr GSensor(p9,p10); int isr_flag = 0; osPoolDef(mpool, 16, message_t); osPoolId mpool; osMessageQDef(queue, 16, message_t); osMessageQId queue; void detectionMouvement(void const *args) { Serial pc(USBTX, USBRX); if ( GSensor.ginit() ) { pc.printf("APDS-9960 initialization complete\n\r"); } else { pc.printf("Something went wrong during APDS-9960 init\n\r"); } //Start running the APDS-9960 gesture sensor engine if ( GSensor.enableGestureSensor(true) ) { pc.printf("Gesture sensor is now running\n\r"); } else { pc.printf("Something went wrong during gesture sensor init!\n\r"); } while(1) { if(GSensor.isGestureAvailable()) { message_t *message = (message_t*)osPoolAlloc(mpool); message->val = 0; switch ( GSensor.readGesture() ) { case DIR_UP: message->val = 1; break; case DIR_DOWN: message->val = 2; break; case DIR_LEFT: message->val = 3; break; case DIR_RIGHT: message->val = 4; break; case DIR_NEAR: //message->val = 0; break; case DIR_FAR: //message->val = 0; break; default: { //message->val = 0; } } osMessagePut(queue, (uint32_t)message, osWaitForever); osDelay(10); } } } //osThreadDef(detectionMouvement, osPriorityNormal, DEFAULT_STACK_SIZE); int main() { // CREATION DU THREAD PARALLELE DE LECTURE DE MOUVEMENT Thread thread(detectionMouvement); // CREATION DE LA MESSAGE QUEUE mpool = osPoolCreate(osPool(mpool)); queue = osMessageCreate(osMessageQ(queue), NULL); // GESTION D'UN JEU cJeu* jeu = new cJeu(8,8); // Creation d'un pointeur sur une classe jeu jeu->initialiser(); // Initialisation des réglages principaux jeu->setQueue(&queue, &mpool); // Affectation des pointeurs vers la queue while (!jeu->partieEnCours()) { // Partie en cours } delete jeu; // Fin du jeu ==> Destruction de l'espace pointé }