Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/main.cpp
- Committer:
- clementdoreau
- Date:
- 2016-04-21
- Revision:
- 30:c647da947bd9
- Parent:
- 29:95469b25e187
- Child:
- 31:7313366789f2
File content as of revision 30:c647da947bd9:
#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); pc.printf("Message ==> Envoye \n"); osDelay(10); } } } osThreadDef(detectionMouvement, osPriorityNormal, DEFAULT_STACK_SIZE); int main() { mpool = osPoolCreate(osPool(mpool)); queue = osMessageCreate(osMessageQ(queue), NULL); Serial pc(USBTX, USBRX); osThreadCreate(osThread(detectionMouvement), NULL); Thread thread(detectionMouvement); // Lancement du thread cJeu jeu(16,8); jeu.initialiser(); jeu.setQueue(&queue, &mpool); while (!jeu.partieEnCours()) { } /////////////////////////////// //A VOIR jeu.fin(); }