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