Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/main.cpp@34:3f8df7ccfcbc, 2016-04-22 (annotated)
- Committer:
- Willheisen
- Date:
- Fri Apr 22 11:28:37 2016 +0000
- Revision:
- 34:3f8df7ccfcbc
- Parent:
- 25:b59758a85ed3
- Child:
- 35:7aef0bbdf335
cfd
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 | |
clementdoreau | 25:b59758a85ed3 | 7 | |
clementdoreau | 25:b59758a85ed3 | 8 | glibr GSensor(p9,p10); |
clementdoreau | 25:b59758a85ed3 | 9 | |
clementdoreau | 25:b59758a85ed3 | 10 | int isr_flag = 0; |
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 | 34:3f8df7ccfcbc | 17 | void detectionMouvement(void const *args) |
Willheisen | 34:3f8df7ccfcbc | 18 | { |
Willheisen | 34:3f8df7ccfcbc | 19 | |
clementdoreau | 25:b59758a85ed3 | 20 | |
clementdoreau | 25:b59758a85ed3 | 21 | |
Willheisen | 34:3f8df7ccfcbc | 22 | //Serial pc(USBTX, USBRX); |
clementdoreau | 25:b59758a85ed3 | 23 | if ( GSensor.ginit() ) { |
Willheisen | 34:3f8df7ccfcbc | 24 | //pc.printf("APDS-9960 initialization complete\n\r"); |
clementdoreau | 25:b59758a85ed3 | 25 | } else { |
Willheisen | 34:3f8df7ccfcbc | 26 | //pc.printf("Something went wrong during APDS-9960 init\n\r"); |
clementdoreau | 25:b59758a85ed3 | 27 | } |
clementdoreau | 25:b59758a85ed3 | 28 | |
Willheisen | 34:3f8df7ccfcbc | 29 | //Start running the APDS-9960 gesture sensor engine |
clementdoreau | 25:b59758a85ed3 | 30 | if ( GSensor.enableGestureSensor(true) ) { |
Willheisen | 34:3f8df7ccfcbc | 31 | //pc.printf("Gesture sensor is now running\n\r"); |
clementdoreau | 25:b59758a85ed3 | 32 | } else { |
Willheisen | 34:3f8df7ccfcbc | 33 | //pc.printf("Something went wrong during gesture sensor init!\n\r"); |
clementdoreau | 25:b59758a85ed3 | 34 | } |
clementdoreau | 25:b59758a85ed3 | 35 | |
clementdoreau | 25:b59758a85ed3 | 36 | while(1) { |
Willheisen | 34:3f8df7ccfcbc | 37 | |
Willheisen | 34:3f8df7ccfcbc | 38 | if(GSensor.isGestureAvailable()) { |
Willheisen | 34:3f8df7ccfcbc | 39 | message_t *message = (message_t*)osPoolAlloc(mpool); |
Willheisen | 34:3f8df7ccfcbc | 40 | message->val = 0; |
clementdoreau | 25:b59758a85ed3 | 41 | switch ( GSensor.readGesture() ) { |
clementdoreau | 25:b59758a85ed3 | 42 | case DIR_UP: |
Willheisen | 34:3f8df7ccfcbc | 43 | message->val = 1; |
clementdoreau | 25:b59758a85ed3 | 44 | break; |
clementdoreau | 25:b59758a85ed3 | 45 | case DIR_DOWN: |
Willheisen | 34:3f8df7ccfcbc | 46 | |
Willheisen | 34:3f8df7ccfcbc | 47 | message->val = 2; |
clementdoreau | 25:b59758a85ed3 | 48 | break; |
clementdoreau | 25:b59758a85ed3 | 49 | case DIR_LEFT: |
Willheisen | 34:3f8df7ccfcbc | 50 | |
Willheisen | 34:3f8df7ccfcbc | 51 | message->val = 3; |
Willheisen | 34:3f8df7ccfcbc | 52 | |
clementdoreau | 25:b59758a85ed3 | 53 | break; |
clementdoreau | 25:b59758a85ed3 | 54 | case DIR_RIGHT: |
Willheisen | 34:3f8df7ccfcbc | 55 | |
Willheisen | 34:3f8df7ccfcbc | 56 | message->val = 4; |
clementdoreau | 25:b59758a85ed3 | 57 | break; |
clementdoreau | 25:b59758a85ed3 | 58 | case DIR_NEAR: |
Willheisen | 34:3f8df7ccfcbc | 59 | //message->val = 0; |
clementdoreau | 25:b59758a85ed3 | 60 | break; |
clementdoreau | 25:b59758a85ed3 | 61 | case DIR_FAR: |
Willheisen | 34:3f8df7ccfcbc | 62 | //message->val = 0; |
clementdoreau | 25:b59758a85ed3 | 63 | break; |
Willheisen | 34:3f8df7ccfcbc | 64 | default: { |
Willheisen | 34:3f8df7ccfcbc | 65 | //message->val = 0; |
Willheisen | 34:3f8df7ccfcbc | 66 | } |
clementdoreau | 25:b59758a85ed3 | 67 | } |
Willheisen | 34:3f8df7ccfcbc | 68 | osMessagePut(queue, (uint32_t)message, osWaitForever); |
Willheisen | 34:3f8df7ccfcbc | 69 | |
Willheisen | 34:3f8df7ccfcbc | 70 | osDelay(10); |
clementdoreau | 25:b59758a85ed3 | 71 | } |
clementdoreau | 25:b59758a85ed3 | 72 | } |
clementdoreau | 25:b59758a85ed3 | 73 | } |
Willheisen | 21:f0cf4173ecdb | 74 | |
Willheisen | 34:3f8df7ccfcbc | 75 | osThreadDef(detectionMouvement, osPriorityNormal, DEFAULT_STACK_SIZE); |
clementdoreau | 23:298a1314fc81 | 76 | |
Willheisen | 9:6f3d8b714a59 | 77 | int main() |
Willheisen | 9:6f3d8b714a59 | 78 | { |
Willheisen | 34:3f8df7ccfcbc | 79 | mpool = osPoolCreate(osPool(mpool)); |
Willheisen | 34:3f8df7ccfcbc | 80 | queue = osMessageCreate(osMessageQ(queue), NULL); |
Willheisen | 34:3f8df7ccfcbc | 81 | Serial pc(USBTX, USBRX); |
Willheisen | 34:3f8df7ccfcbc | 82 | osThreadCreate(osThread(detectionMouvement), NULL); |
Willheisen | 34:3f8df7ccfcbc | 83 | Thread thread(detectionMouvement); // Lancement du thread |
clementdoreau | 25:b59758a85ed3 | 84 | |
clementdoreau | 25:b59758a85ed3 | 85 | cJeu jeu(8,8); |
Willheisen | 34:3f8df7ccfcbc | 86 | //Serial pc(USBTX, USBRX); |
Willheisen | 11:c37922a0a915 | 87 | jeu.initialiser(); |
Willheisen | 34:3f8df7ccfcbc | 88 | jeu.setQueue(&queue, &mpool); |
Willheisen | 24:9f3005f1ba96 | 89 | |
Willheisen | 34:3f8df7ccfcbc | 90 | |
Willheisen | 34:3f8df7ccfcbc | 91 | |
Willheisen | 34:3f8df7ccfcbc | 92 | while (!jeu.partieEnCours()) { |
Willheisen | 21:f0cf4173ecdb | 93 | } |
Willheisen | 21:f0cf4173ecdb | 94 | /////////////////////////////// |
Willheisen | 21:f0cf4173ecdb | 95 | ///A VOIR |
Willheisen | 21:f0cf4173ecdb | 96 | jeu.fin(); |
Willheisen | 13:336220ac9a8b | 97 | |
clementdoreau | 25:b59758a85ed3 | 98 | |
clementdoreau | 25:b59758a85ed3 | 99 | |
Willheisen | 34:3f8df7ccfcbc | 100 | |
clementdoreau | 7:4b283e36b147 | 101 | } |