Announcement

Collapse
No announcement yet.

strange touch behaviour

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • strange touch behaviour


    I made a program that gets every second a serial command and updates an image every second on the screen.

    Problem is that it looks like the touch is not detected during the drawing of the screen.

    If I leave my finger for 2 seconds on the screen it works, but just touching it does not work.

    Here most important part of my code:
    It's not the full code(total code is already 14k), It's just to indicate that I want to have touch while the image is changing from data received via Serial.

    Code:
    #platform "uLCD-43PT" #inherit "4DGL_16bitColours.fnc"#MODE RUNFLASH              // execute the app as top level prog, leaving memory available for overlays etc #inherit "Protocol.fnc" #CONST    DEBUG           1       // set 1 true, 0 false    COMPORT         0       // specify which comport  1 = LPC   /   0 = C##END // variables// variablesvar serialData[PROTOLCOL_MESSAGE_DATAFIELD_LENGTH_MAX/2];  // serial data buffervar serDataPtr;var serData[200];                    // Array for serial DATALENGTHvar serialReceived := 0;             // used to see if data is received and screen should be rebuildvar serialAcknowledged := 0;         // used to see if acknowledgement was receivedvar serDataLength;func main()     // Set screen mode    gfx_ScreenMode(PORTRAIT);    // Default white background and clear screen to remove remainders    gfx_BGcolour(GRAY);    // Clear screen    gfx_Cls();    // mount sdcard    mountSd();    // enable touch screen    touch_Set(TOUCH_ENABLE);       var aSettings[17];                                                    // Array for storing between functions      aSettings[0] := 0;                                               // controller (first controller)      aSettings[1] := 0;                                                    // counter for show view only ones(no refresh 1)      aSettings[2] := 0;                                                    // active button for the view, to change background color of button      aSettings[3] := 0;                                                    // OPCODE      aSettings[4] := 0;                                                    // Battery status 0 is nothing, value: 1-100      aSettings[5] := 0;                                                    // SDCard false or true      aSettings[6] := 0;                                                    // BUTTON1 SELECTED option 0 false, 1 true      aSettings[7] := 0;                                                    // Temperature      aSettings[8] := 0;                                                    // Elec      aSettings[9] := 0;                                                    // Elec2      aSettings[10] := 0;                                                   // RESUME last session Yes or NO        aSettings[11] := 0;                                                   // mA  -- StimulationSettings      aSettings[12] := 0;                                                   // Stim  -- StimulationSettings      aSettings[13] := 0;                                                   // Interval1  -- StimulationSettings      aSettings[14] := 0;                                                   // Interval2  -- StimulationSettings      aSettings[15] := 0;                                                   // pulsewidt  -- StimulationSettings       aSettings[16] := 0;                                                   // timingstatus       aSettings[17] := 0;                                                   // System ok?       ProtocolCreate(SenderReceivedAckowledge, ReceiverReceivedCommand);    // NEW serial protocol   while(1)   ProtocolMain();                                                     // protocol.fnc  -- use serial protocol   serDataPtr := str_Ptr(serData);   aSettings[3] := str_GetByte(serDataPtr++);                          // Set opcode from protocol pointer   var state, x, y; var generalImages;                  // general Images var ptcImage;                       // PTC images var changesettingsImages;           // change settings images      changesettingsImages := file_LoadImageControl("settings.Dat","settings.Gci",1); generalImages := file_LoadImageControl("general.Dat", "general.Gci",1); ptcImage := file_LoadImageControl("ptc2.Dat", "ptc2.Gci",1);              // PTC images  if(aSettings[3] == 0x11)         img_Show(generalImages,6);                                 // clear background         gfx_TransparentColour(YELLOW);         gfx_Transparency(ON);         img_Show(ptcImage, (aSettings[16]+0));         gfx_Transparency(OFF); endif   img_Show( changesettingsImages, 31); // middle bottom menu   if(state == TOUCH_PRESSED)          x := touch_Get(TOUCH_GETX);          y := touch_Get(TOUCH_GETY);    if( (y < 435 &amp;&amp; y > 340 &amp;&amp; x > 10 &amp;&amp; x < 70) )            aSettings[0] := 9;  // Set controller to turnoff            aSettings[1] := 0;  // Reset view            //SETTINGSMENU := 0;        endif endif    mem_Free( changesettingsImages);    mem_Free( generalImages);    mem_Free( ptcImage);wend  endfunc  /** * Function Mount sdcard */func mountSd()var D;                           // disk // mount flash sdcard  //  putstr("Mounting...\n");    if (!(D:=file_Mount()))        while(!(D:=file_Mount()))            putstr("ERROR 1: Drive not mounted...");            pause(200);            gfx_Cls();            pause(200);        wend    endif   // print("Drive mounted.\n");   // pause(1000);   // gfx_Cls();endfunc   func SenderReceivedAckowledge(var *dataPtr, var dataLength)     print("ReceivedAckowledge");     var                 DataFieldPtr;     var                 index := 0;     var                 dataStrPtr;      dataStrPtr := str_Ptr(dataPtr);     //resetFont();     //while(index < dataLength)     //   print(str_GetByte(dataStrPtr + index++));     //wend      //serialAcknowledged := ACKNOWLEDGED;endfunc func ReceiverReceivedCommand(var *dataPtr, var dataLength)     var                 DataFieldPtr;     var                 index := 0;     var                 dataStrPtr;      dataStrPtr := str_Ptr(dataPtr);     serDataLength := dataLength;     serDataPtr := str_Ptr(serData);      //str_CopyN(serDataPtr,dataStrPtr, dataLength*2); // do not use can not handle 0     while(index < dataLength)       // print(str_GetByte(dataStrPtr + index++) , " ");        str_PutByte(serDataPtr++, str_GetByte(dataStrPtr + index++));     wend     // used to see if data is received and screen should be rebuild     serialReceived := 1;     ProtocolReceiverSendAcknowledge(dataPtr, dataLength);endfunc

  • #2


    Your 'main loop' keeps loading and freeing the same image control, you only need to do that once, move that code outside of your main loop.

    It also appears you are redrawing the same image in your main loop, only draw it when it changes.

    On the cutdown code I can't see where touch status is being 'set', nor can I see how you are processing your serial data (you should not be looping waiting for it, only process it when you have everything you need).

    Maybe preemptively do this http://4d.websitetoolbox.com/post?id=6240068

    If you are still having issues put a timer in so that you can see how often you are getting the touch status, if that is happenning infrequently then you still have something NQR in your code.
    Mark

    Comment

    Working...
    X