Hasković Nedžad Džafić Faris

Dependencies:   mbed nRF24L01P

Files at this revision

API Documentation at this revision

Comitter:
tim003
Date:
Thu Jun 05 16:04:37 2014 +0000
Commit message:
G6-tim003-chat;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF24L01P.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b285e41a1176 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 05 16:04:37 2014 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "nRF24L01P.h"
+#include <string>
+#define TRANSFER_SIZE 4
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTA13);    // mosi, miso, sck, csn, ce, irq
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+
+char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
+int txDataCnt = 0;
+int rxDataCnt = 0;
+
+string zaPoslat;
+int brZaPoslat(0);
+
+void primiPoruku() {
+    
+}
+
+
+void saljiPoruku() {
+    for(int i = 0; i<zaPoslat.size(); i+=4) if(i<zaPoslat.size()-4)
+    my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*)zaPoslat.substr(i,4).c_str(),  zaPoslat.substr(i,4).size());
+    zaPoslat.clear();
+}
+
+int main() {
+    my_nrf24l01p.powerUp();
+    my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
+    my_nrf24l01p.setReceiveMode();
+    my_nrf24l01p.enable(); 
+    while (1) {
+        if ( pc.readable() ) {
+ 
+            char znak = pc.getc();
+            if(znak == 'x') saljiPoruku();
+            else zaPoslat += znak;        
+            myled1 = !myled1;
+        }
+ 
+        // If we've received anything in the nRF24L01+...
+        if ( my_nrf24l01p.readable() ) {
+ 
+            // ...read the data into the receive buffer
+            rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
+ 
+            // Display the receive buffer contents via the host serial link
+            for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
+ 
+                pc.putc( rxData[i] );
+            }
+ 
+            // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
+            myled2 = !myled2;
+        }
+    }
+      
+}
diff -r 000000000000 -r b285e41a1176 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 05 16:04:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file
diff -r 000000000000 -r b285e41a1176 nRF24L01P.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24L01P.lib	Thu Jun 05 16:04:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/pabloamr/code/nRF24L01P/#8d55f1f49a33