This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

draw two point an uniline on lcd of stm32f429

hi all membres i want draw on the lcd of stm32f429Zit two point and after that i want draw a uniline between this two point i try with this code but i got only 1 point can anyone help me ?

void drawtwopoint()
{  TP_STATE* TP_State;

int i=0;
        int xx[2],yy[2] ;
  while (1)
  { TP_State = IOE_TP_GetState();
    if((!TP_State->TouchDetected) && ((TP_State->Y < 245) && (TP_State->Y >= 3)))
    {TP_State = IOE_TP_GetState();
      if((TP_State->X >= 237) || (TP_State->X < 3))
      {}
      else
      {
          while (i!=2)

          {
          xx[i]= TP_State->X;
        yy[i] = TP_State->Y;
        LCD_DrawFullCircle(xx[i] ,yy[i], 6);
                i=i+1;
        }
       LCD_DrawUniLine(xx[0] ,yy[0],xx[1],yy[1]);
         }
          }
    }
}

Parents Reply Children
  • Haven't you spent some time thinking about this before you started to code?

    All you need is to use two different coordinates when you draw.

    So how do you get two different coordinates?

    The simmplest way would be to
    - get one coordinate from IOE_TP_GetState() when you see "TouchDetected".
    - then continue to call IOE_TP_GetState() until you no longer see TouchDetected.

    That's quite similar to tracking a mouse - getting the first coordinate of the mouse when a mouse button is pressed and getting the second coordinate when the mouse button is released.

    You get a line from the point where you started touch to the point where you removed the finger.

    Or if you want to fill lots of lines on your display:
    - get the first coordinate directly you see TouchDetected.
    - then run a loop while you wait for touch no longer detected
    - use the new coordinate as second coordinate and draw

    You create a "star" of multiple lines from the original touch point)

    or
    - get the first coordinate directly you see TouchDetected
    - then run a loop where you get new coordinates as long as TouchDetected.
    - draw from coordinate 1 to coordinate 2
    - copy coordinate 2 to coordinate 1
    - repeat getting new coordinate 2 while touch detected

    You get a long trace of multiple line segments as the drawn line segments "hunts" you finger.

  • ok can u write the code for the second point plz

  • Does it matter if I can write the code, when it's your task? You ask for help with your shoelaces too?

  • i only ask u the code of this two step
    - then run a loop while you wait for touch no longer detected - use the new coordinate as second coordinate and draw

  • Why not buffer each touch as you get it. And then plot a line between the last and current points?

    Please try to use whole words, you're not texting and there's not a per letter charge.

  • "Put your heart, mind, and soul into even your smallest acts. This is the secret of success."

    Swami Sivananda

  • ok i ptut my mind and my eyes and my hair also this code work and i get two different point but i want get the uniline between the two point can u help me only in this step

    int i=0;
    while(i!=2)
     {
            TP_State = IOE_TP_GetState();
       if(TP_State->TouchDetected)
    
      {
           if((TP_State->X >= 237) || (TP_State->X < 3))
    
                 {}
    
             else
         {
              LCD_DrawFullCircle( TP_State->X, TP_State->Y ,6);
             i=i+1;
    
     }
             }
    
    if  (!TP_State->TouchDetected)                continue;
    
    }
    

  • So you still haven't figured out how you can use variables to store a coordinate pair while you wait for a second coordinate pair? So that when you get that second coordinate pair you now have access to two coordinate pairs and then have the ability to draw a line between (x0,y0) and (x1,y1)?

  • it is ok i will share the code to all membres

    int i=0;
      int xx[2],yy[2] ;
      while(i!=2)
      {
    
        TP_State = IOE_TP_GetState();
    
        if(TP_State->TouchDetected)
        {  xx[i]=TP_State->X;
                yy[i]=TP_State->Y;
          if((TP_State->X >= 237) || (TP_State->X < 3))
          {}
          else
          {
    
            LCD_DrawFullCircle( TP_State->X, TP_State->Y ,6);
                             i=i+1;
    
    
             }
             }
                     if  (!TP_State->TouchDetected)
               continue;
    
    
    
      }
       LCD_DrawUniLine( xx[0],yy[0] ,xx[1],yy[1]);
    
    
    

  • int i=0;
    int xx[2],yy[2];
    
    while (i!=2) {
        TP_State = IOE_TP_GetState();
    
        if (TP_State->TouchDetected) {
            xx[i]=TP_State->X;
            yy[i]=TP_State->Y;
            if ((TP_State->X >= 237) || (TP_State->X < 3)) {
            } else {
                LCD_DrawFullCircle(TP_State->X, TP_State->Y ,6);
                i=i+1;
            }
        }
        if (!TP_State->TouchDetected)     <=== what use is this for?
            continue;
    }
    LCD_DrawUniLine(xx[0],yy[0],xx[1],yy[1]);
    

    Notice that the part with the continue doesn't do anything - remove the two lines and the while statement will still repeat.

    And why do you have your "negated" logic where the if statement leads to a dummy empty block with the real code in the else block?
    Why check if x is too close to the border - why not instead if x is not too close to the border? Then the if block will do the job and no else part will be needed.
    If the goal is to test "should I draw", then it's obviously better to test for that, instead of testing for "should I not draw"...