Projet S5 info - Advanced version
Dependencies: XBeeLib mbed-rtos mbed
Fork of Capteurs-Beginner by
Diff: main.cpp
- Revision:
- 5:9505aed3788c
- Parent:
- 4:69f8aea1eaf2
- Child:
- 6:19b89212e67f
--- a/main.cpp Thu Feb 25 19:51:31 2016 +0000 +++ b/main.cpp Thu Mar 31 14:08:37 2016 +0000 @@ -1,13 +1,65 @@ #include "mbed.h" +#include "rtos.h" +#include "XBeeLib.h" + +using namespace XBeeLib; Serial pc(USBTX, USBRX); -DigitalIn sensor(p30); + +XBeeZB* xbee; + +DigitalIn capteur_1(p15); +DigitalIn capteur_2(p16); +DigitalIn capteur_3(p17); +DigitalIn capteur_4(p19); +DigitalIn capteur_5(p20); +DigitalIn capteur_6(p21); + +Mutex capt_lock; + +bool capt_1; +bool capt_2; +bool capt_3; +bool capt_4; +bool capt_5; +bool capt_6; + +/* lecture des capteurs à partir des broches du mbed : p15, p16, p17, 19, 20 21*/ -int main() -{ - while (true) - { - pc.printf("%i ", sensor.read()); - wait(.25); - } +void lecture_capteurs (void const *args){ + capt_lock.lock(); + + capt_1=capteur_1.read(); + capt_2=capteur_2.read(); + capt_3=capteur_3.read(); + capt_4=capteur_4.read(); + capt_5=capteur_5.read(); + capt_6=capteur_6.read(); + + capt_lock.unlock(); +} + +void send_data_to_coordinator(const char data) +{ + const TxStatus txStatus = xbee->send_data_to_coordinator((const uint8_t *)data, 1); } + +void envoi_donnees (void const *args) { + capt_lock.lock(); + char data = (capt_1 << 7) | (capt_2 << 6) | (capt_3 << 5) | (capt_4 << 4) | (capt_5 << 3) | (capt_6 << 2); + capt_lock.unlock(); + + send_data_to_coordinator(data); +} + +int main (void) { + xbee = new XBeeZB(p13, p14, NC, NC, NC, 9600); + + RtosTimer readTimer(lecture_capteurs, osTimerPeriodic); + RtosTimer sendTimer(envoi_donnees, osTimerPeriodic); + + readTimer.start(5); + sendTimer.start(5); + + wait(osWaitForever); +} \ No newline at end of file