d
Dependencies: xtoff RF24Network mbed
Transmitter.h@0:a1bd5b12a602, 2018-07-12 (annotated)
- Committer:
- gimohd
- Date:
- Thu Jul 12 12:02:35 2018 +0000
- Revision:
- 0:a1bd5b12a602
hoi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gimohd | 0:a1bd5b12a602 | 1 | #ifndef Transmitter_h |
gimohd | 0:a1bd5b12a602 | 2 | #define Transmitter_h |
gimohd | 0:a1bd5b12a602 | 3 | #include "mbed.h" |
gimohd | 0:a1bd5b12a602 | 4 | #include <RF24Network.h> |
gimohd | 0:a1bd5b12a602 | 5 | #include <RF24.h> |
gimohd | 0:a1bd5b12a602 | 6 | |
gimohd | 0:a1bd5b12a602 | 7 | #define nrf_CE D4 |
gimohd | 0:a1bd5b12a602 | 8 | #define nrf_CSN D3 |
gimohd | 0:a1bd5b12a602 | 9 | #define spi_SCK A1 |
gimohd | 0:a1bd5b12a602 | 10 | #define spi_MOSI A6 |
gimohd | 0:a1bd5b12a602 | 11 | #define spi_MISO A5 |
gimohd | 0:a1bd5b12a602 | 12 | |
gimohd | 0:a1bd5b12a602 | 13 | #define INIT '1' |
gimohd | 0:a1bd5b12a602 | 14 | #define TARE '2' |
gimohd | 0:a1bd5b12a602 | 15 | #define TARE_FIRST '3' |
gimohd | 0:a1bd5b12a602 | 16 | #define TARE_COMPLETE '4' |
gimohd | 0:a1bd5b12a602 | 17 | #define TARE_ERROR '5' |
gimohd | 0:a1bd5b12a602 | 18 | #define POSITION '6' |
gimohd | 0:a1bd5b12a602 | 19 | #define POSITION_WAIT '7' |
gimohd | 0:a1bd5b12a602 | 20 | #define POSITION_ERROR '8' |
gimohd | 0:a1bd5b12a602 | 21 | #define READ '9' |
gimohd | 0:a1bd5b12a602 | 22 | #define RECEIVE 'a' |
gimohd | 0:a1bd5b12a602 | 23 | #define STARTUP 'b' |
gimohd | 0:a1bd5b12a602 | 24 | #define STARTUP_SUCCES 'c' |
gimohd | 0:a1bd5b12a602 | 25 | #define BATTERY 'd' |
gimohd | 0:a1bd5b12a602 | 26 | |
gimohd | 0:a1bd5b12a602 | 27 | |
gimohd | 0:a1bd5b12a602 | 28 | #ifdef PRINT_ENABLE |
gimohd | 0:a1bd5b12a602 | 29 | #define IF_PRINT_ENABLE(x) ({x;}) |
gimohd | 0:a1bd5b12a602 | 30 | #else |
gimohd | 0:a1bd5b12a602 | 31 | #define IF_PRINT_ENABLE(x) |
gimohd | 0:a1bd5b12a602 | 32 | #endif |
gimohd | 0:a1bd5b12a602 | 33 | |
gimohd | 0:a1bd5b12a602 | 34 | //Identificatie verzender/ontvanger |
gimohd | 0:a1bd5b12a602 | 35 | const uint16_t this_node = 01; |
gimohd | 0:a1bd5b12a602 | 36 | const uint16_t other_node = 00; |
gimohd | 0:a1bd5b12a602 | 37 | |
gimohd | 0:a1bd5b12a602 | 38 | struct payload_t { |
gimohd | 0:a1bd5b12a602 | 39 | bool reedsensor; |
gimohd | 0:a1bd5b12a602 | 40 | float gram; |
gimohd | 0:a1bd5b12a602 | 41 | bool messageAvailable; |
gimohd | 0:a1bd5b12a602 | 42 | char messageIndex; |
gimohd | 0:a1bd5b12a602 | 43 | }; |
gimohd | 0:a1bd5b12a602 | 44 | |
gimohd | 0:a1bd5b12a602 | 45 | enum State {State_init, |
gimohd | 0:a1bd5b12a602 | 46 | State_tare, |
gimohd | 0:a1bd5b12a602 | 47 | State_position, |
gimohd | 0:a1bd5b12a602 | 48 | State_read, |
gimohd | 0:a1bd5b12a602 | 49 | State_receive, |
gimohd | 0:a1bd5b12a602 | 50 | State_calibrate |
gimohd | 0:a1bd5b12a602 | 51 | }; |
gimohd | 0:a1bd5b12a602 | 52 | |
gimohd | 0:a1bd5b12a602 | 53 | struct state_Packet { |
gimohd | 0:a1bd5b12a602 | 54 | char setstate; |
gimohd | 0:a1bd5b12a602 | 55 | }; |
gimohd | 0:a1bd5b12a602 | 56 | |
gimohd | 0:a1bd5b12a602 | 57 | |
gimohd | 0:a1bd5b12a602 | 58 | class Verzender |
gimohd | 0:a1bd5b12a602 | 59 | { |
gimohd | 0:a1bd5b12a602 | 60 | private: |
gimohd | 0:a1bd5b12a602 | 61 | |
gimohd | 0:a1bd5b12a602 | 62 | |
gimohd | 0:a1bd5b12a602 | 63 | public: |
gimohd | 0:a1bd5b12a602 | 64 | Verzender(); |
gimohd | 0:a1bd5b12a602 | 65 | |
gimohd | 0:a1bd5b12a602 | 66 | /** |
gimohd | 0:a1bd5b12a602 | 67 | Update to receive a message available for this node |
gimohd | 0:a1bd5b12a602 | 68 | */ |
gimohd | 0:a1bd5b12a602 | 69 | void update(); |
gimohd | 0:a1bd5b12a602 | 70 | |
gimohd | 0:a1bd5b12a602 | 71 | |
gimohd | 0:a1bd5b12a602 | 72 | /** |
gimohd | 0:a1bd5b12a602 | 73 | Send a message to the receiver |
gimohd | 0:a1bd5b12a602 | 74 | |
gimohd | 0:a1bd5b12a602 | 75 | @param message of type payload_t |
gimohd | 0:a1bd5b12a602 | 76 | */ |
gimohd | 0:a1bd5b12a602 | 77 | bool write(payload_t message); |
gimohd | 0:a1bd5b12a602 | 78 | |
gimohd | 0:a1bd5b12a602 | 79 | |
gimohd | 0:a1bd5b12a602 | 80 | /** |
gimohd | 0:a1bd5b12a602 | 81 | Test whether there is a message available for this node |
gimohd | 0:a1bd5b12a602 | 82 | */ |
gimohd | 0:a1bd5b12a602 | 83 | bool available(); |
gimohd | 0:a1bd5b12a602 | 84 | |
gimohd | 0:a1bd5b12a602 | 85 | |
gimohd | 0:a1bd5b12a602 | 86 | /** |
gimohd | 0:a1bd5b12a602 | 87 | Read a message to the receiver |
gimohd | 0:a1bd5b12a602 | 88 | |
gimohd | 0:a1bd5b12a602 | 89 | @return message of type state_packet |
gimohd | 0:a1bd5b12a602 | 90 | */ |
gimohd | 0:a1bd5b12a602 | 91 | state_Packet read(); |
gimohd | 0:a1bd5b12a602 | 92 | |
gimohd | 0:a1bd5b12a602 | 93 | |
gimohd | 0:a1bd5b12a602 | 94 | /*messageIndex: |
gimohd | 0:a1bd5b12a602 | 95 | 0: Nothing wrong |
gimohd | 0:a1bd5b12a602 | 96 | 1: Tare first |
gimohd | 0:a1bd5b12a602 | 97 | 2: Error on Position |
gimohd | 0:a1bd5b12a602 | 98 | 3: Bad Tare value (<2.5V) |
gimohd | 0:a1bd5b12a602 | 99 | */ |
gimohd | 0:a1bd5b12a602 | 100 | void sendMessage(char index); |
gimohd | 0:a1bd5b12a602 | 101 | |
gimohd | 0:a1bd5b12a602 | 102 | void Verzender::printDetails(); |
gimohd | 0:a1bd5b12a602 | 103 | }; |
gimohd | 0:a1bd5b12a602 | 104 | |
gimohd | 0:a1bd5b12a602 | 105 | #endif |
gimohd | 0:a1bd5b12a602 | 106 | |
gimohd | 0:a1bd5b12a602 | 107 | |
gimohd | 0:a1bd5b12a602 | 108 | |
gimohd | 0:a1bd5b12a602 | 109 | |
gimohd | 0:a1bd5b12a602 | 110 |