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:
- 22:cccb77300fd5
- Parent:
- 17:1a634bb615f3
- Child:
- 26:5700cde2350b
- Child:
- 30:389d09853cd1
--- a/main.cpp Sun Mar 22 17:32:47 2015 +0000 +++ b/main.cpp Sun Mar 22 19:57:40 2015 +0000 @@ -14,13 +14,14 @@ #include "CountDown.h" #include "FlexSensor.h" #include "MMA8452Q.h" +#include "Structure.h" +#include "Xbee.h" #define GO 0x01 #define ACTIVATE_ACCEL 0 Serial m_pc(USBTX, USBRX); - -enum GameMode { GUNNER, RPS, AirGuitar}; +LocalFileSystem local("local"); // file system for config.txt //PROTOTYPES DE FONCTION void gunner(void const* args); @@ -34,13 +35,16 @@ void analyze_GUITAR(uint8_t axe_z); void etat_de_jeu(void const *args); void reception_coord(void const *args); +void ReadConfig(); uint8_t play = 0; FlexSensor flexSensors(p15, p16, p17); // flex sensor 1. Accel accel; RtosTimer *sync; -GameMode mode = GUNNER; +GameMode_e mode = GUNNER; +short PanId; +Xbee* xbee = NULL; Thread *threads[3]; Thread* gunner_thread_ptr = NULL; // Possiblement mettre dans un tableau @@ -60,6 +64,11 @@ { m_pc.printf("==== PROGRAM START MOBILE ====\r\n"); // Initializing the accelerometer + + ReadConfig(); //read config file + m_pc.printf("PANID %#04x\r\n", PanId); + xbee = new Xbee(PanId, p13, p14); //set PAN ID + #if ACTIVATE_ACCEL accel = Accel(); accel.init_MMA8452(); @@ -111,6 +120,8 @@ flex_t data = flexSensors.get_flex_values(); m_pc.printf("index: %u, majeur: %u, annulaire: %u\n\r", data.index, data.majeur, data.annulaire); + char data_test[3] = {data.index, data.majeur, data.annulaire}; + xbee->EnvoyerDonnees(data_test,3); } } @@ -222,3 +233,29 @@ } } } + +//read config file +void ReadConfig() +{ + FILE* file = fopen("/local/config.txt","r"); + if (file != NULL) + { + char buffer[2]; + //char time; + //char selector; + + fscanf(file, "%x", &buffer); //panID = 2 char + //fscanf(file, "%d", &time); //read period = 1 decimal + //fscanf(file, "%d", &selector); //end device selector = 1 decimal + + PanId = buffer[1] << 8 | buffer[0]; //set PAN ID global variable + //ReadPeriod = time; //set read period global variable + //EndDeviceSelection = selector; //set end device selection global variable + + fclose(file); //close file + } + else //if file is not found + { + m_pc.printf("ERROR AT CONFIG FILE \r\n"); + } +}