Fez Raptor Glide touch problems

Recently I have been trying to get a glide touch button example working on my fez raptor and have run into issues.

The first issue was touch events not firing correctly from the display. I was receiving “Failed to perform I2C transaction” message in the console window. Long story short i overcame that issue by downloading the cp7 driver source and modifying ReadRegister with code i found in another thread then recompiling the driver and referencing my modified driver in my example project.

static byte ReadRegister(byte Address)
        {
         int timeout=0x10;
            I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];

            // create write buffer (we need one byte)
            byte[] RegisterAddress = new byte[1] { Address };
            xActions[0] = I2CDevice.CreateWriteTransaction(RegisterAddress);
            // create read buffer to read the register
            byte[] RegisterValue = new byte[1];
            xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
         while(timeout>0)
         {
            if (i2cBus.Execute(xActions, 100) == 0)
            {
               //Debug.Print("Failed to perform I2C transaction");
               Thread.sleep(10);
               timeout--;
            }
            else
            {
               //Debug.Print("Register value: " + RegisterValue[0].ToString());
               timeout = 0;
            }
            
            
         }
            return RegisterValue[0];
        }

This driver fix gets the following code working properly on my cp7

using Microsoft.SPOT;

namespace GadgeteerApp2
{
    public partial class Program
    {
        void ProgramStarted()
        {
            this.display_CP7.ScreenPressed += (a, b) => display_CP7.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Red, (uint)b.touchPos[0].xPos, (uint)b.touchPos[0].yPos, 5, 5);
            this.display_CP7.ScreenReleased += (a) => Debug.Print("R");
            this.display_CP7.MenuPressed += (a) => Debug.Print("M");
            this.display_CP7.HomePressed += (a) => Debug.Print("H");
            this.display_CP7.BackPressed += (a) => Debug.Print("B");
        }
    }
}

So once i got that working i attempted to get the button press example working.


<Glide Version="1.0.7">
  <Window Name="WindowRGB" Width="320" Height="240" BackColor="11AA88">
    <Button Name="buttonRed" X="20" Y="100" Width="80" Height="32" Alpha="255" Text="Red" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <Button Name="buttonGreen" X="120" Y="100" Width="80" Height="32" Alpha="255" Text="Green" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <Button Name="buttonBlue" X="220" Y="100" Width="80" Height="32" Alpha="255" Text="Blue" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
  </Window>
</Glide>

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Glide;
using GHI.Glide.UI;

namespace GlideButtonDemo
{
    public partial class Program
    {
        static GHI.Glide.Display.Window window;

        void ProgramStarted()
        {
            // Do one-time tasks here
            Debug.Print("Program Started");

            GlideTouch.Initialize();

            // Load the Window XML string.
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Window1));

            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Assign the Window to MainWindow; rendering it to the LCD.
            Glide.MainWindow = window;

            // Get the Buttons
            Button buttonRed = (Button)window.GetChildByName("buttonRed");
            Button buttonGreen = (Button)window.GetChildByName("buttonGreen");
            Button buttonBlue = (Button)window.GetChildByName("buttonBlue");

            // Set up event handlers
            buttonRed.TapEvent += new OnTap(buttonRed_TapEvent);
            buttonGreen.TapEvent += new OnTap(buttonGreen_TapEvent);
            buttonBlue.TapEvent += new OnTap(buttonBlue_TapEvent);

        }

        void buttonBlue_TapEvent(object sender)
        {
            Debug.Print("Blue tapped");
        }

        void buttonGreen_TapEvent(object sender)
        {
            Debug.Print("Green tapped");
        }

        void buttonRed_TapEvent(object sender)
        {
            Debug.Print("Red tapped");
        }
    }
}


The screen properly displays the three buttons but does not log output to the console when the buttons are pressed. I have tried downloading the glide source and recompiling it with netmf 4.2 as the target as that is what im currently using as the target for my example program. I have also tried using the supplied Glide dll in the GHI sdk.

For some reason it seems like glide is not intercepting display touch events properly and therefore no buttons are working. Any help or advice would be appreciated.

Do you use hardware I2C? I think there were some issues with tat on Raptor.
If you use software I2C then it should work without any performance penalty on raptor.

1 Like

Right now I have the cp7 touch connection connected to port 6 on my raptor. That wasn’t working initially but the driver change fixed that problem and the screen is outputting touch events over i2c on that port correctly. I’ve tried stepping into the initialize touch method on glide but the event handlers that get setup in initialize touch for handling display events never fire the glide delegates. But the screen touch events that glide defines handlers for are being emitted as i can create a handler in ProgramStarted that fires correctly whenever i touch tap gesture over the cp7.

OK so some new info even with the driver fix i used i still get

“Failed to perform I2C transaction” in the debug console when using glide but not when using native touch events.

For instance:

this works and properly fires touch events and draws ellipses and logs to console correctly with no error messages.


