proculus_display_pulga

Files at this revision

API Documentation at this revision

Comitter:
ruschigo
Date:
Mon Apr 27 18:30:55 2020 +0000
Parent:
1:2e4f9cb1c3e9
Commit message:
the change screen behaviour is pretty well

Changed in this revision

Source/main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2e4f9cb1c3e9 -r afae00ebf9ba Source/main.cpp
--- a/Source/main.cpp	Mon Apr 27 17:40:57 2020 +0000
+++ b/Source/main.cpp	Mon Apr 27 18:30:55 2020 +0000
@@ -16,31 +16,14 @@
     struct proculus_pkt pkt;
     uint16_t data[255];
     char msg[100];
-    //char rx_buffer[100];
     pkt.buffer = data;
     int unknow = 0;
-    //wait(SERIAL_DELAY/1000);
-    sprintf(msg, "rx_to_rcv=%d",rx_to_rcv);
-    debug_serial->puts("_|_");
-    debug_serial->puts(msg);
+    //sprintf(msg, "rx_to_rcv=%d",rx_to_rcv);
+    //debug_serial->puts("_|_");
+    //debug_serial->puts(msg);
     while(serial1.readable() || rx_to_rcv >0){
-        //while(!serial1.readable()); 
         serial_rx_buffer[i] = serial1.getc();
-        /*if(i == 0 && serial_rx_buffer[0] == 0x5a){//header packet start
-            i++;
-            rx_to_rcv--;
-            while(serial_rx_buffer[i] != 0xa5){
-                if(serial1.readable())
-                    serial_rx_buffer[i] = serial1.getc();
-            }
-        }*/
         i++;
-        /*THIS IS ALTERNATIVE TO SOLVE A BUG, BUT NOT FIX THE BUG
-        BUG: Uart interrupt is activates twice, then it read the header_h (5a)
-        close the interruption, open a new one starting from header_l (5a)
-        then nothing will work fine at all, creating the rx_to_rcv, i know how
-        many bytes should be read, then just stay here until it complete the
-        full packet*/
         rx_to_rcv --;
         if(rx_to_rcv <= 0)
             break;
@@ -52,7 +35,7 @@
         raw_to_string(serial_rx_buffer, msg, i);
         debug_serial->puts(msg);
         debug_serial->puts("_|_");
-        sprintf(msg, "i=%d",i);
+        sprintf(msg, "rcvsize=%d",i);
         debug_serial->puts(msg);
         debug_serial->puts("_|_");
     }
@@ -72,7 +55,7 @@
                 pkt.address = serial_rx_buffer[4];
                 pkt.lenght = serial_rx_buffer[5];
                 while(j < pkt.lenght){
-                    pkt.buffer[i] = serial_rx_buffer[6 + j];
+                    pkt.buffer[j] = serial_rx_buffer[6 + j];
                     j++;
                 }
             }
@@ -93,31 +76,17 @@
             unknow = 1;//received something unknow
     }
     
-    if(unknow ==0){
-        //sprintf(msg, "rx_buffer[0]=%x|i=%d", rx_buffer[0],i);
-        //debug_serial->puts(msg);
-    
-        if(serial_rx_buffer[3] == R_VP){
+    if(unknow ==0){    
+        if(pkt.cmd == R_VP){
         //if(pkt.address == 0x32){
             //data[0] = data[0] + 1;
             //proculus_set_vp(0x5, 10, pkt.buffer);
         //}
         }
-        if(pkt.cmd == R_CTRL_REG){//
-        //if(serial_rx_buffer[3] == R_CTRL_REG){//from a read control register comand
-            //sprintf(msg, "pkt.address=%x",pkt.address );
-            //sprintf(msg, "serial_rx_buffer[4]=%x",serial_rx_buffer[4]);
-            //debug_serial->puts(msg);
-            //debug_serial->puts("_|_");
-            if(pkt.address == PIC_ID_H){//
-            //if(serial_rx_buffer[4] == PIC_ID_H){//read screen cmd
-                //screen_id = (serial_rx_buffer[6] << 8 );
-                //screen_id |= serial_rx_buffer[7];
+        if(pkt.cmd == R_CTRL_REG){//from a read control register comand
+            if(pkt.address == PIC_ID_H){//read screen cmd
                 screen_id = (pkt.buffer[0] << 8 );
                 screen_id |= pkt.buffer[1];
-                sprintf(msg, "screen_id=%x",screen_id);
-                debug_serial->puts(msg);
-                debug_serial->puts("_|_");
                 if(screen_id == SCREEN_CALIBRATING)
                     jump_to_screen(0x46);
                 else
@@ -130,9 +99,6 @@
         debug_serial->puts("unknowPKT");
         debug_serial->puts("_|_");
     }
-     //sprintf(msg, "pkt.address=%x", serial_rx_buffer[1]);
-    //strcpy(serial_rx_buffer, "init");
-    //debug_serial->puts(msg);
         
 }
 
@@ -167,8 +133,6 @@
     struct proculus_pkt pkt;
     //setup the device rx irq handler
     serial1.attach(&serial_rx_irq, RawSerial::RxIrq);
-    //serial1->attach(&serial_tx_irq, RawSerial::TxIrq);
-    //serial1->attach(&serial_rx_irq);
     //setup the baud rate to match with display
     serial1.baud(115200);
 #ifdef DEBUG_SERIAL
@@ -180,6 +144,7 @@
     while(1) {
         
         if(!sensor_open){//are the device secure to operate?
+            
             get_screen_at_irq();
             wait(3);
         }else{