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:
- 55:adde1b6081b8
- Parent:
- 54:8709cb24abe3
- Child:
- 57:ce80fbd67161
--- a/main.cpp Sat Apr 11 22:58:48 2015 +0000 +++ b/main.cpp Sun Apr 12 00:39:07 2015 +0000 @@ -48,7 +48,7 @@ Mobile_Vers_Fixe mail_mvf; //RtosTimer *sync; GameMode_e mode = WAITING; -AirGuitar_opMode_e opMode; +AirGuitar_opMode_e opMode; short PanId; char GantID; Xbee xbee; @@ -80,13 +80,15 @@ xbee.Recevoir(); } -int main(void const* args) +int main(void const* args) { m_pc.printf("\r\n==== PROGRAM START MOBILE ====\r\n"); // Initializing the accelerometer ReadConfig(); //read config file + opMode = PICK; // temporaire m_pc.printf("PANID %x\r\n", PanId); + m_pc.printf("opMode %u\r\n", opMode); xbee = Xbee(PanId, p13, p14); //set PAN ID xbeeReceive = new Thread(startXbeeReceive); threadGetGameMode = new Thread(GetGameMode); @@ -100,7 +102,7 @@ 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; @@ -156,7 +158,7 @@ default: break; } - m_pc.printf("\n\r Mode recu: %x", mode); + m_pc.printf("\n\r Mode recu: %x \n\r", mode); } } } @@ -188,11 +190,10 @@ void transmit_xbee_data(void const* args) { - while(1) - { + while(1) { Thread::signal_wait(0x01); xbee.EnvoyerStructure(mail_mvf); - wait(0.1); + wait(0.1); } } @@ -231,7 +232,7 @@ // send data frame to the fixed mbed for analyze } - accel.clear_TRANSIENT_INTERRUPT(); + accel.clear_TRANSIENT_INTERRUPT(); } } @@ -242,55 +243,47 @@ } void airGuitar(void const* args) -{ - Mobile_Vers_Fixe *mailAirGuitar = new Mobile_Vers_Fixe; - mailAirGuitar->flexSensor.index = true; - mailAirGuitar->flexSensor.annulaire = true; - mailAirGuitar->flexSensor.majeur = true; - if(opMode == PICK) - { - mailAirGuitar->gants = 'D'; // Droit +{ + mail_mvf.flexSensor.index = true; + mail_mvf.flexSensor.annulaire = true; + mail_mvf.flexSensor.majeur = true; + if(opMode == PICK) { + mail_mvf.gants = 'P'; // Droit + } else if(opMode == FRET) { + mail_mvf.gants = 'F'; // Gauche } - else if(opMode == FRET) - { - mailAirGuitar->gants = 'G'; // Gauche - } - mailAirGuitar->accelData.x = 0x00; - mailAirGuitar->accelData.y = 0x00; - mailAirGuitar->accelData.z = 0x00; - + mail_mvf.accelData.x = 0x01; + mail_mvf.accelData.y = 0x01; + mail_mvf.accelData.z = 0x01; + flex_t flex_data; - - switch(opMode) - { - case PICK: - while(true) - { + while(true) { + switch(opMode) { + case PICK: Thread::signal_wait(0x02); - mailAirGuitar->accelData.x = 0x01; - xbee.EnvoyerStructure(mailAirGuitar); - } - break; //unreachable. - case FRET: - while(true) - { + threads[XBEE_TRANSMIT]->signal_set(0x01); + accel.clear_TRANSIENT_INTERRUPT(); + break; + case FRET: + flex_data = flexSensors.get_flex_values(); - if(flex_data != mailAirGuitar->flexSensor) - { - mailAirGuitar->flexSensor = flex_data; - xbee.EnvoyerStructure(mailAirGuitar); + if(flex_data != mail_mvf.flexSensor) { + mail_mvf.flexSensor = flex_data; + threads[XBEE_TRANSMIT]->signal_set(0x01); } Thread::wait(50); - } - break; //unreachable. - default: - break; + + break; + default: + break; + } + } } void configure_GUITAR() { - accel.set_TRANSIENT_MODE(0x18, 0x05, 0x08); // z plan transient motion detection + accel.set_TRANSIENT_MODE(0x12, 0x05, 0x08); // z plan transient motion detection } //read config file @@ -305,14 +298,14 @@ fscanf(file, "%x", &buffer); GantID = buffer[0]; - + char mode[4]; fscanf(file, "%x", mode); if(mode == "FRET") opMode = FRET; if(mode == "PICK") opMode = PICK; - + fclose(file); //close file } else { //if file is not found m_pc.printf("ERROR AT CONFIG FILE \r\n");