prva verzija, poslednji bajt je sporan

Revision:
2:190bae43eca9
Parent:
1:dd44d6b64300
Child:
3:3b0754ed31e9
--- a/main.cpp	Sun Jul 12 10:23:39 2020 +0200
+++ b/main.cpp	Thu Jul 16 22:14:03 2020 +0200
@@ -6,7 +6,7 @@
 #include "mbed.h"
 #include "platform/mbed_thread.h"
 
-#include "MiWiApp.h"
+#include "MiWiDrv.h"
 #include "SerialCom.h"
 // Blinking rate in milliseconds
 #define BLINKING_RATE_MS                                                    200
@@ -25,8 +25,6 @@
 void consolafun( void );
 Thread th_consola( consolafun );
 
-void refreshMiWifun( void );
-Thread th_refreshMiWi( refreshMiWifun );
 
 int main()
 {
@@ -35,61 +33,22 @@
 
     inic_MiWi( );
     
-    DigitalOut led(LED1,1);
+//    DigitalOut led(LED1,1);
     DigitalOut ledB(LED3,1);
-DigitalOut ledG(LED2,1);
+//  DigitalOut ledG(LED2,1);
 
 
 
-   set_mode( 3 );   //prijem
- 
+   setMiWimode( 3 );   //prijem
  
- //for( int i=0; i<10; i++)
- {
-      char r = readMiWiReg( 0x14 );  // read GCONFIG
-  printf("rssi = %d\n\r", r );
-//  print_regs();
-}
  
 int b = b2;
  
- wait(0.5);
    start_SerialCom( );   
+   start_MiWiRx( );
    
     while (true) 
     {
- //       led = !led;
-
-extern DigitalIn pin_irq0, pin_irq1;
-//
-//   unsigned char r = readMiWiReg( 0x14 );  // read GCONFIG
-//  printf("rssi = %d   ", r );
-//  printf(" irq0=%d  irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); fflush(stdout);
-////if( r> 50 )
-
-    if( get_mode( ) == 3 )
-    {
-        if( pin_irq0.read() )
-        {
-              
-             rx_br = 0;   
-            //    print_regs();
-                while( pin_irq0.read() )
-                   {
-                       rx_niz[rx_br++]= readMiWiData();
-                      
-                       
-                    }
-                        for(int i=0; i<rx_br;i++) { printf(" %d ", rx_niz[i]); } 
-                       printf("\n\rrx_br %d\n\r", rx_br);
-                    if( rx_br <= 4) { ledG=0; wait(0.1); ledG=1;}
-                    else if(rx_br>3) {led = 0;sendToScom(rx_niz+2, rx_niz[0]-2/* MINIMUM(rx_br, rx_niz[0]-2)* */ ); }
-                       rx_br = 0;
-       }
-        else        { if(!led )  led = 1; }
-    }
-//    else
-    {
          
         if( b!= b2)
         {
@@ -97,24 +56,11 @@
         if( b ) {/*set_mode( 1 );*/ ledB = 1;}
         else    { ledB = 0; txMiWi( tx_niz ); }
         }
-   
-    }
-
-
-
+ 
         thread_sleep_for(BLINKING_RATE_MS);
     }
 }
 
-char refrtx[10]={3,1,2, 3};
-void refreshMiWifun( void )
-{
-    while(true)
-    {
-        wait(10);
-       txMiWi(refrtx);
-    }
-}
 
 
 void consolafun( void )
@@ -127,29 +73,32 @@
      {
          case 'r': case 'R':  
          
-            printf("\n\rcitanje registra, unesi broj:\n\r");
+            printf("\n\rcitanje registra, unesi broj hex:\n\r");
             int r;
             scanf("%x", &r);
-            printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
+            printf( "\n\rregistar hex %x ima vrednost hex %x\n\r", r, readMiWiReg(r));
         
             break;
          case 'w': case 'W':  
          {
-            printf("\n\rupis registra, unesi broj registra:");
+            printf("\n\rupis registra, unesi broj registra hex:");
             int r;
             scanf("%x", &r);
             printf( " %x", r );
-            printf("\n\runesi vrednost registra:");
+            printf("\n\runesi vrednost registra hex:");
             int v;
             scanf("%x", &v);
             printf( " %x", v );
-            printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
+            printf( "\n\rregistar hex %x ima vrednost hex %x\n\r", r, readMiWiReg(r));
         }
             break;
         case 's': case 'S':
             printf("aktivacija serijala\n\r");
              start_SerialCom( );   
              break;
+        case 'f': case 'F':
+            printMiWiregs( );
+            break;
      }
         
     }