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
Diff: main.cpp
- Revision:
- 52:10fb8ca4ed03
- Parent:
- 51:299408ceee3a
- Child:
- 54:8709cb24abe3
--- a/main.cpp Sat Apr 11 19:30:24 2015 +0000 +++ b/main.cpp Sat Apr 11 22:55:35 2015 +0000 @@ -20,6 +20,7 @@ #define GO 0x01 #define ACTIVATE_FLEX 1 #define ACTIVATE_ACCEL 1 +#define XBEE_TRANSMIT 3 Serial m_pc(USBTX, USBRX); LocalFileSystem local("local"); // file system for config.txt @@ -29,7 +30,7 @@ void rps(void const* args); void airGuitar(void const* args); void flex(void const* args); -void test(void const* args); +void transmit_xbee_data(void const* args); void analyze_sensor_data(void const* args); void configure_GUNNER(); void configure_RPS(); @@ -44,19 +45,20 @@ FlexSensor flexSensors(p18, p19, p20, p17); // flex sensor 1. Accel accel; flex_t flex_data; +Mobile_Vers_Fixe mail_mvf; //RtosTimer *sync; -GameMode_e mode = RPS; +GameMode_e mode = WAITING; short PanId; char GantID; Xbee xbee; -Thread *threads[3]; +Thread *threads[4]; 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 Thread* flex_thread_ptr = NULL; // Lecture des entrées analogiques Thread* Thread_Send_Data_To_Fixe = NULL;// Thread pour envoyer les données des sensors au fixe -Thread* test_thread_ptr = NULL; +Thread* transmit_xbee_data_thread_ptr = NULL; Thread* xbeeReceive = NULL; Thread* threadGetGameMode = NULL; @@ -93,15 +95,17 @@ accel.init_MMA8452(); timer2_init(); #endif - + transmit_xbee_data_thread_ptr = new Thread(transmit_xbee_data); gunner_thread_ptr = new Thread(gunner); flex_thread_ptr = new Thread(flex); rps_thread_ptr = new Thread(rps); + airguitar_thread_ptr = new Thread(airGuitar); threads[GUNNER] = gunner_thread_ptr; threads[RPS] = rps_thread_ptr; threads[AirGuitar] = airguitar_thread_ptr; + threads[XBEE_TRANSMIT] = transmit_xbee_data_thread_ptr; while(true) { } @@ -133,7 +137,6 @@ if (evtD.status == osEventMail) { Fixe_Vers_Mobile *mail = (Fixe_Vers_Mobile*)evtD.value.p; mode = mail->game; - m_pc.printf("Mode \r\n %c", mode); // Envoyer la structure xbee.mailbox_TypeDeJeu.free(mail); switch(mode) { @@ -161,21 +164,19 @@ void gunner(void const* args) { // local variables - while(mode == GUNNER) { - m_pc.printf("Gunner thread"); + while(true) { Thread::signal_wait(0x02); flex_data = flexSensors.get_flex_values(); while(flex_data.index != 0) { wait(10); flex_data = flexSensors.get_flex_values(); } - Mobile_Vers_Fixe *mail = new Mobile_Vers_Fixe; - mail->flexSensor = flex_data; - mail->gants = GantID; - mail->accelData.x = 0x00; - mail->accelData.y = 0x00; - mail->accelData.z = 0x01; - xbee.EnvoyerStructure(mail); + mail_mvf.flexSensor = flex_data; + mail_mvf.gants = 'D'; + mail_mvf.accelData.x = 0x00; + mail_mvf.accelData.y = 0x00; + mail_mvf.accelData.z = 0x01; + threads[XBEE_TRANSMIT]->signal_set(0x01); } } @@ -184,28 +185,30 @@ accel.set_TRANSIENT_MODE(0x18, 0x05, 0x08); // z plan transient motion detection } +void transmit_xbee_data(void const* args) +{ + while(1) + { + Thread::signal_wait(0x01); + xbee.EnvoyerStructure(mail_mvf); + wait(0.1); + } +} + void rps(void const* args) { - Mobile_Vers_Fixe *mailGauche = new Mobile_Vers_Fixe; - mailGauche->flexSensor.index = true; - mailGauche->flexSensor.annulaire = true; - mailGauche->flexSensor.majeur = true; - mailGauche->gants = 'G'; // Gauche ou Droit - mailGauche->accelData.x = 0x01; - mailGauche->accelData.y = 0x00; - mailGauche->accelData.z = 0x01; + Mobile_Vers_Fixe mailGauche; + mailGauche.flexSensor.index = true; + mailGauche.flexSensor.annulaire = true; + mailGauche.flexSensor.majeur = true; + mailGauche.gants = 'G'; // Gauche ou Droit + mailGauche.accelData.x = 0x01; + mailGauche.accelData.y = 0x00; + mailGauche.accelData.z = 0x01; - /* - while (1) { - m_pc.printf("Sending test \r\n"); - wait(1); - xbee.EnvoyerStructure(mailGauche); - //mailbox_Mobile_Vers_Fixe.put(mail); - } - */ // local variables - while(mode == RPS) { + while(true) { Thread::signal_wait(0x02); windup++; m_pc.printf("Decide in : %d \n\r", windup); @@ -213,41 +216,24 @@ windup = 0; Thread::wait(500); //flex_data = flexSensors.get_flex_values(); - /*Mobile_Vers_Fixe *mail = new Mobile_Vers_Fixe; - mail->flexSensor.index = false; - mail->flexSensor.annulaire = false; - mail->flexSensor.majeur = false; - mail->gants = 'D'; // Gauche ou Droit - mail->accelData.x = 0x01; - mail->accelData.y = 0x00; - mail->accelData.z = 0x00;*/ + mail_mvf.flexSensor.index = false; + mail_mvf.flexSensor.annulaire = false; + mail_mvf.flexSensor.majeur = false; + mail_mvf.gants = 'D'; // Gauche ou Droit + mail_mvf.accelData.x = 0x01; + mail_mvf.accelData.y = 0x00; + mail_mvf.accelData.z = 0x00; m_pc.printf("Envoie de mail"); - - xbee.EnvoyerStructure(mailGauche); + threads[XBEE_TRANSMIT]->signal_set(0x01); + mail_mvf = mailGauche; + threads[XBEE_TRANSMIT]->signal_set(0x01); + // send data frame to the fixed mbed for analyze } accel.clear_TRANSIENT_INTERRUPT(); } } -void test(void const* args) -{ - m_pc.printf("TEST Thread\r\n"); - flex_t flex_data = {0,1,0}; - - Mobile_Vers_Fixe *mail = new Mobile_Vers_Fixe; - mail->flexSensor = flex_data; - mail->gants = GantID; - mail->accelData.x = 0x01; - mail->accelData.y = 0x00; - mail->accelData.z = 0x00; - while(1) - { - m_pc.printf("send\r\n"); - xbee.EnvoyerStructure(mail); - wait(1); - } -} void configure_RPS() {