Main Site Documentation

Problems getting Touch on CP7


#1

I’m trying to get responce from the touch panel of the display_CP7 on my Hydra board. Up till now I have succesfully added some glide moke-up to the screen, so I would think basic set-up is fine.

Strange enough I can not get it to work., Interupts are not beiing dispatched to my code. So I added the calibration functionality to my project which I activate by pressing the Joystick. This seems to work fine but then again the calibration routine requests a touch to start… No responce aswell. Please check my code underneath. Any sugestions?


#2

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)

#3

:wink:


#4

Since the CP7 uses a different way to handle touch events, you will need to feed the touch events to Glide. Check this sample out to help get you started: http://www.ghielectronics.com/glide/example/5/

Hope this helps!


#5

Tnx, Steven, On top of the example it says; GHI display e.g. 3.5", 4.3" or 7" then you don’t need to use this example. Since I’m using a GHI CP7?? are there any more 7" panels?

Anyway I’m trying to get this in my code. The touch panel on the CP7 panel seems directly connected to the Hydra board, without any silicon driver IC. In order to initialize the touch panel I would think I need the pins as digital IO? Or am I mistaken? It is a cap. Touch correct? Is there a touch peripheral on board of the uC? or is it in between the driver PCB and the panel? The only chip on top side is a TI TPS65100 Tripple output LCD supply.

I understand now I have to forward the touch events to Glide. But I still have no idear how to read the touch panel and how to get X, Y coordinates. Tnx so much!


#6

We will remove that text.


#7

Tnx Gus! I made a thread for handling the touch panel but still I have no idear what kind of touch panel I’m dealing with. :wink: The Designer Toolbox only presents connector 5 and 6 as a valid options. Since connectors 5 and 6 can be be UART or I2C I guess there I need to open a com port or I2C channel?? then I have no idear what to send for init and how to retrieve X, Y pos.


#8

Since you are using Gadgeteer, you can just use the events that the display module has available to collect the touch positions. The following example will read the touch position and raise the touch down event for Glide.

Note: This example will only track the first finger to touch the screen. Any other position will be ignored.

Place this code inside ProgramStarted() to sign up for the event:

display_CP7.ScreenPressed += new Display_CP7.TouchEventHandler(display_CP7_ScreenPressed);

And the handler for the event:

// These are used for the touch up event
        int lastX = 0;
        int lastY = 0;

        // These store the current X and Y
        int x;
        int y;

        // Keeps track of whether the panel was touched or not
        bool isTouched = false;

        void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            GHIElectronics.NETMF.Glide.Geom.Point touches;

            if (touchStatus.numTouches > 0)
            {
                touches.X = touchStatus.touchPos[0].xPos;
                touches.Y = touchStatus.touchPos[0].yPos;

                x = 0; // Zero should be the read X coordinate
                y = 0; // Zero should be the read Y coordinate

                if (isTouched == false)
                {
                    // Touch down
                    GlideTouch.RaiseTouchDownEvent(null, new TouchEventArgs(touches));

                    lastX = x;
                    lastY = y;
                    isTouched = true;
                }
                else
                {
                    if (lastX != touches.X && lastY != touches.Y)
                        isTouched = false;
                }
            }
            else
            {
                if (isTouched == true)
                {
                    // Touch up
                    touches.X = lastX;
                    touches.Y = lastY;
                    //GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));

                    isTouched = false;
                }
            }
        }

This should get touch working with the CP7 display. Hope this helps.


#9

Ok… I disconnected the flatband cable and underneath there is a FocalTech FT5406. It turns out it supports I2C, UART and SPI :wink:

Are all possibilities laied out to the GHI connector? At least SPI is not supported by connector 5 and 6. Does anyone have experience with setting this up? initilize and pos. read out?


#10

The touch controller uses I2C. If you add the display to the designer, all of the setup and communication is taken care of for you.


#11

Tnx Steven, Touch is working! code underneath.

At the moment I’m trying to get an on screen keyboard if a TextBox is touched. Since the buttons are working great it should not be so hard… Strange enough textBox.TapEvent += new OnTap(textBox_TapEvent); does not encounter whatever touches I make. How do I make a Tap event? is it indeed a double touch? I think I don’t forward the tab touches correctly to Glide. Anyone any idear? Other sugestions?

