![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
main.cpp@8:c43411433ce1, 2018-02-22 (annotated)
- Committer:
- pietor
- Date:
- Thu Feb 22 14:08:11 2018 +0000
- Revision:
- 8:c43411433ce1
- Parent:
- 7:8515f205483b
- Child:
- 9:e14f65b8ffc2
Werken 22.02;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pietor | 4:7ebc3b421306 | 1 | /** |
pietor | 4:7ebc3b421306 | 2 | Main.cpp |
pietor | 4:7ebc3b421306 | 3 | Purpose: main class |
pietor | 4:7ebc3b421306 | 4 | |
pietor | 4:7ebc3b421306 | 5 | @author Pieter Berteloot |
pietor | 4:7ebc3b421306 | 6 | */ |
akashvibhute | 0:3982c0e9eda1 | 7 | #include "mbed.h" |
pietor | 4:7ebc3b421306 | 8 | #include "Ontvanger.h" |
pietor | 4:7ebc3b421306 | 9 | |
akashvibhute | 0:3982c0e9eda1 | 10 | Serial pc(USBTX, USBRX); |
pietor | 4:7ebc3b421306 | 11 | Ontvanger receive; |
pietor | 6:6a82110ff393 | 12 | Timer t; |
pietor | 6:6a82110ff393 | 13 | |
pietor | 7:8515f205483b | 14 | |
pietor | 7:8515f205483b | 15 | State2 current_state = init_state; |
pietor | 7:8515f205483b | 16 | |
pietor | 6:6a82110ff393 | 17 | void acitvateLed() |
pietor | 6:6a82110ff393 | 18 | { |
pietor | 6:6a82110ff393 | 19 | t.reset(); |
pietor | 6:6a82110ff393 | 20 | } |
pietor | 6:6a82110ff393 | 21 | |
pietor | 7:8515f205483b | 22 | void setCurrentState( State2 setState ) |
pietor | 7:8515f205483b | 23 | { |
pietor | 7:8515f205483b | 24 | current_state = setState; |
pietor | 7:8515f205483b | 25 | } |
pietor | 7:8515f205483b | 26 | |
pietor | 7:8515f205483b | 27 | |
pietor | 7:8515f205483b | 28 | State2 getCurrentState() |
pietor | 7:8515f205483b | 29 | { |
pietor | 7:8515f205483b | 30 | return current_state; |
pietor | 7:8515f205483b | 31 | } |
pietor | 7:8515f205483b | 32 | |
akashvibhute | 2:608cf8c5c55e | 33 | int main() |
akashvibhute | 0:3982c0e9eda1 | 34 | { |
pietor | 4:7ebc3b421306 | 35 | while(1) { |
pietor | 4:7ebc3b421306 | 36 | receive.update(); |
pietor | 7:8515f205483b | 37 | switch (current_state) { |
pietor | 7:8515f205483b | 38 | case init_state: |
pietor | 7:8515f205483b | 39 | pc.baud(9600); |
pietor | 7:8515f205483b | 40 | pc.printf("Ontvangger: \r\n"); |
pietor | 7:8515f205483b | 41 | t.start(); |
pietor | 7:8515f205483b | 42 | state_Packet packet; |
pietor | 7:8515f205483b | 43 | payload_t payload; |
pietor | 7:8515f205483b | 44 | setCurrentState(receive_state); |
pietor | 7:8515f205483b | 45 | break; |
pietor | 7:8515f205483b | 46 | |
pietor | 7:8515f205483b | 47 | case send_state: |
pietor | 7:8515f205483b | 48 | packet.setState = State_position; |
pietor | 7:8515f205483b | 49 | bool ok = receive.write(packet); |
pietor | 7:8515f205483b | 50 | if (ok) |
pietor | 7:8515f205483b | 51 | pc.printf("ok.\n\r"); |
pietor | 7:8515f205483b | 52 | else |
pietor | 7:8515f205483b | 53 | pc.printf("failed.\n\r"); |
pietor | 7:8515f205483b | 54 | wait(0.1); |
pietor | 7:8515f205483b | 55 | setCurrentState(receive_state); |
pietor | 7:8515f205483b | 56 | break; |
pietor | 7:8515f205483b | 57 | |
pietor | 7:8515f205483b | 58 | case receive_state: |
pietor | 7:8515f205483b | 59 | pc.printf("");//print niet weg doen, één of andere reden werkt het dan wel |
pietor | 7:8515f205483b | 60 | |
pietor | 7:8515f205483b | 61 | if (receive.available()) { |
pietor | 7:8515f205483b | 62 | payload_t payload; |
pietor | 7:8515f205483b | 63 | payload = receive.read(); |
pietor | 8:c43411433ce1 | 64 | pc.printf("%f\r\n", payload.milligram); |
pietor | 7:8515f205483b | 65 | if (payload.reedsensor) { |
pietor | 7:8515f205483b | 66 | acitvateLed(); |
pietor | 7:8515f205483b | 67 | } |
pietor | 7:8515f205483b | 68 | } |
pietor | 7:8515f205483b | 69 | |
pietor | 7:8515f205483b | 70 | if (t.read() <= 1) |
pietor | 7:8515f205483b | 71 | myled1 = myled2 = myled3 = myled4 = 1; |
pietor | 7:8515f205483b | 72 | else |
pietor | 7:8515f205483b | 73 | myled1 = myled2 = myled3 = myled4 = 0; |
pietor | 7:8515f205483b | 74 | |
pietor | 7:8515f205483b | 75 | if(pc.readable()) { |
pietor | 7:8515f205483b | 76 | char c = pc.getc(); |
pietor | 7:8515f205483b | 77 | if(c == 's') |
pietor | 7:8515f205483b | 78 | setCurrentState(send_state); |
pietor | 7:8515f205483b | 79 | wait(0.5); |
pietor | 7:8515f205483b | 80 | } |
pietor | 7:8515f205483b | 81 | break; |
akashvibhute | 0:3982c0e9eda1 | 82 | } |
akashvibhute | 0:3982c0e9eda1 | 83 | } |
akashvibhute | 0:3982c0e9eda1 | 84 | } |