Ok, I just typed a very long post, and lost all of it. Ugh, this has not been a fun day.
So, I took my first VB program to do some simple graphics on the CP7:
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Namespace FEZHydraCP7test
Partial Public Class Program
Dim numtouch As Integer = 0
Dim xpos As Integer = 0
Dim ypos As Integer = 0
' This is run when the mainboard is powered up or reset.
Public Sub ProgramStarted()
'*******************************************************************************************
' Hardware modules added in the Program.gadgeteer designer view are used by typing
' their name followed by a period, e.g. button. or camera.
'
' Many hardware modules generate useful events. To set up actions for those events, use the
' left dropdown box at the top of this code editing window to choose a hardware module, then
' use the right dropdown box to choose the event - an event handler will be auto-generated.
'*******************************************************************************************/
' Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started")
'Thread.Sleep(1000)
' Displays "Hello World" on the screen in red text at screen coordinates 100,100
display.SimpleGraphics.DisplayText("Hello World", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 100)
End Sub
Private Sub display_BackPressed(ByVal sender As Gadgeteer.Modules.GHIElectronics.Display_CP7) Handles display.BackPressed
display.SimpleGraphics.DisplayTextInRectangle("Back to the Future", 300, 300, 200, 30, GT.Color.Purple, Resources.GetFont(Resources.FontResources.NinaB))
End Sub
Private Sub display_HomePressed(ByVal sender As Gadgeteer.Modules.GHIElectronics.Display_CP7) Handles display.HomePressed
display.SimpleGraphics.Clear()
End Sub
Private Sub display_MenuPressed(ByVal sender As Gadgeteer.Modules.GHIElectronics.Display_CP7) Handles display.MenuPressed
display.SimpleGraphics.DisplayText("No Menu Yet", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 350, 250)
End Sub
Private Sub display_ScreenPressed(ByVal sender As Gadgeteer.Modules.GHIElectronics.Display_CP7, ByVal touchStatus As Gadgeteer.Modules.GHIElectronics.Display_CP7.TouchStatus) Handles display.ScreenPressed
display.SimpleGraphics.DisplayRectangle(GT.Color.Black, 1, GT.Color.Black, 90, 190, 50, 130)
numtouch = touchStatus.numTouches
display.SimpleGraphics.DisplayText(CStr(numtouch), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 200)
xpos = touchStatus.touchPos(numtouch - 1).xPos
display.SimpleGraphics.DisplayText(CStr(xpos), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 250)
ypos = touchStatus.touchPos(numtouch - 1).yPos
display.SimpleGraphics.DisplayText(CStr(ypos), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 300)
display.SimpleGraphics.DisplayEllipse(GT.Color.Cyan, xpos, ypos, 10, 10)
End Sub
' If you want to do something periodically, declare a GT.Timer by uncommenting the below line
' and then use the dropdown boxes at the top of this window to generate a Tick event handler.
' Dim WithEvents timer As GT.Timer = new GT.Timer(1000) ' every second (1000ms)
Private Sub display_ScreenReleased(ByVal sender As Gadgeteer.Modules.GHIElectronics.Display_CP7) Handles display.ScreenReleased
Debug.Print("Screen Press Release Detected")
display.SimpleGraphics.DisplayEllipse(GT.Color.Red, xpos, ypos, 10, 10)
End Sub
End Class
End Namespace
This code never let me get into debug, even if the config loaded and I hit Ctrl-Shft-F5. I created some similar code in C#:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace FEZHydraCP7Test
{
public partial class Program
{
int numtouch = 0;
int xpos = 0;
int ypos = 0;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
display_CP7.SimpleGraphics.DisplayText("Hello World", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 100);
display_CP7.ScreenPressed += new Display_CP7.TouchEventHandler(display_CP7_ScreenPressed);
display_CP7.ScreenReleased += new Display_CP7.TouchEventHandlerTouchReleased(display_CP7_ScreenReleased);
display_CP7.HomePressed += new Display_CP7.TouchEventHandlerHomeButton(display_CP7_HomePressed);
display_CP7.BackPressed += new Display_CP7.TouchEventHandlerBackButton(display_CP7_BackPressed);
display_CP7.MenuPressed += new Display_CP7.TouchEventHandlerMenuButton(display_CP7_MenuPressed);
}
void display_CP7_MenuPressed(Display_CP7 sender)
{
display_CP7.SimpleGraphics.DisplayText("No Menu Yet", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 350, 250);
}
void display_CP7_BackPressed(Display_CP7 sender)
{
display_CP7.SimpleGraphics.DisplayTextInRectangle("Back to the Future", 300, 300, 200, 30, GT.Color.Purple, Resources.GetFont(Resources.FontResources.NinaB));
}
void display_CP7_HomePressed(Display_CP7 sender)
{
display_CP7.SimpleGraphics.Clear();
display_CP7.SimpleGraphics.DisplayText("Hello World", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 100);
}
void display_CP7_ScreenReleased(Display_CP7 sender)
{
Debug.Print("Screen Press Release Detected");
display_CP7.SimpleGraphics.DisplayEllipse(GT.Color.Red, (uint) xpos, (uint) ypos, 10, 10);
}
void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
{
display_CP7.SimpleGraphics.DisplayRectangle(GT.Color.Black, 1, GT.Color.Black, 90, 190, 50, 130);
numtouch = touchStatus.numTouches;
xpos = touchStatus.touchPos[numtouch - 1].xPos;
ypos = touchStatus.touchPos[numtouch - 1].yPos;
display_CP7.SimpleGraphics.DisplayText(numtouch.ToString(), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 200);
display_CP7.SimpleGraphics.DisplayText(xpos.ToString(), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 250);
display_CP7.SimpleGraphics.DisplayText(ypos.ToString(), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 100, 300);
display_CP7.SimpleGraphics.DisplayEllipse(GT.Color.Cyan, (uint) xpos, (uint) ypos, 10, 10);
}
}
}
That fired up right into debug mode no problem. I assume it didn’t need to change the config?
Well, then I tried the following in C# to just display a glide window like in my second post:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
//using Microsoft.SPOT.Presentation;
//using Microsoft.SPOT.Presentation.Controls;
//using Microsoft.SPOT.Presentation.Media;
//using Microsoft.SPOT.Presentation.Shapes;
//using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Glide;
using GHI.Glide.Display;
using GHI.Glide.UI;
namespace FEZHydraCP7GlideTest
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
Window windowtest = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.testwindow));
Glide.FitToScreen = true;
Glide.MainWindow = windowtest;
}
}
}
It went into the reset loop for a couple minutes, and then displayed the window, just like the VB version. However, when I hit Ctrl-Shft-F5, it loaded right up into debug mode. Oddly enough, I tried the VB version again and that also managed to get into debug mode. presumably because it didn’t need to change the display config.
I thought I’d be smart, load the simple C# graphics code I first tested with in this post, and then try to load the VB version of that, but that didn’t work. Hitting Ctrl-Shft-F5 for that one in VB is just running a hamster wheel.
In summary, it seems that C# does a more consistent job, so maybe I’ll go with that instead. However, the real problem is why do I keep running into the reset loop when changing display configs. Likely, if I can fix that problem, VB will work as well. However, I’m still quite green and any help debugging this would be most appreciated.
Thanks,
Jon