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: mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P
main.cpp@44:a4f81588fcd5, 2018-04-29 (annotated)
- Committer:
- jacksacane
- Date:
- Sun Apr 29 16:32:23 2018 +0000
- Revision:
- 44:a4f81588fcd5
- Parent:
- 41:9ed924a1f2e0
- Child:
- 45:805f92c68d55
Change RF freq instead of pipes/addresses, comment out LCD for now
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
drechtmann3 | 34:d73e95bbdbed | 1 | #include "uLCD_4DGL.h" |
Nurchu | 0:c35b54fb9c3c | 2 | #include "mbed.h" |
Nurchu | 7:0ac1f1ca8aa6 | 3 | #include "rtos.h" |
Nurchu | 20:e068469ffb89 | 4 | |
Nurchu | 2:dc046ff72566 | 5 | #include "Microphone.h" |
Nurchu | 20:e068469ffb89 | 6 | #include "Speaker.h" |
drechtmann3 | 18:e2a8ea6f55d3 | 7 | #include "HUD.h" |
Nurchu | 20:e068469ffb89 | 8 | #include "nRF24L01P.h" |
Nurchu | 20:e068469ffb89 | 9 | |
Nurchu | 20:e068469ffb89 | 10 | #include "CircularBuf.h" |
Nurchu | 20:e068469ffb89 | 11 | #include "CircularBuf.cpp" // Hack to get templates to work |
Nurchu | 20:e068469ffb89 | 12 | |
Nurchu | 27:08d34e60b6d0 | 13 | // How many times larger the buffer should be |
Nurchu | 33:5d86c111d9bc | 14 | #define FIFO_BUFFER_SCALE 250 |
Nurchu | 27:08d34e60b6d0 | 15 | // How maybe bytes to send over RF |
Nurchu | 27:08d34e60b6d0 | 16 | #define DATA_PACKET_SIZE 32 |
Nurchu | 27:08d34e60b6d0 | 17 | // How quickly to sample the mic / play the speaker |
jacksacane | 40:4f7d95c68d29 | 18 | #define SAMPLE_PERIOD 1/8000.0 |
Nurchu | 20:e068469ffb89 | 19 | |
Nurchu | 20:e068469ffb89 | 20 | |
Nurchu | 27:08d34e60b6d0 | 21 | Serial pc(USBTX, USBRX); |
Nurchu | 27:08d34e60b6d0 | 22 | DigitalOut myled1(LED1); // Mic data sent over RF |
Nurchu | 27:08d34e60b6d0 | 23 | DigitalOut myled2(LED2); // Speaker data recieved over RF |
Nurchu | 27:08d34e60b6d0 | 24 | DigitalOut myled3(LED3); // Sampled mic / played the speaker |
Nurchu | 27:08d34e60b6d0 | 25 | DigitalOut myled4(LED4); // Heartbeat |
Nurchu | 20:e068469ffb89 | 26 | |
Nurchu | 20:e068469ffb89 | 27 | Speaker spkr(p18); |
Nurchu | 27:08d34e60b6d0 | 28 | Microphone mic(p16); |
Nurchu | 27:08d34e60b6d0 | 29 | |
drechtmann3 | 34:d73e95bbdbed | 30 | uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin; |
Nurchu | 20:e068469ffb89 | 31 | |
Nurchu | 20:e068469ffb89 | 32 | nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq |
Nurchu | 27:08d34e60b6d0 | 33 | CircularBuf<uint8_t> txbuff( FIFO_BUFFER_SCALE * DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 34 | CircularBuf<uint8_t> rxbuff( FIFO_BUFFER_SCALE * DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 35 | Ticker sampler; //10:41 am 4/20 |
Nurchu | 20:e068469ffb89 | 36 | |
Nurchu | 29:0c6f3c0c992a | 37 | InterruptIn button(p12); //changed DitialIn to InterruptIn at 5:54 4/18/18 |
jacksacane | 41:9ed924a1f2e0 | 38 | BusIn channel(p21, p22, p23, p24, p25); |
Nurchu | 20:e068469ffb89 | 39 | |
jacksacane | 21:95009b231c1f | 40 | int rfFreq; |
jacksacane | 21:95009b231c1f | 41 | int dataRate; |
jacksacane | 21:95009b231c1f | 42 | unsigned long long rxAddr, txAddr; |
jacksacane | 40:4f7d95c68d29 | 43 | int pipe = 0; |
jacksacane | 44:a4f81588fcd5 | 44 | int channelNum = 0; |
jacksacane | 21:95009b231c1f | 45 | |
jacksacane | 21:95009b231c1f | 46 | enum operatingMode { |
jacksacane | 21:95009b231c1f | 47 | RECEIVE = 0, |
jacksacane | 21:95009b231c1f | 48 | TRANSMIT |
jacksacane | 21:95009b231c1f | 49 | }; |
jacksacane | 21:95009b231c1f | 50 | |
jacksacane | 21:95009b231c1f | 51 | operatingMode mode; |
jacksacane | 21:95009b231c1f | 52 | |
Nurchu | 27:08d34e60b6d0 | 53 | // Cheap nonbranching min function |
Nurchu | 27:08d34e60b6d0 | 54 | int min(int a, int b) { |
Nurchu | 27:08d34e60b6d0 | 55 | return a * (int)(a <= b) + b * (int)(b < a); |
Nurchu | 27:08d34e60b6d0 | 56 | } |
drechtmann3 | 1:fc0a2c17e086 | 57 | |
jacksacane | 40:4f7d95c68d29 | 58 | // Sets the channel of the RF device based on which swtiches are flipped |
jacksacane | 40:4f7d95c68d29 | 59 | // by changing RX/TX pipes |
Nurchu | 27:08d34e60b6d0 | 60 | // TODO: Make sure we don't have to restart the device or anything to change this |
jacksacane | 40:4f7d95c68d29 | 61 | void setChannel() { |
jacksacane | 44:a4f81588fcd5 | 62 | int oldChannel = channelNum; |
jacksacane | 44:a4f81588fcd5 | 63 | //int oldPipe = pipe; |
jacksacane | 44:a4f81588fcd5 | 64 | //int width = 5; |
jacksacane | 40:4f7d95c68d29 | 65 | switch (channel) { |
jacksacane | 40:4f7d95c68d29 | 66 | case 0: // Channel 0 |
jacksacane | 44:a4f81588fcd5 | 67 | //rxAddr = txAddr = 0xC2C2C2C2C0; |
jacksacane | 44:a4f81588fcd5 | 68 | //pipe = NRF24L01P_PIPE_P0; |
jacksacane | 44:a4f81588fcd5 | 69 | channelNum = 0; |
jacksacane | 44:a4f81588fcd5 | 70 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 71 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 72 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 73 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 74 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 75 | } |
jacksacane | 40:4f7d95c68d29 | 76 | break; |
jacksacane | 40:4f7d95c68d29 | 77 | case 1: // Channel 1 |
jacksacane | 44:a4f81588fcd5 | 78 | //rxAddr = txAddr = 0xC2C2C2C2C1; |
jacksacane | 44:a4f81588fcd5 | 79 | //pipe = NRF24L01P_PIPE_P1; |
jacksacane | 44:a4f81588fcd5 | 80 | channelNum = 1; |
jacksacane | 44:a4f81588fcd5 | 81 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 82 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 83 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 84 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 85 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 86 | } |
jacksacane | 40:4f7d95c68d29 | 87 | break; |
jacksacane | 40:4f7d95c68d29 | 88 | case 2: // Channel 2 |
jacksacane | 44:a4f81588fcd5 | 89 | //rxAddr = txAddr = 0xC2C2C2C2C2; |
jacksacane | 44:a4f81588fcd5 | 90 | //pipe = NRF24L01P_PIPE_P2; |
jacksacane | 44:a4f81588fcd5 | 91 | channelNum = 2; |
jacksacane | 44:a4f81588fcd5 | 92 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 93 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 94 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 95 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 96 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 97 | } |
jacksacane | 40:4f7d95c68d29 | 98 | break; |
jacksacane | 40:4f7d95c68d29 | 99 | case 4: // Channel 3 |
jacksacane | 44:a4f81588fcd5 | 100 | //rxAddr = txAddr = 0xC2C2C2C2C3; |
jacksacane | 44:a4f81588fcd5 | 101 | //pipe = NRF24L01P_PIPE_P3; |
jacksacane | 44:a4f81588fcd5 | 102 | channelNum = 3; |
jacksacane | 44:a4f81588fcd5 | 103 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 104 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 105 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 106 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 107 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 108 | } |
jacksacane | 40:4f7d95c68d29 | 109 | break; |
jacksacane | 40:4f7d95c68d29 | 110 | case 8: // Channel 4 |
jacksacane | 44:a4f81588fcd5 | 111 | //rxAddr = txAddr = 0xC2C2C2C2C4; |
jacksacane | 44:a4f81588fcd5 | 112 | //pipe = NRF24L01P_PIPE_P4; |
jacksacane | 44:a4f81588fcd5 | 113 | channelNum = 4; |
jacksacane | 44:a4f81588fcd5 | 114 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 115 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 116 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 117 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 118 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 119 | } |
jacksacane | 40:4f7d95c68d29 | 120 | break; |
jacksacane | 40:4f7d95c68d29 | 121 | case 16: // Channel 5 |
jacksacane | 44:a4f81588fcd5 | 122 | //rxAddr = txAddr = 0xC2C2C2C2C5; |
jacksacane | 44:a4f81588fcd5 | 123 | //pipe = NRF24L01P_PIPE_P5; |
jacksacane | 44:a4f81588fcd5 | 124 | channelNum = 5; |
jacksacane | 44:a4f81588fcd5 | 125 | if (channelNum != oldChannel) { |
jacksacane | 44:a4f81588fcd5 | 126 | //my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 44:a4f81588fcd5 | 127 | //my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 44:a4f81588fcd5 | 128 | rfFreq = channelNum + NRF24L01P_MIN_RF_FREQUENCY; |
jacksacane | 44:a4f81588fcd5 | 129 | my_nrf24l01p.setRfFrequency(rfFreq); |
jacksacane | 41:9ed924a1f2e0 | 130 | } |
jacksacane | 40:4f7d95c68d29 | 131 | break; |
jacksacane | 40:4f7d95c68d29 | 132 | default: |
jacksacane | 40:4f7d95c68d29 | 133 | break; |
jacksacane | 40:4f7d95c68d29 | 134 | } |
Nurchu | 27:08d34e60b6d0 | 135 | |
jacksacane | 40:4f7d95c68d29 | 136 | //pc.printf("Pipe = %d\r\n", pipe); |
jacksacane | 40:4f7d95c68d29 | 137 | |
Nurchu | 27:08d34e60b6d0 | 138 | // TODO: Don't force it to the default RF frequency |
jacksacane | 40:4f7d95c68d29 | 139 | //channelNum = 2; |
Nurchu | 27:08d34e60b6d0 | 140 | |
jacksacane | 40:4f7d95c68d29 | 141 | //my_nrf24l01p.setRfFrequency(channelNum + NRF24L01P_MIN_RF_FREQUENCY); |
Nurchu | 27:08d34e60b6d0 | 142 | } |
drechtmann3 | 1:fc0a2c17e086 | 143 | |
Nurchu | 27:08d34e60b6d0 | 144 | // Callback interrupt from the button to shift into transmit mode |
Nurchu | 27:08d34e60b6d0 | 145 | void enterTransmitMode() { |
Nurchu | 27:08d34e60b6d0 | 146 | mode = TRANSMIT; |
Nurchu | 33:5d86c111d9bc | 147 | txbuff.clear(); |
Nurchu | 27:08d34e60b6d0 | 148 | } |
drechtmann3 | 1:fc0a2c17e086 | 149 | |
Nurchu | 27:08d34e60b6d0 | 150 | // Callback interrupt from the button to shift into receive mode |
Nurchu | 27:08d34e60b6d0 | 151 | void enterRecieveMode() { |
Nurchu | 27:08d34e60b6d0 | 152 | mode = RECEIVE; |
drechtmann3 | 34:d73e95bbdbed | 153 | rxbuff.clear(); |
drechtmann3 | 10:a8fcfc869fa5 | 154 | } |
drechtmann3 | 1:fc0a2c17e086 | 155 | |
Nurchu | 27:08d34e60b6d0 | 156 | // Called every SAMPLE_PERIOD ms to sample the mic or output data into the speaker |
Nurchu | 27:08d34e60b6d0 | 157 | void sampleData() |
Nurchu | 12:efcfe4c0d9f2 | 158 | { |
Nurchu | 27:08d34e60b6d0 | 159 | // Depending on the mode, only sample the mic or output data to the speaker |
Nurchu | 27:08d34e60b6d0 | 160 | if (mode == RECEIVE) { |
Nurchu | 27:08d34e60b6d0 | 161 | // Get speaker sample from buffer |
Nurchu | 27:08d34e60b6d0 | 162 | // If there is no data in the buffer, it will just output 0 to the write function |
Nurchu | 27:08d34e60b6d0 | 163 | uint8_t speakerSample = 0; |
Nurchu | 27:08d34e60b6d0 | 164 | rxbuff.pop(&speakerSample, 1); |
Nurchu | 27:08d34e60b6d0 | 165 | |
Nurchu | 27:08d34e60b6d0 | 166 | // Output into the actual speaker |
Nurchu | 27:08d34e60b6d0 | 167 | spkr.write(speakerSample); |
Nurchu | 27:08d34e60b6d0 | 168 | } else { |
Nurchu | 27:08d34e60b6d0 | 169 | // Get mic sample and place into buffer |
Nurchu | 33:5d86c111d9bc | 170 | uint8_t micSample = mic.getData(); |
Nurchu | 27:08d34e60b6d0 | 171 | txbuff.push(&micSample, 1); |
Nurchu | 12:efcfe4c0d9f2 | 172 | |
Nurchu | 27:08d34e60b6d0 | 173 | // Make sure the speaker is actually off |
Nurchu | 27:08d34e60b6d0 | 174 | spkr.turnOff(); |
Nurchu | 27:08d34e60b6d0 | 175 | } |
Nurchu | 27:08d34e60b6d0 | 176 | |
Nurchu | 27:08d34e60b6d0 | 177 | // TODO: This will have to be removed later on once we actually crank up the sample rate |
Nurchu | 27:08d34e60b6d0 | 178 | myled3 = !myled3; |
Nurchu | 27:08d34e60b6d0 | 179 | } |
drechtmann3 | 1:fc0a2c17e086 | 180 | |
Nurchu | 27:08d34e60b6d0 | 181 | // Communicates to the other MBED using RF |
Nurchu | 27:08d34e60b6d0 | 182 | void commThread() |
Nurchu | 27:08d34e60b6d0 | 183 | { |
Nurchu | 27:08d34e60b6d0 | 184 | // We want this in it's own thread so we don't have to worry about the |
Nurchu | 27:08d34e60b6d0 | 185 | // timings screwing anything else up |
Nurchu | 27:08d34e60b6d0 | 186 | // It can't be in an interrupt because of that |
Nurchu | 27:08d34e60b6d0 | 187 | while (true) { |
Nurchu | 27:08d34e60b6d0 | 188 | // Change what we are sending based on what mode we are in |
Nurchu | 27:08d34e60b6d0 | 189 | if (mode == RECEIVE) { |
Nurchu | 27:08d34e60b6d0 | 190 | // Make sure something is there to read |
Nurchu | 27:08d34e60b6d0 | 191 | if (my_nrf24l01p.readable( NRF24L01P_PIPE_P0 )) { |
Nurchu | 27:08d34e60b6d0 | 192 | uint8_t spkrPacket[DATA_PACKET_SIZE]; |
Nurchu | 27:08d34e60b6d0 | 193 | |
Nurchu | 27:08d34e60b6d0 | 194 | // Remove entire packet of data from the bus |
Nurchu | 27:08d34e60b6d0 | 195 | int numReceived = my_nrf24l01p.read( NRF24L01P_PIPE_P0, (char*) spkrPacket, DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 196 | |
Nurchu | 27:08d34e60b6d0 | 197 | // Place into buffer to play speaker in another thread |
Nurchu | 27:08d34e60b6d0 | 198 | // Only place into the buffer the number of bytes received |
Nurchu | 27:08d34e60b6d0 | 199 | rxbuff.push(spkrPacket, min(DATA_PACKET_SIZE, numReceived)); |
Nurchu | 27:08d34e60b6d0 | 200 | |
jacksacane | 40:4f7d95c68d29 | 201 | //pc.printf("Receiviing....\n\r"); |
Nurchu | 27:08d34e60b6d0 | 202 | myled2 = !myled2; |
Nurchu | 27:08d34e60b6d0 | 203 | } |
Nurchu | 27:08d34e60b6d0 | 204 | } else { // mode == TRANSMIT |
Nurchu | 27:08d34e60b6d0 | 205 | if (txbuff.size() >= DATA_PACKET_SIZE) { |
Nurchu | 27:08d34e60b6d0 | 206 | uint8_t micPacket[DATA_PACKET_SIZE]; |
Nurchu | 27:08d34e60b6d0 | 207 | |
Nurchu | 27:08d34e60b6d0 | 208 | // Pull an entire packet of data from the mic sample buffer |
Nurchu | 27:08d34e60b6d0 | 209 | int numPopped = txbuff.pop(micPacket, DATA_PACKET_SIZE); |
drechtmann3 | 34:d73e95bbdbed | 210 | // rxbuff.push(micPacket, DATA_PACKET_SIZE); |
Nurchu | 27:08d34e60b6d0 | 211 | |
Nurchu | 27:08d34e60b6d0 | 212 | // Send the entire buffer to the other device |
Nurchu | 27:08d34e60b6d0 | 213 | // TODO: We just assume that DATA_PACKET_SIZE bytes were popped, this may |
Nurchu | 27:08d34e60b6d0 | 214 | // not be the case |
Nurchu | 27:08d34e60b6d0 | 215 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*) micPacket, DATA_PACKET_SIZE ); |
drechtmann3 | 34:d73e95bbdbed | 216 | |
Nurchu | 27:08d34e60b6d0 | 217 | myled1 = !myled1; |
Nurchu | 27:08d34e60b6d0 | 218 | } |
drechtmann3 | 1:fc0a2c17e086 | 219 | } |
Nurchu | 27:08d34e60b6d0 | 220 | |
Nurchu | 33:5d86c111d9bc | 221 | //pc.printf("TX Size %d RX Size%d Mode %d\n\r", txbuff.size(), rxbuff.size(), mode); |
Nurchu | 27:08d34e60b6d0 | 222 | Thread::yield(); |
Nurchu | 33:5d86c111d9bc | 223 | //Thread::wait(10); |
Nurchu | 12:efcfe4c0d9f2 | 224 | } |
Nurchu | 12:efcfe4c0d9f2 | 225 | } |
drechtmann3 | 1:fc0a2c17e086 | 226 | |
Nurchu | 27:08d34e60b6d0 | 227 | // Displays the current info to the LCD display |
jacksacane | 44:a4f81588fcd5 | 228 | /*void lcdThread() |
jacksacane | 21:95009b231c1f | 229 | { |
jacksacane | 21:95009b231c1f | 230 | while (1) { |
drechtmann3 | 34:d73e95bbdbed | 231 | uLCD.locate(0, 0); |
jacksacane | 41:9ed924a1f2e0 | 232 | uLCD.printf("Freq: %d MHz", rfFreq); |
drechtmann3 | 34:d73e95bbdbed | 233 | uLCD.locate(0, 2); |
jacksacane | 41:9ed924a1f2e0 | 234 | uLCD.printf("Rate: %d kbps", dataRate); |
drechtmann3 | 34:d73e95bbdbed | 235 | uLCD.locate(0, 4); |
jacksacane | 44:a4f81588fcd5 | 236 | uLCD.printf("Addr: 0x%010llX", txAddr); |
drechtmann3 | 34:d73e95bbdbed | 237 | uLCD.locate(0, 6); |
jacksacane | 44:a4f81588fcd5 | 238 | //uLCD.printf("RX: 0x%010llX", rxAddr); |
jacksacane | 44:a4f81588fcd5 | 239 | uLCD.printf("Channel: %d", channelNum); |
jacksacane | 44:a4f81588fcd5 | 240 | uLCD.locate(0, 10); |
Nurchu | 27:08d34e60b6d0 | 241 | |
jacksacane | 21:95009b231c1f | 242 | switch (mode) { |
jacksacane | 21:95009b231c1f | 243 | case RECEIVE: |
jacksacane | 41:9ed924a1f2e0 | 244 | uLCD.printf("Mode: Receiving"); |
jacksacane | 21:95009b231c1f | 245 | break; |
jacksacane | 21:95009b231c1f | 246 | case TRANSMIT: |
jacksacane | 44:a4f81588fcd5 | 247 | uLCD.line(0, 8, 127, 8, BLACK); |
jacksacane | 21:95009b231c1f | 248 | uLCD.printf("Mode: Transmitting"); |
jacksacane | 21:95009b231c1f | 249 | break; |
jacksacane | 21:95009b231c1f | 250 | } |
drechtmann3 | 34:d73e95bbdbed | 251 | |
jacksacane | 21:95009b231c1f | 252 | // Maybe add some graphics too idk |
jacksacane | 44:a4f81588fcd5 | 253 | Thread::wait(1000); |
jacksacane | 21:95009b231c1f | 254 | } |
jacksacane | 44:a4f81588fcd5 | 255 | }*/ |
jacksacane | 21:95009b231c1f | 256 | |
Nurchu | 12:efcfe4c0d9f2 | 257 | int main() |
Nurchu | 12:efcfe4c0d9f2 | 258 | { |
jacksacane | 44:a4f81588fcd5 | 259 | //Thread lcd; |
Nurchu | 27:08d34e60b6d0 | 260 | Thread comm; |
jacksacane | 21:95009b231c1f | 261 | |
Nurchu | 27:08d34e60b6d0 | 262 | // Set up the nrf24l01p |
jacksacane | 41:9ed924a1f2e0 | 263 | my_nrf24l01p.setAirDataRate(2000); // 2Mbs |
jacksacane | 21:95009b231c1f | 264 | rfFreq = my_nrf24l01p.getRfFrequency(); |
jacksacane | 21:95009b231c1f | 265 | dataRate = my_nrf24l01p.getAirDataRate(); |
jacksacane | 21:95009b231c1f | 266 | rxAddr = my_nrf24l01p.getRxAddress(); |
jacksacane | 21:95009b231c1f | 267 | txAddr = my_nrf24l01p.getTxAddress(); |
jacksacane | 21:95009b231c1f | 268 | |
Nurchu | 27:08d34e60b6d0 | 269 | my_nrf24l01p.setTransferSize(DATA_PACKET_SIZE); |
jacksacane | 21:95009b231c1f | 270 | |
jacksacane | 21:95009b231c1f | 271 | my_nrf24l01p.setReceiveMode(); |
jacksacane | 21:95009b231c1f | 272 | my_nrf24l01p.enable(); |
jacksacane | 21:95009b231c1f | 273 | |
jacksacane | 40:4f7d95c68d29 | 274 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", rfFreq ); |
jacksacane | 40:4f7d95c68d29 | 275 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
jacksacane | 40:4f7d95c68d29 | 276 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
jacksacane | 40:4f7d95c68d29 | 277 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", txAddr ); |
jacksacane | 40:4f7d95c68d29 | 278 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", rxAddr ); |
jacksacane | 40:4f7d95c68d29 | 279 | |
Nurchu | 27:08d34e60b6d0 | 280 | pc.printf("Finished starting up....\n\r"); |
Nurchu | 27:08d34e60b6d0 | 281 | |
jacksacane | 22:e835b3490280 | 282 | mode = RECEIVE; |
jacksacane | 22:e835b3490280 | 283 | |
jacksacane | 21:95009b231c1f | 284 | // Initialize the uLCD |
drechtmann3 | 34:d73e95bbdbed | 285 | uLCD.baudrate(3000000); |
drechtmann3 | 34:d73e95bbdbed | 286 | uLCD.background_color(BLACK); |
jacksacane | 21:95009b231c1f | 287 | |
jacksacane | 21:95009b231c1f | 288 | // Spawn threads |
jacksacane | 44:a4f81588fcd5 | 289 | //lcd.start(lcdThread); |
Nurchu | 27:08d34e60b6d0 | 290 | comm.start(commThread); |
jacksacane | 21:95009b231c1f | 291 | |
Nurchu | 27:08d34e60b6d0 | 292 | // Setup the button to enter transmit mode when pushed down |
Nurchu | 27:08d34e60b6d0 | 293 | // and recieve when release |
jacksacane | 28:9413eb50156d | 294 | button.mode(PullUp); |
Nurchu | 31:39d04aedc3e5 | 295 | button.fall(&enterTransmitMode); |
Nurchu | 31:39d04aedc3e5 | 296 | button.rise(&enterRecieveMode); |
Nurchu | 27:08d34e60b6d0 | 297 | |
Nurchu | 27:08d34e60b6d0 | 298 | // Setup sampler to sample at a specific frequency |
Nurchu | 31:39d04aedc3e5 | 299 | sampler.attach(&sampleData, SAMPLE_PERIOD); |
Nurchu | 27:08d34e60b6d0 | 300 | |
Nurchu | 27:08d34e60b6d0 | 301 | // Heartbeat thread |
drechtmann3 | 1:fc0a2c17e086 | 302 | while (1) { |
Nurchu | 27:08d34e60b6d0 | 303 | myled4 = !myled4; |
jacksacane | 40:4f7d95c68d29 | 304 | setChannel(); // Poll the DIP switch and change channels accordingly |
Nurchu | 27:08d34e60b6d0 | 305 | Thread::wait(100); |
Nurchu | 12:efcfe4c0d9f2 | 306 | } |
Nurchu | 12:efcfe4c0d9f2 | 307 | } |