S5Team
/
HelloWorld
none
Fork of HelloWorld by
main.cpp
- Committer:
- JacquesEd
- Date:
- 2015-01-26
- Revision:
- 3:58803195db3f
- Parent:
- 2:8d4c217c39e5
- Child:
- 4:2857c116c1e1
File content as of revision 3:58803195db3f:
#include "mbed.h" //#include "rtos.h" DigitalIn en_1(p15); DigitalIn en_2(p16); AnalogIn ea_1(p19); AnalogIn ea_2(p20); Serial pc (USBTX, USBRX); int test[100] = {1,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,,1,1,0,1,0,0,0,1,1,0,1,0 ,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1 ,01,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,}; int index = 0; //RtosTimer time ; int date = 0; int taille = 100; int compteur = 0; int index = 0; int tableau[100][2]; int flag[2] = {0,1}; void lecture_analog(void const *args) { int sample[6][2]; int i = 0; for (i = 0; i <6; i ++) { //sample[i][0] = args.read_u16(); sample[i][0] = test[indext]; // sample[i][1] = date; } i = 0; while (true) { // synchronisation sur la période d'échantillonnage flag[0] = 1; while (flag[1] == 1) thread.yield(); // lecture de l'étampe temporelle //date = time.read_ms(); // lecture des échantillons analogiques sample[i][0] = args.read_u16(); i++; // calcul de la nouvelle moyenne courante if ((sample[i][0] - sample[(i+5)%6][0]) > 0x9FFF) { tableau[i][0] = 1; // 1 pr analog //tableau[i][1] = date; } // génération éventuelle d'un événement if (i >= 6) i = 0; } flag[0] = 0; } void lecture_num(void const *args) { flag[1] = 1; while (flag[0] == 1) thread.yield(); int value[2][2]; int i = 0; value[i][0] = args.read(); //value[i][1] = date; while (true) { // synchronisation sur la période d'échantillonnage // lecture de l'étampe temporelle //date = time.read_ms(); // lecture des échantillons numériques wait_ms(100); i++; value[i][0] = args.read(); //value[i][1] = date; // prise en charge du phénomène de rebond if (value[0][0] != value[1][0]) { wait_ms(50); int *temp = new int; temp = args.read(); // génération éventuelle d'un événement if (temp == value[i]) { tableau[compteur][0] = 0; //0 pr numérique // tableau[compteur][1] = value[i][1]; compteur++; } wait_ms(50); } if (i >=2) i = 0; } flag[1] = 0; } void collection(void const *args) { int i = 0; while (true) { // attente et lecture d'un événement // écriture de l'événement en sortie (port série) if (tableau[i][0] == 0) pc.printf("event_n at: "); else pc.printf("event_a at: "); pc.printf ("%i", tableau[i][1]); i++; } } int main() { // initialisation du RTC // time.start(); // démarrage des tâches while(1) { // creation des threads Thread event_n1 = new Thread(new lecture_num(en_1)); Thread event_n2 = new Thread(new lecture_num(en_2)); Thread event_a1 = new Thread(new lecture_analog(ea_1)); Thread event_a2 = new Thread(new lecture_analog(ea_2)); event_n1.start(); event_n2.start(); event_a1.start(); event_a2.start(); } // time.stop(); }