Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Repo_Noeud_Mobile by
main.cpp
- Committer:
- groygirard
- Date:
- 2015-03-21
- Revision:
- 15:dc18545822b3
- Parent:
- 14:bda91cead7f2
- Child:
- 17:1a634bb615f3
- Child:
- 25:184915935d68
File content as of revision 15:dc18545822b3:
/* S5 Projet - Conception d'un systeme embarque reseaute * main.cpp * * @author Equipe de projet 2 * */ // System libraries #include "mbed.h" #include "rtos.h" // Proprietary libraries #include "Cible.h" #include "CountDown.h" #include "FlexSensor.h" #include "MMA8452Q.h" #define GO 0x01 Serial m_pc(USBTX, USBRX); enum GameMode { GUNNER, RPS, AirGuitar}; //PROTOTYPES DE FONCTION void gunner(void const* args); void rps(void const* args); void airGuitar(void const* args); void get_sensor_data(void const* args); void analyze_sensor_data(void const* args); void analyze_GUNNER(uint8_t axe_x); void analyze_RPS(uint8_t axe_z); void analyze_GUITAR(uint8_t axe_z); void etat_de_jeu(void const *args); void reception_coord(void const *args); uint8_t play = 0; FlexSensor index(DIGITAL, p15); // flex sensor 1. FlexSensor majeur(DIGITAL, p16); // flex sensor 2. FlexSensor annulaire(DIGITAL, p17); // flex sensor 3. CountDown countDown; Accel accel; FlexSensor flex; RtosTimer *sync; GameMode mode = RPS; Thread *threads[3]; Thread* gunner_thread_ptr = NULL; // Possiblement mettre dans un tableau Thread* rps_thread_ptr = NULL; // avec des position codees Thread* airguitar_thread_ptr = NULL; // dans des define. guillaume typedef struct { accel_t accel_data; flex_t flex_data; } sensors_t; Mail<sensors_t, 32> mailbox_sensors; int main(void const* args) { // Initializing the accelerometer accel = Accel(); accel.init_MMA8452(); RtosTimer timer(get_sensor_data, osTimerPeriodic, (void *)0); sync = &timer; switch(mode) { case GUNNER: gunner_thread_ptr = new Thread(gunner); break; case RPS: rps_thread_ptr = new Thread(rps); break; case AirGuitar: airguitar_thread_ptr = new Thread(airGuitar); break; default: break; } Thread thread0(reception_coord); Thread thread1(etat_de_jeu); Thread thread2(analyze_sensor_data); threads[0] = &thread0; threads[1] = &thread1; threads[2] = &thread2; while(true) { } } void gunner(void const* args) { // local variables Cible* cible = new Cible(); countDown.run(); while(true) { // Thread::signal_wait(GO); cible->reset(); int target = rand() % 3; cible->set(target); countDown.run(); } } void rps(void const* args) { // local variables while(true) { Thread::signal_wait(GO); // code... } } void airGuitar(void const* args) { // local variables while(true) { Thread::signal_wait(GO); // code... } } void get_sensor_data(void const* args) { sensors_t *mail = mailbox_sensors.alloc(); mail->accel_data = accel.get_axis_values(); mail->flex_data = flex.get_flex_values(); m_pc.printf("I2C Communication success: Data received %d; %d; %d;\r\n", mail->accel_data.x, mail->accel_data.y, mail->accel_data.z); mailbox_sensors.put(mail); } void analyze_GUNNER(uint8_t axe_x) { } void analyze_RPS(uint8_t axe_z) { } void analyze_GUITAR(uint8_t axe_z) { } void etat_de_jeu(void const *args) { while(true) { Thread::signal_wait(0x1); m_pc.printf("Etat \r\n"); switch(play) { case 0: sync->stop(); break; case 1: sync->start(250); break; default: break; } } } void reception_coord(void const *args) { while(true) { if(play == 0) { play = 1; threads[1]->signal_set(0x1); Thread::wait(2000); } else { play = 0; threads[1]->signal_set(0x1); Thread::wait(2000); } } } void analyze_sensor_data(void const* args) { while (true) { // attente et lecture d'un événement digital osEvent evtD = mailbox_sensors.get(); if (evtD.status == osEventMail) { sensors_t *mail = (sensors_t*)evtD.value.p; // écriture de l'événement en sortie (port série) m_pc.printf("Valeur des trois axes de l'accelerometre: %d, %d, %d\r\n" , mail->accel_data.x, mail->accel_data.y, mail->accel_data.z); switch(mode) { case GUNNER: analyze_GUNNER(mail->accel_data.x); break; case RPS: analyze_RPS(mail->accel_data.z); break; case AirGuitar: analyze_GUITAR(mail->accel_data.z); break; default: break; } mailbox_sensors.free(mail); } } }