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-06
- Revision:
- 12:ebb08773dbdb
- Parent:
- 8:51f6c8f59449
- Child:
- 14:bda91cead7f2
File content as of revision 12:ebb08773dbdb:
/* 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); 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; Thread *threads[2]; 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; 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); } } } int main(void const* args) { // Initializing the accelerometer accel = Accel(); accel.init_MMA8452(); RtosTimer timer(get_sensor_data, osTimerPeriodic, (void *)0); sync = &timer; GameMode mode = GUNNER; 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 thread(reception_coord); Thread thread2(etat_de_jeu); threads[0] = &thread; threads[1] = &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); }