![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
Diff: main.cpp
- Revision:
- 15:f8aad6d1db68
- Parent:
- 14:3e69c8a9c730
- Child:
- 16:691649d8a3da
--- a/main.cpp Thu Jul 12 08:56:54 2018 +0000 +++ b/main.cpp Fri Jul 13 06:28:33 2018 +0000 @@ -25,10 +25,11 @@ #define PRINT_ENABLE #include "mbed.h" +//#include "rtos.h" #include "Ontvanger.h" Serial pc(USBTX, USBRX); -Ontvanger receive; +Ontvanger receiver; Timer t; DigitalOut myled1(LED1); @@ -36,102 +37,66 @@ DigitalOut myled3(LED3); DigitalOut myled4(LED4); -char c; - State2 current_state = init_state; -void acitvateLed() + +//Thread thread; +//Mutex stdio_mutex; +//Mutex nrf_mutex; + +void receive() { - t.reset(); + while (true) { + pc.printf("");//print niet weg doen, één of andere reden werkt het niet zonder + receiver.update(); + if (receiver.available()) { + payload_t payload; + payload = receiver.read(); + if(!payload.messageAvailable) { + pc.printf("%f\r\n", payload.gram); + } + } + } } -void setCurrentState( State2 setState ) +void send() { - current_state = setState; + //bool ok = receive.write(packet); + bool ok = true; + if (ok) + pc.printf("Vok.\n\r"); + else + pc.printf("Vfailed.\n\r"); } -State2 getCurrentState() +/** +char c = 'a'; +void led2_thread() { - return current_state; -} + while (true) { + stdio_mutex.lock(); + //c = pc.getc(); + pc.printf("Character %c\r\n", c); + stdio_mutex.unlock(); + } +}**/ int main() { - IF_PRINT_ENABLE( pc.printf("\r\nVOntvanger: \r\n"); - pc.printf("Vtesting Radio... %d\r\n", receive.isValid()); - ); - - while(1) { - receive.update(); - switch (current_state) { - case init_state: - IF_PRINT_ENABLE(pc.printf("XInit State\n\r");); - pc.baud(9600); - t.start(); - state_Packet packet; - payload_t payload; - setCurrentState(testConnection_state); - break; - - case testConnection_state: - IF_PRINT_ENABLE(pc.printf("XTesting State\n\r");); - packet.setState = 't'; - - if (receive.write(packet)){ - pc.printf("VConnection test passed.\n\r"); - setCurrentState(receive_state); - } - else - IF_PRINT_ENABLE(pc.printf("VConnection failed, trying again...\n\r");); - - wait_ms(500); - break; - - case send_state: - IF_PRINT_ENABLE(pc.printf("SSend State\n\r");); - if(c == 's') { - IF_PRINT_ENABLE(pc.printf("VSend state: Tare\n\r");); - packet.setState = 's'; - } - if (c == 'c') { - IF_PRINT_ENABLE(pc.printf("VSend state: Calibrate\n\r");); - packet.setState = 'c'; - } - bool ok = receive.write(packet); - if (ok) - IF_PRINT_ENABLE(pc.printf("Vok.\n\r");); - else - IF_PRINT_ENABLE(pc.printf("Vfailed.\n\r");); - wait(0.1); - setCurrentState(receive_state); - break; - - case receive_state: - pc.printf("");//print niet weg doen, één of andere reden werkt het niet zonder - if (receive.available()) { - payload_t payload; - payload = receive.read(); - if(!payload.messageAvailable) { - pc.printf("%f\r\n", payload.gram); - if (payload.reedsensor) { - acitvateLed(); - } - } - } - - if (t.read() <= 1) { - myled1 = myled2 = myled3 = myled4 = 1; - } else - myled1 = myled2 = myled3 = myled4 = 0; - - if(pc.readable()) { - c = pc.getc(); - if(c == 's' or c == 'c') - setCurrentState(send_state); - wait(0.5); - } - break; - } + float massa = 69; + //thread.start(receive); + while (true) { + pc.printf(""); + wait_ms(100); + receiver.update(); + payload_t payload; + massa++; + payload.gram = massa; + bool ok = receiver.write(payload); + if (ok) + pc.printf("ok.\r\n"); + else + pc.printf("failed.\r\n"); } -} \ No newline at end of file +}