Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/main.cpp@40:08490d120ec4, 2016-04-24 (annotated)
- Committer:
- Willheisen
- Date:
- Sun Apr 24 22:11:55 2016 +0000
- Revision:
- 40:08490d120ec4
- Parent:
- 38:418278e5eb6b
VERSION FINALE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
clementdoreau | 1:ab5f440f4156 | 1 | #include "mbed.h" |
Willheisen | 8:92d0c4961a16 | 2 | #include "cJeu.h" |
clementdoreau | 25:b59758a85ed3 | 3 | #include "glibr.h" |
Willheisen | 34:3f8df7ccfcbc | 4 | #include "cmsis_os.h" |
Willheisen | 34:3f8df7ccfcbc | 5 | |
Willheisen | 34:3f8df7ccfcbc | 6 | |
Willheisen | 38:418278e5eb6b | 7 | //Instanciation d'un capteur de mouvement |
Willheisen | 38:418278e5eb6b | 8 | //Paramètres: broches I2C SDA, SCL |
clementdoreau | 25:b59758a85ed3 | 9 | glibr GSensor(p9,p10); |
clementdoreau | 25:b59758a85ed3 | 10 | |
Willheisen | 34:3f8df7ccfcbc | 11 | osPoolDef(mpool, 16, message_t); |
Willheisen | 34:3f8df7ccfcbc | 12 | osPoolId mpool; |
Willheisen | 34:3f8df7ccfcbc | 13 | |
Willheisen | 34:3f8df7ccfcbc | 14 | osMessageQDef(queue, 16, message_t); |
Willheisen | 34:3f8df7ccfcbc | 15 | osMessageQId queue; |
Willheisen | 34:3f8df7ccfcbc | 16 | |
Willheisen | 38:418278e5eb6b | 17 | //Fonction de détection des mouvements, appelé par le 2e thread |
Willheisen | 34:3f8df7ccfcbc | 18 | void detectionMouvement(void const *args) |
Willheisen | 34:3f8df7ccfcbc | 19 | { |
clementdoreau | 35:7aef0bbdf335 | 20 | Serial pc(USBTX, USBRX); |
Willheisen | 38:418278e5eb6b | 21 | //Initialisation du capteur |
clementdoreau | 25:b59758a85ed3 | 22 | if ( GSensor.ginit() ) { |
clementdoreau | 35:7aef0bbdf335 | 23 | pc.printf("APDS-9960 initialization complete\n\r"); |
clementdoreau | 25:b59758a85ed3 | 24 | } else { |
clementdoreau | 35:7aef0bbdf335 | 25 | pc.printf("Something went wrong during APDS-9960 init\n\r"); |
clementdoreau | 25:b59758a85ed3 | 26 | } |
clementdoreau | 25:b59758a85ed3 | 27 | |
Willheisen | 38:418278e5eb6b | 28 | //Démarrage du moteur de détection des mouvements |
clementdoreau | 25:b59758a85ed3 | 29 | if ( GSensor.enableGestureSensor(true) ) { |
clementdoreau | 35:7aef0bbdf335 | 30 | pc.printf("Gesture sensor is now running\n\r"); |
clementdoreau | 25:b59758a85ed3 | 31 | } else { |
clementdoreau | 35:7aef0bbdf335 | 32 | pc.printf("Something went wrong during gesture sensor init!\n\r"); |
clementdoreau | 25:b59758a85ed3 | 33 | } |
clementdoreau | 25:b59758a85ed3 | 34 | while(1) { |
Willheisen | 38:418278e5eb6b | 35 | //Si un mouvement est détecté |
Willheisen | 34:3f8df7ccfcbc | 36 | if(GSensor.isGestureAvailable()) { |
Willheisen | 34:3f8df7ccfcbc | 37 | message_t *message = (message_t*)osPoolAlloc(mpool); |
Willheisen | 34:3f8df7ccfcbc | 38 | message->val = 0; |
Willheisen | 38:418278e5eb6b | 39 | //On lit le mouvement détecté et on associe un nombre |
clementdoreau | 25:b59758a85ed3 | 40 | switch ( GSensor.readGesture() ) { |
clementdoreau | 25:b59758a85ed3 | 41 | case DIR_UP: |
Willheisen | 34:3f8df7ccfcbc | 42 | message->val = 1; |
clementdoreau | 25:b59758a85ed3 | 43 | break; |
clementdoreau | 25:b59758a85ed3 | 44 | case DIR_DOWN: |
Willheisen | 34:3f8df7ccfcbc | 45 | message->val = 2; |
clementdoreau | 25:b59758a85ed3 | 46 | break; |
clementdoreau | 25:b59758a85ed3 | 47 | case DIR_LEFT: |
Willheisen | 34:3f8df7ccfcbc | 48 | message->val = 3; |
clementdoreau | 25:b59758a85ed3 | 49 | break; |
clementdoreau | 25:b59758a85ed3 | 50 | case DIR_RIGHT: |
Willheisen | 34:3f8df7ccfcbc | 51 | message->val = 4; |
clementdoreau | 25:b59758a85ed3 | 52 | break; |
clementdoreau | 25:b59758a85ed3 | 53 | case DIR_NEAR: |
clementdoreau | 25:b59758a85ed3 | 54 | break; |
clementdoreau | 25:b59758a85ed3 | 55 | case DIR_FAR: |
clementdoreau | 25:b59758a85ed3 | 56 | break; |
Willheisen | 34:3f8df7ccfcbc | 57 | default: { |
Willheisen | 34:3f8df7ccfcbc | 58 | } |
clementdoreau | 25:b59758a85ed3 | 59 | } |
Willheisen | 38:418278e5eb6b | 60 | //On ajoute la valeur du mouvement à la queue |
Willheisen | 34:3f8df7ccfcbc | 61 | osMessagePut(queue, (uint32_t)message, osWaitForever); |
Willheisen | 34:3f8df7ccfcbc | 62 | osDelay(10); |
clementdoreau | 25:b59758a85ed3 | 63 | } |
clementdoreau | 25:b59758a85ed3 | 64 | } |
clementdoreau | 25:b59758a85ed3 | 65 | } |
Willheisen | 21:f0cf4173ecdb | 66 | |
clementdoreau | 23:298a1314fc81 | 67 | |
Willheisen | 9:6f3d8b714a59 | 68 | int main() |
Willheisen | 36:f58a566595ad | 69 | { |
Willheisen | 38:418278e5eb6b | 70 | // Création du 2e thread pour la détection de mouvement |
clementdoreau | 35:7aef0bbdf335 | 71 | Thread thread(detectionMouvement); |
Willheisen | 38:418278e5eb6b | 72 | // Cération de la Message Queue, pour transmission de la valeur du mouvement détecté |
Willheisen | 34:3f8df7ccfcbc | 73 | mpool = osPoolCreate(osPool(mpool)); |
Willheisen | 34:3f8df7ccfcbc | 74 | queue = osMessageCreate(osMessageQ(queue), NULL); |
Willheisen | 38:418278e5eb6b | 75 | // Instanciation d'un jeu, sur une matrice de 8 colonnes sur 16 lignes |
Willheisen | 38:418278e5eb6b | 76 | cJeu* jeu = new cJeu(8,16); |
Willheisen | 38:418278e5eb6b | 77 | // Initialisation des réglages principaux |
Willheisen | 38:418278e5eb6b | 78 | jeu->initialiser(); |
Willheisen | 38:418278e5eb6b | 79 | // Affectation des pointeurs vers la queue |
Willheisen | 38:418278e5eb6b | 80 | jeu->setQueue(&queue, &mpool); |
Willheisen | 38:418278e5eb6b | 81 | // On lance le jeu |
Willheisen | 36:f58a566595ad | 82 | jeu->nouvelleManche(); |
Willheisen | 38:418278e5eb6b | 83 | // Fin du jeu ==> Destruction de l'espace pointé |
Willheisen | 38:418278e5eb6b | 84 | delete jeu; |
clementdoreau | 7:4b283e36b147 | 85 | } |