Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: xtoff2 RF24Network mbed
Fork of RF24Network_Receive by
Revision 13:f54dfb74247e, committed 2018-03-21
- Comitter:
- pietor
- Date:
- Wed Mar 21 16:22:28 2018 +0000
- Parent:
- 12:a3dd2ebf8f93
- Child:
- 14:3e69c8a9c730
- Commit message:
- Werkend 21/03: Added Messages
Changed in this revision
--- a/Ontvanger.cpp Mon Mar 12 10:56:50 2018 +0000
+++ b/Ontvanger.cpp Wed Mar 21 16:22:28 2018 +0000
@@ -1,5 +1,6 @@
#include "Ontvanger.h"
+Serial pc2(USBTX, USBRX);
RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
RF24Network network(radio);
@@ -29,6 +30,10 @@
{
payload_t payload_rx;
network.read(header_rx,&payload_rx,sizeof(payload_rx));
+
+ if(payload_rx.messageAvailable == true)
+ printMessage(payload_rx.messageIndex);
+
return payload_rx;
}
@@ -51,4 +56,33 @@
return radio.testRPD();
}
+void Ontvanger::printMessage(char index){
+ switch (index) {
+ case '1':
+ pc2.printf("Message: Initializing...\n\r");
+ break;
+ case '2':
+ pc2.printf("Message: Taring...\n\r");
+ break;
+ case '3':
+ pc2.printf("Message: Error: Tare first\n\r");
+ break;
+ case '4':
+ pc2.printf("Message: Tare completed\n\r");
+ break;
+ case '5':
+ pc2.printf("Message: Error: Tare value to low... Retry\n\r");
+ break;
+ case '6':
+ pc2.printf("Message: Waiting on the right position...\n\r");
+ break;
+ case '7':
+ pc2.printf("Message: Wait 5 Seconds on POSITION...\n\r");
+ break;
+ case '8':
+ pc2.printf("Message: ERROR: Not on position\n\r");
+ break;
+}
+ }
+
--- a/Ontvanger.h Mon Mar 12 10:56:50 2018 +0000
+++ b/Ontvanger.h Wed Mar 21 16:22:28 2018 +0000
@@ -25,7 +25,9 @@
//
struct payload_t {
bool reedsensor;
- float milligram;
+ float gram;
+ bool messageAvailable;
+ char messageIndex;
};
enum State2 {init_state,
@@ -43,7 +45,7 @@
};
struct state_Packet {
- State setState;
+ char setState;
};
@@ -60,6 +62,7 @@
payload_t read();
bool isValid();
bool testRPD();
+ void printMessage(char index);
};
#endif
--- a/main.cpp Mon Mar 12 10:56:50 2018 +0000
+++ b/main.cpp Wed Mar 21 16:22:28 2018 +0000
@@ -22,7 +22,7 @@
---- -----
*/
//uncommend #define PRINT_ENABLE to see informational prints
-#define PRINT_ENABLE
+//#define PRINT_ENABLE
#include "mbed.h"
#include "Ontvanger.h"
@@ -78,10 +78,11 @@
IF_PRINT_ENABLE(pc.printf("Send State\n\r"););
if(c == 's') {
IF_PRINT_ENABLE(pc.printf("Send state: Tare\n\r"););
- packet.setState = State_tare;
- } else if (c == 'c') {
+ packet.setState = 's';
+ }
+ if (c == 'c') {
IF_PRINT_ENABLE(pc.printf("Send state: Calibrate\n\r"););
- packet.setState = State_calibrate;
+ packet.setState = 'c';
}
bool ok = receive.write(packet);
if (ok)
@@ -97,9 +98,11 @@
if (receive.available()) {
payload_t payload;
payload = receive.read();
- pc.printf("%f\r\n", payload.milligram);
- if (payload.reedsensor) {
- acitvateLed();
+ if(!payload.messageAvailable) {
+ pc.printf("%f\r\n", payload.gram);
+ if (payload.reedsensor) {
+ acitvateLed();
+ }
}
}
