Projet S5 info - Advanced version
Dependencies: XBeeLib mbed-rtos mbed
Fork of Capteurs-Beginner by
main.cpp@7:e11d6545731a, 2016-04-06 (annotated)
- Committer:
- vinbel93
- Date:
- Wed Apr 06 20:16:07 2016 +0000
- Revision:
- 7:e11d6545731a
- Parent:
- 6:19b89212e67f
- Child:
- 8:096edc8e8679
gp2d12
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vinbel93 | 0:58bb278068d6 | 1 | #include "mbed.h" |
SonSenpai | 5:9505aed3788c | 2 | #include "rtos.h" |
SonSenpai | 5:9505aed3788c | 3 | #include "XBeeLib.h" |
SonSenpai | 5:9505aed3788c | 4 | |
SonSenpai | 5:9505aed3788c | 5 | using namespace XBeeLib; |
vinbel93 | 0:58bb278068d6 | 6 | |
vinbel93 | 4:69f8aea1eaf2 | 7 | Serial pc(USBTX, USBRX); |
SonSenpai | 5:9505aed3788c | 8 | |
SonSenpai | 5:9505aed3788c | 9 | XBeeZB* xbee; |
SonSenpai | 5:9505aed3788c | 10 | |
vinbel93 | 7:e11d6545731a | 11 | AnalogIn GP2D12(p15); |
vinbel93 | 7:e11d6545731a | 12 | DigitalIn capteur_1(p16); |
vinbel93 | 7:e11d6545731a | 13 | DigitalIn capteur_2(p17); |
vinbel93 | 7:e11d6545731a | 14 | DigitalIn capteur_3(p18); |
SonSenpai | 5:9505aed3788c | 15 | DigitalIn capteur_4(p19); |
SonSenpai | 5:9505aed3788c | 16 | DigitalIn capteur_5(p20); |
SonSenpai | 5:9505aed3788c | 17 | DigitalIn capteur_6(p21); |
SonSenpai | 5:9505aed3788c | 18 | |
SonSenpai | 5:9505aed3788c | 19 | Mutex capt_lock; |
SonSenpai | 5:9505aed3788c | 20 | |
SonSenpai | 5:9505aed3788c | 21 | bool capt_1; |
SonSenpai | 5:9505aed3788c | 22 | bool capt_2; |
SonSenpai | 5:9505aed3788c | 23 | bool capt_3; |
SonSenpai | 5:9505aed3788c | 24 | bool capt_4; |
SonSenpai | 5:9505aed3788c | 25 | bool capt_5; |
SonSenpai | 5:9505aed3788c | 26 | bool capt_6; |
vinbel93 | 7:e11d6545731a | 27 | |
vinbel93 | 7:e11d6545731a | 28 | uint16_t GP2D12_value; |
SonSenpai | 5:9505aed3788c | 29 | |
SonSenpai | 5:9505aed3788c | 30 | /* lecture des capteurs à partir des broches du mbed : p15, p16, p17, 19, 20 21*/ |
vinbel93 | 4:69f8aea1eaf2 | 31 | |
SonSenpai | 5:9505aed3788c | 32 | void lecture_capteurs (void const *args){ |
SonSenpai | 5:9505aed3788c | 33 | capt_lock.lock(); |
SonSenpai | 5:9505aed3788c | 34 | |
SonSenpai | 5:9505aed3788c | 35 | capt_1=capteur_1.read(); |
SonSenpai | 5:9505aed3788c | 36 | capt_2=capteur_2.read(); |
SonSenpai | 5:9505aed3788c | 37 | capt_3=capteur_3.read(); |
SonSenpai | 5:9505aed3788c | 38 | capt_4=capteur_4.read(); |
SonSenpai | 5:9505aed3788c | 39 | capt_5=capteur_5.read(); |
SonSenpai | 5:9505aed3788c | 40 | capt_6=capteur_6.read(); |
SonSenpai | 5:9505aed3788c | 41 | |
vinbel93 | 7:e11d6545731a | 42 | GP2D12_value = GP2D12.read_u16(); |
vinbel93 | 7:e11d6545731a | 43 | |
vinbel93 | 7:e11d6545731a | 44 | |
SonSenpai | 5:9505aed3788c | 45 | capt_lock.unlock(); |
SonSenpai | 5:9505aed3788c | 46 | } |
SonSenpai | 5:9505aed3788c | 47 | |
vinbel93 | 6:19b89212e67f | 48 | void send_data_to_coordinator(const uint8_t* data) |
SonSenpai | 5:9505aed3788c | 49 | { |
vinbel93 | 7:e11d6545731a | 50 | const TxStatus txStatus = xbee->send_data_to_coordinator(data, 2); |
vinbel93 | 0:58bb278068d6 | 51 | } |
SonSenpai | 5:9505aed3788c | 52 | |
SonSenpai | 5:9505aed3788c | 53 | void envoi_donnees (void const *args) { |
SonSenpai | 5:9505aed3788c | 54 | capt_lock.lock(); |
vinbel93 | 7:e11d6545731a | 55 | uint8_t data[3]; |
vinbel93 | 7:e11d6545731a | 56 | data[0] = (capt_1 << 7) | (capt_2 << 6) | (capt_3 << 5) | (capt_4 << 4) | (capt_5 << 3) | (capt_6 << 2); |
vinbel93 | 7:e11d6545731a | 57 | data[1] = (GP2D12_value & 0xFF00) >> 8; |
vinbel93 | 7:e11d6545731a | 58 | |
vinbel93 | 7:e11d6545731a | 59 | pc.printf("%x \n\r", GP2D12_value); |
vinbel93 | 7:e11d6545731a | 60 | pc.printf("%02x %02x %02x\n\r", data[0], data[1], data[2]); |
SonSenpai | 5:9505aed3788c | 61 | capt_lock.unlock(); |
SonSenpai | 5:9505aed3788c | 62 | |
vinbel93 | 7:e11d6545731a | 63 | send_data_to_coordinator(data); |
SonSenpai | 5:9505aed3788c | 64 | } |
SonSenpai | 5:9505aed3788c | 65 | |
SonSenpai | 5:9505aed3788c | 66 | int main (void) { |
SonSenpai | 5:9505aed3788c | 67 | xbee = new XBeeZB(p13, p14, NC, NC, NC, 9600); |
SonSenpai | 5:9505aed3788c | 68 | |
SonSenpai | 5:9505aed3788c | 69 | RtosTimer readTimer(lecture_capteurs, osTimerPeriodic); |
SonSenpai | 5:9505aed3788c | 70 | RtosTimer sendTimer(envoi_donnees, osTimerPeriodic); |
SonSenpai | 5:9505aed3788c | 71 | |
vinbel93 | 7:e11d6545731a | 72 | readTimer.start(50); |
vinbel93 | 7:e11d6545731a | 73 | sendTimer.start(50); |
SonSenpai | 5:9505aed3788c | 74 | |
SonSenpai | 5:9505aed3788c | 75 | wait(osWaitForever); |
SonSenpai | 5:9505aed3788c | 76 | } |