xml


<Glide Version="1.0.5">
  <Window Name="xmlMainWnd" Width="800" Height="480" BackColor="E08040">
    <TextBox Name="textBox" X="300" Y="100" Width="120" Height="32" Alpha="255" Text="" TextAlign="Left" Font="4" FontColor="000000"/>
    <Button Name="buttonTestOn" X="580" Y="410" Width="80" Height="32" Alpha="255" Text="On" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <Button Name="buttonTestOff" X="680" Y="410" Width="80" Height="32" Alpha="255" Text="Off" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <Button Name="buttonKB" X="480" Y="410" Width="80" Height="32" Alpha="255" Text="Key" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
  </Window>
</Glide> 

program cs


using System;
using System.Collections;
using System.IO;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;

namespace App42
{

    public partial class Program
    {
        static Window stkMainWnd;
        static TextBlock textBlock;
        static int timeCnt = 0;
        static string outStr;
        GT.Timer timer = new GT.Timer(1000);
        static Thread wdThread;


        void ProgramStarted()
        {
            Debug.Print("Program Started");

            //Watchdog.Enable(5000);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();
            wdThread = new Thread(wdThreadFunc);
            wdThread.Start();
            GlideTouch.Initialize();
            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
            joystick.JoystickReleased += new Joystick.JoystickEventHandler(joystick_JoystickReleased);
            display_CP7.ScreenPressed += new Display_CP7.TouchEventHandler(display_CP7_ScreenPressed);



            // Main window layout
            stkMainWnd = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.xmlMainWnd));
            stkMainWnd.BackImage = Resources.GetBitmap(Resources.BitmapResources.resBgImage);

            textBlock = new TextBlock("", 255, 100, 100, 100, 100);
            textBlock.Text = "Starting...";
            textBlock.FontColor = Colors.White;
            stkMainWnd.AddChild(textBlock);

            Button buttonTestOn = (Button)stkMainWnd.GetChildByName("buttonTestOn");
            buttonTestOn.PressEvent += new OnPress(buttonTestOn_PressEvent);
            Button buttonTestOff = (Button)stkMainWnd.GetChildByName("buttonTestOff");
            buttonTestOff.PressEvent += new OnPress(buttonTestOff_PressEvent);
            Button buttonKB = (Button)stkMainWnd.GetChildByName("buttonKB");
            buttonKB.PressEvent += new OnPress(buttonKB_PressEvent);
            TextBox textBox = (TextBox)stkMainWnd.GetChildByName("textBox");
            textBox.TapEvent += new OnTap(textBox_TapEvent);
            // textBox.TapEvent += new OnTap(Glide.OpenKeyboard);
            // textBlockNum.ValueChangedEvent += new OnValueChanged(textBox_ValueChangedEvent);


            // display active window
            Glide.MainWindow = stkMainWnd;
        }


        static void textBox_ValueChangedEvent(object sender)
        {
            TextBox textBox = (TextBox)stkMainWnd.GetChildByName("textBox");
            Debug.Print(textBox.Text);
        }

        void textBox_TapEvent(object sender)
        {
            Debug.Print("textBox_TapEvent!!!!!!!!!");
        }

        void buttonKB_PressEvent(object sender)
        {
            Debug.Print("buttonKB_PressEvent!!!!!!!!!");
        }


        static int lastX = 0;
        static int lastY = 0;
        static int x;
        static int y;
        static bool isTouched = false;
        void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            GHIElectronics.NETMF.Glide.Geom.Point touches;
            if (touchStatus.numTouches > 0)
            {
                touches.X = touchStatus.touchPos[0].xPos;
                touches.Y = touchStatus.touchPos[0].yPos;
                x = 0;
                y = 0;
                if (isTouched == false)
                {
                    GlideTouch.RaiseTouchDownEvent(null, new TouchEventArgs(touches));
                    lastX = x;
                    lastY = y;
                    isTouched = true;
                }
                else
                {
                    if (lastX != touches.X && lastY != touches.Y)
                    {
                        touches.X = lastX;
                        touches.Y = lastY;
                        GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
                        isTouched = false;
                    }
                }
            }
            else
            {
                if (isTouched == true)
                {
                    touches.X = lastX;
                    touches.Y = lastY;
                    GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
                    isTouched = false;
                }
            }
        }

        void wdThreadFunc()
        {
            while (true)
            {
                //Thread.Sleep(3000);
                //Watchdog.ResetCounter();
            }
        }

        void joystick_JoystickReleased(Joystick sender, Joystick.JoystickState state)
        {
            led7r.TurnLightOff(7);
        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            led7r.TurnLightOn(7, false);
        }


        void timer_Tick(GT.Timer timer)
        {
            //PulseDebugLED();
            timeCnt++;
            stkMainWnd.RemoveChild(textBlock);
            outStr = "test " + timeCnt.ToString() + " nr";
            textBlock.Text = outStr;
            stkMainWnd.AddChild(textBlock);
            Glide.MainWindow = stkMainWnd;
        }

        void buttonTestOn_PressEvent(object sender)
        {
            led7r.TurnLightOn(6, false);
        }

        void buttonTestOff_PressEvent(object sender)
        {
            led7r.TurnLightOff(6);
        }

    }
}


