Glide, CP7 Display and FEZ Raptor

Hi,

I’m using FEZ Raptor, Glide UI on CP7 Display and NETMF version is 4.2.

I managed to solve the I2C Failure (on https://www.ghielectronics.com/community/forum/topic?id=15360) with the code below but I’m now having problem triggering the button Tap Event.

When I pressed on my CP7 Display, the code is registering the input as the output line are printing:
[em]=== Raise Touch Up Event
=== Raise Touch Down Event
=== Raise Touch Up Event
=== Raise Touch Down Event
=== Raise Touch Up Event
Screen Released[/em]

and the UI also shows the pressed effect but my question is how do I wired up the _btnToggle.TapEvent event correctly?

Here’s my code.

    public partial class Program
    {
        private GHI.Glide.Display.Window _mainWindow;
        private GHI.Glide.UI.Button _btnToggle;
        private GHI.Glide.UI.TextBlock _tbCounter;

        private bool isLedOn = true;
        private int _clickCounter = 0;

        static int lastX = 0;
        static int lastY = 0;
        static int x;
        static int y;
        static bool isTouched = false;

        void ProgramStarted()
        {
            ledStrip.TurnAllLedsOn();
            isLedOn = true;

            bToggle.LEDMode = Button.LEDModes.OnWhilePressed;
            bToggle.ButtonPressed += bToggle_ButtonPressed;

            SetupScreen();

            Debug.Print("Program Started");
        }

        private void SetupScreen()
        {
            Glide.FitToScreen = true;
            _mainWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.MainWindow));

            _btnToggle = (GHI.Glide.UI.Button)_mainWindow.GetChildByName("btnToggle");
            _tbCounter = (GHI.Glide.UI.TextBlock)_mainWindow.GetChildByName("tbCounter");

            _btnToggle.TapEvent += _btnToggle_TapEvent;

            displayMain.HomePressed += displayMain_HomePressed;
            displayMain.MenuPressed += displayMain_MenuPressed;
            displayMain.ScreenReleased += displayMain_ScreenReleased;
            displayMain.ScreenPressed += displayMain_ScreenPressed;

            Glide.MainWindow = _mainWindow;
            //GlideTouch.Initialize();
        }

        void displayMain_ScreenReleased(Display_CP7 sender)
        {
            Debug.Print("Screen Released");
        }

        void displayMain_MenuPressed(Display_CP7 sender)
        {
            Debug.Print("Menu Pressed");
        }

        void displayMain_HomePressed(Display_CP7 sender)
        {
            Debug.Print("Home Pressed");
        }

        void displayMain_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            //displayMain.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Red, (uint)touchStatus.touchPos[0].xPos, (uint)touchStatus.touchPos[0].yPos, 5, 5);

            GHI.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));
                    Debug.Print("=== Raise Touch Down Event");
                    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));
                        Debug.Print("=== Raise Touch Up Event");
                        isTouched = false;
                    }
                }
            }
            else
            {
                if (isTouched == true)
                {
                    touches.X = lastX;
                    touches.Y = lastY;
                    GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
                    Debug.Print("=== Raise Touch Up Event (Single)");
                    isTouched = false;
                }
            }
        }

        void _btnToggle_TapEvent(object sender)
        {
            ToggleLed();
        }

        void bToggle_ButtonPressed(Button sender, Button.ButtonState state)
        {
            ToggleLed();
        }

        private void ToggleLed()
        {
            _clickCounter += 1;
            if (isLedOn)
            {
                ledStrip.TurnAllLedsOff();
                isLedOn = false;
            }
            else
            {
                ledStrip.TurnAllLedsOn();
                isLedOn = true;
            }
            _tbCounter.Text = _clickCounter.ToString();
            _mainWindow.Invalidate();
        }
    }

Hi jeeshenlee, and welcome to the forum.

So I am not quite sure I understand - and not having a CP7 I can’t test your code. I think that you are wanting to set up the button tap event correctly - can you actually add a debug.print to the button tap event to make sure it’s not working already ??

Hi Brett, thanks!

Yes, I just did and it’s not triggering.

How do I wired the GlideTouch event to my Button control tap event?

Well according to the code in this example https://www.ghielectronics.com/community/codeshare/entry/349 it’s as simple as:

// Get the Buttons
GHIElectronics.NETMF.Glide.UI.Button buttonRed = (GHIElectronics.NETMF.Glide.UI.Button)window.GetChildByName("buttonRed");
GHIElectronics.NETMF.Glide.UI.Button buttonGreen = (GHIElectronics.NETMF.Glide.UI.Button)window.GetChildByName("buttonGreen");
GHIElectronics.NETMF.Glide.UI.Button buttonBlue = (GHIElectronics.NETMF.Glide.UI.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)
{
led.TurnBlue();
}



I can’t vouch for the validity or the currency of the code, but OnTap seems to be the key.

Hi Brett,

Yes, I understand. I managed to run the code on other display (e.g. GHI Display T43) but somehow it doesn’t work on CP7 Display. ???

Given the resolution change, I would suspect it could be a screen position error - but I don’t know how to approach diagnosing that; perhaps a long row of buttons along the screen, and see if you can get any press detections working?.

I havent tried it with the Raptor yet, but I tried a number of ways to get CP7 to generate screen presses. The only way I got it to work successfully was with this code.


        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));
                
                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));
        }

Maybe this might work for you.

Found the problem. ;D

Just realize _btnToggle.TapEvent is actually DisplayObject event.

Replace the TapEvent with PressEvent and everything works well now. Thanks!



[em]NOTE: PressEvent is Button's event.[/em]