using Microsoft.SPOT;

namespace GadgeteerApp2
{
    public partial class Program
    {
        void ProgramStarted()
        {
            this.display_CP7.ScreenPressed += (a, b) => display_CP7.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Red, (uint)b.touchPos[0].xPos, (uint)b.touchPos[0].yPos, 5, 5);
            this.display_CP7.ScreenReleased += (a) => Debug.Print("R");
            this.display_CP7.MenuPressed += (a) => Debug.Print("M");
            this.display_CP7.HomePressed += (a) => Debug.Print("H");
            this.display_CP7.BackPressed += (a) => Debug.Print("B");
        }
    }
}

But the glide example i posted outputs “Failed to perform I2C transaction” whenever i touch the screen which is causing events to not be fired when using glide.

About software i2c what would i need to do to use software i2c rather than the native i2c coming from port 6. I figure i can atleast test that and see if it fixes the glide problem im having.

There is an issue, as Reinhard noted with the G400 processor and I2C and LCD timing.

Changing to the software I2C will work well and I actually found that there was little impact in through put. The G400 is fast enough that you don’t notice it.

I am fast sampling a bunch of MCP3428’s on a shared I2C bus with the touch driver working under interrupts. It works without loss of any data. I get a huge improvement in processing power from the previous ChipworkX module and I have a higher resolution screen to boot.

2 Likes

I too had problems with CP7 but with a FEZ Spider. When I used the Glide.Initialize() function it never worked an generated the I2C issue you saw.

In a post somewhere, sorry I cant seem to find it, someone suggested removing this line of code due to port conflict as Glide is setup for T but the CP7 needs I (different config).

Then I set up my own Press handlers as per the postings in the forums and forwarded it to Glide

An example of the code is here:
https://drive.google.com/file/d/0B33xtdsvpTTSM1lmZlcydVRyVW8/edit?usp=sharing

Look specifically at display.cs

So I did this and it worked. I am not sure if it is applicable in your case but it is worth a try.

HTH
Khalil

2 Likes

Thanks khalilm, Dave, Reinhard I just threw this together based on Khalilm’s example and it worked. I’ll just manually register the screen events with glide as its the quickest at the moment although i may eventually revisit software i2c. Here is the working example.


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Glide;
using GHI.Glide.UI;
using GHI.Glide.Geom;

namespace GlideButtonDemo
{
    public partial class Program
    {
        static GHI.Glide.Display.Window window;

        Point last = new Point(0, 0);
        bool touched = false;


        void ProgramStarted()
        {
            // Do one-time tasks here
            Debug.Print("Program Started");

            // Load the Window XML string.
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Window1));

            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Assign the Window to MainWindow; rendering it to the LCD.
            Glide.MainWindow = window;

            this.display_CP7.ScreenPressed += (a, b) => display_CP7_ScreenPressed(a, b);
            this.display_CP7.ScreenReleased += (a) => display_CP7_ScreenReleased(a);

            // Get the Buttons
            Button buttonRed = (Button)window.GetChildByName("buttonRed");
            Button buttonGreen = (Button)window.GetChildByName("buttonGreen");
            Button buttonBlue = (Button)window.GetChildByName("buttonBlue");

            // Set up event handlers
            buttonRed.TapEvent += new OnTap(buttonRed_TapEvent);
            buttonGreen.TapEvent += new OnTap(buttonGreen_TapEvent);
            buttonBlue.TapEvent += new OnTap(buttonBlue_TapEvent);

        }

        void buttonBlue_TapEvent(object sender)
        {
            Debug.Print("Blue tapped");
        }

        void buttonGreen_TapEvent(object sender)
        {
            Debug.Print("Green tapped");
        }

        void buttonRed_TapEvent(object sender)
        {
            Debug.Print("Red tapped");
        }

        void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            if (touchStatus.numTouches <= 0 || GlideTouch.IgnoreAllEvents)
                return;

            Point touch = new Point(touchStatus.touchPos[0].xPos, touchStatus.touchPos[0].yPos);

            if (this.touched)
            {
                if (this.last.X != touch.X || this.last.Y != touch.Y)
                    GlideTouch.RaiseTouchMoveEvent(sender, new TouchEventArgs(touch));
                //GlideTouch.RaiseTouchDownEvent(sender, new TouchEventArgs(touch));

                this.last.X = touch.X;
                this.last.Y = touch.Y;
            }
            else
            {
                this.last.X = touch.X;
                this.last.Y = touch.Y;
                this.touched = true;

                GlideTouch.RaiseTouchDownEvent(sender, new TouchEventArgs(touch));
            }
        }

        void display_CP7_ScreenReleased(Display_CP7 sender)
        {
            this.touched = false;

            GlideTouch.RaiseTouchUpEvent(sender, new TouchEventArgs(this.last));
        }
    }
}


1 Like