bosko lekovic
/
MiWi_spi
prva verzija, poslednji bajt je sporan
Diff: main.cpp
- Revision:
- 1:dd44d6b64300
- Parent:
- 0:c06c791ca345
- Child:
- 2:190bae43eca9
diff -r c06c791ca345 -r dd44d6b64300 main.cpp --- a/main.cpp Fri Jul 10 09:28:30 2020 +0000 +++ b/main.cpp Sun Jul 12 10:23:39 2020 +0200 @@ -7,11 +7,11 @@ #include "platform/mbed_thread.h" #include "MiWiApp.h" - +#include "SerialCom.h" // Blinking rate in milliseconds #define BLINKING_RATE_MS 200 - +#define MINIMUM( A, B) A<B ? A:B DigitalIn b2(SW2); @@ -19,10 +19,15 @@ char tx_niz[] = { 7,0,1,2,3, 4, 5 , 6, 7, 8}; +char rx_niz[100]; +int rx_br; void consolafun( void ); Thread th_consola( consolafun ); +void refreshMiWifun( void ); +Thread th_refreshMiWi( refreshMiWifun ); + int main() { // Initialise the digital pin LED1 as an output @@ -32,6 +37,7 @@ DigitalOut led(LED1,1); DigitalOut ledB(LED3,1); +DigitalOut ledG(LED2,1); @@ -42,11 +48,13 @@ { char r = readMiWiReg( 0x14 ); // read GCONFIG printf("rssi = %d\n\r", r ); - print_regs(); +// print_regs(); } int b = b2; + wait(0.5); + start_SerialCom( ); while (true) { @@ -63,16 +71,21 @@ { if( pin_irq0.read() ) { - led = 0; - print_regs(); + + rx_br = 0; + // print_regs(); while( pin_irq0.read() ) { - printf(" %x ", readMiWiData( )); - // printf("\n\r irq0=%d irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); + rx_niz[rx_br++]= readMiWiData(); + + } - printf("\n\r"); - print_regs(); - } + 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 @@ -93,7 +106,15 @@ } } - +char refrtx[10]={3,1,2, 3}; +void refreshMiWifun( void ) +{ + while(true) + { + wait(10); + txMiWi(refrtx); + } +} void consolafun( void ) @@ -125,6 +146,10 @@ printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); } break; + case 's': case 'S': + printf("aktivacija serijala\n\r"); + start_SerialCom( ); + break; } }