#12

Does anyone with CP7 panel succesfully getting tap events from a textbox / checkbox or whatever?


#13

Since touch events need to be forwarded into Glide by calling RaiseTouchDownEvent as responce on a incomming touch event I guess a tap event also needs to be forwarded into Glide.

Since I do not understand the term RaiseTouchGestureEvent… would it be possible that Glide generates tap events based on forwarded guestures? There is no such function as RaiseTapEvent… Does anyone have experience with this?


#14

Is there someone who is willing to dive in this issue? I’m prepared to pay expensis for solving this issue. So succesfully handling a tap event in the application, and opening a keyboard when a tap event is made on a textbox? please let me know to which expensis. tnx so much.

Here you can find the project as-is.

https://dl.dropbox.com/u/31320210/App42_revA3.zip


#15

I’ll be glad to try and take a look, but can’t get to it before mid-next week (9/20). If someone else can get to it beforehand, please jump in!


#16

In your timer handler you are removing target text block from window, changing the text of the text block and then adding the text block back to the window.
You should change the text, repaint the text block area with the background color, and then invalidate the text block.

You are also setting the main window in the timer handler. Not necessary.

Is the display_CP7_ScreenPressed method ever getting called?


#17

Thanks so much stevepresley. mid next week is ok. Please let me know to which expensis. you can email me if you will let me send it in a PM.

Tnx Mike, I tried to removed the whole Timer interupt to see if I maybe forgot to call some base class in order to dispatch the timer interupt further instead blocking it for other threats like the tap event. No differemce…

The display_CP7_ScreenPressed is called succesfully. It turned out I needed this function in order to forward touch events in Glide. This solved the button press event which where never thrown by Glide. So buttons are working now on the touch event. Unfortunatly tap events are still not thrown for example editboxes and checkboxes which have tap events instead of press events.


#18

@ stevepresley, it seems not possible to send a PM on this forum. Please send an email to Chris@ Systek.nl


#19

solved;


        void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            //GHIElectronics.NETMF.Glide.Geom.Point touches;
            Microsoft.SPOT.Touch.TouchInput[] touches = new Microsoft.SPOT.Touch.TouchInput[] { new TouchInput() };
            if (touchStatus.numTouches > 0)
            {
                //touchinput wordt verzonden naar micorsoft.spot
                touches[0].X = touchStatus.touchPos[0].xPos;
                touches[0].Y = touchStatus.touchPos[0].yPos;
                
                //touchinput wordt verzonden naar Glide
                pos_x = touchStatus.touchPos[0].xPos;
                pos_y = touchStatus.touchPos[0].yPos;
                if (isTouched == false)
                {
                    GlideTouch.RaiseTouchDownEvent(sender, new TouchEventArgs(touches));
                    lastX = pos_x;
                    lastY = pos_y;
                    isTouched = true;
                }
                else
                {
                    // Filteren van het ingedrukt houden van een plaats op het beelscherm
                    if (System.Math.Abs(pos_x - lastX) > 2 || System.Math.Abs(pos_y - lastY) > 2)
                    {
                        touches[0].X = pos_x;
                        touches[0].Y = pos_y;
                        GlideTouch.RaiseTouchMoveEvent(null, new TouchEventArgs(touches));

                        lastX = pos_x;
                        lastY = pos_y;
                    }
                }
            }
        }