Announcement

Collapse
No announcement yet.

Generating touch events

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

  • Generating touch events

    I was wondering if it is possible to generate a virtual touch event from 4dgl code. This would probably require an additional PmmC function which would set the internal touch variables in the same way as does the actual touch on the display.

    I would found this option very useful, because I am trying to make a remote panel over the serial connection, so if the display is connected to the computer, I can manipulate the display from the computer, just as if I was present by the device. I was able to get the display image on the computer screen (for the moment it is a bit slow ~ 10 seconds), but I can't get the operator manipulation back to the display. I could write a dedicated function for each button and trigger it from the serial, but this is rather hopeless...

    Regards,
    Valentin

  • #2


    There is no scope to add extra functions to the PmmC.

    You need to write it in 4DGL code.

    It should be that hard to do, you just need to think it through fairly thoroughly, something like a serial set of touch state and imagetouched (rather than x and y) and a simple flag to use those values rather than the real values
    Mark

    Comment


    • #3


      I agree, it is possible to do it that way. It was just an idea which would add some interesting new possibilities.

      Regards,
      Valentin

      Comment


      • #4


        Another question, I am using the gfx_GetPixel to copy the screen to computer. In the manual, the function description states that the returned colour can be either 8 or 16 bit. If this is applicable to uLCD32PT, how do I switch it to 8 bit mode?
        I can do the 565 to 332 transformation manually, but it is a bit slow...

        Regards,
        Valentin

        Comment


        • #5


          There really is no 8 bit mode, it would only be 8 bits if the display were 8 bits.

          I would have thought 565 to 332 would be quick enough.

          The getpixel is probably the 'slowest', you might like to try

          disp_setGRAM(x1, y1, x2, y2)
          and then a series of disp_ReadWord()

          to read the display.

          I haven't tried it and it might not work as expected as it depends on the nature of the display driver itself, but it's worth a try, as, if it works, it should be quite a bit faster than reading each pixel individually.
          Mark

          Comment


          • #6


            I have tested the suggested disp_ReadWord() command and I have some problems. I am able to set the area of interest with the disp_setGRAM(x1, y1, x2, y2) and write points, but I am not able to read the value of points (the return value is always zero). As far as I could see, this approach is really considerably faster than using GetPixel and SetPixel, so I am very interested to see this working. I assume that I should do some additional initialization using the disp_WriteControl, but I can't find any instructions on how the display control registers work. I am using the uLCD32PT (and migrating to uLCD32PTU).

            Regards,
            Valentin

            Comment


            • #7


              Here is a basic template for a virtual touch event,
              code is adapted from http://www.4dsystems.com.au/code/index.php?node=75&id=98
              // It uses 4DGL uVGA Link (on the Tools menu in the workshop) as a quick way of demonstrating.
              // Open 4DGL uVGA Link
              , you can now draw on the LCD just as if you were touching it.....

              [quote]


              var touchState; // touchscreen status
              var touchX; // touch X pos
              var touchY; // touch Y pos

              var combuf[100]; // mouse events serial buffer

              var B1State:=UP;

              // initialize comms buffer for mouse
              func mouseInit()
              com_Init(combuf,200,0); // must use buffered comms
              setbaud(BAUD_19200);
              endfunc


              func main()

              mouseInit(); // initialize 'mouse'
              touch_Set(TOUCH_ENABLE); // and touch
              while(1)
              touchState := touch_Get(TOUCH_STATUS); // test touchscreen status

              if (touchState == NOTOUCH) // if no touch event occurred
              pollMouse(); // check for over-riding control
              else
              touchX := touch_Get(TOUCH_GETX); // and current position
              touchY := touch_Get(TOUCH_GETY);
              endif

              if(touchState == TOUCH_MOVING)
              // handle touch moving
              gfx_PutPixel(touchX, touchY, 0xFFFF);
              endif

              if(touchState == TOUCH_PRESSED)
              // handle touch pressed
              gfx_CircleFilled(touchX, touchY, 4, 0xF800);
              endif

              if(touchState == TOUCH_RELEASED) // if touch released
              // handle touch release
              endif
              wend

              endfunc


              // wait for mouse/kbd byte
              func mget()
              var c;
              while((c:=serin()) < 0);
              return c;
              endfunc

              func pollMouse()
              var c;
              if((c:=serin()) >= 0)
              // put any text in text window
              if(c0x82)
              // not used here, capture text or proposed new driver commands
              else
              if (c==0x80) // pressed
              touchState := TOUCH_PRESSED;
              B1State := DOWN;
              else if (c==0x81) // released
              touchState := TOUCH_RELEASED;
              B1State := UP;
              else // moved
              touchState := TOUCH_MOVING;
              endif
              touchX := (mget() + mget()
              Regards,
              Dave

              Comment


              • #8


                I have tested the suggested disp_ReadWord() command and I have some problems. I am able to set the area of interest with the disp_setGRAM(x1, y1, x2, y2) and write points, but I am not able to read the value of points (the return value is always zero).
                Once you have set the GRAM area, the internal hardwar pointer is set to read automatically
                from the top left corner, and scan lef to right for each line within the GRAM area.
                During this process of reading, you cannot do anything else that would affect the current GRAM area
                (eg cant print / draw / putpixel etc)

                The operation must be done untill the entire area is read.
                Regards,
                Dave

                Comment


                • #9


                  Oh dear, I have misled you there.

                  Each display has different 'quirks' when it comes to reading the GRAM.
                  Some displays are simple and return the colour value nicely.
                  Unfortunately for the uLCD32 its a bit involved.

                  Here is some demo code...

                  func main()
                  var r,g,b,c1,c2,c3;
                  gfx_MoveTo(10,10);
                  gfx_PutPixel(10,10,RED);
                  gfx_PutPixel(11,10,LIME);
                  gfx_PutPixel(12,10,BLUE);

                  disp_setGRAM(10, 10, 20, 20);

                  disp_ReadWord(); // dummy read to start

                  r := disp_ReadWord();
                  g := disp_ReadWord();
                  b := disp_ReadWord();
                  c1 := gfx_RGBto565(r, g, b);

                  r := disp_ReadWord();
                  g := disp_ReadWord();
                  b := disp_ReadWord();
                  c2 := gfx_RGBto565(r, g, b);

                  r := disp_ReadWord();
                  g := disp_ReadWord();
                  b := disp_ReadWord();
                  c3 := gfx_RGBto565(r, g, b);

                  print([HEX] c1," ",[HEX] c2," ", [HEX] c3); // prints 0x1F00 0x07E0 0x001F

                  repeat forever


                  endfunc

                  Might be faster than gfx_GetPixel but still rather annoying.
                  Regards,
                  Dave

                  Comment


                  • #10


                    Thanks Dave,

                    Unfortunately, if RGB components are read separately, this is much slower than gfx_GetPixel, not to mention that it is a bit cumbersome...

                    As regarding the virtual touch event, I think your solution may work. It is not really crucial for my project, but I hope I will still found the time to implement it..

                    Regards,
                    Valentin

                    Comment

                    Working...
                    X