@John_Brochue: for now, touch seems to be complicated to implement for me.
I try code below, but can’t see change control (maybe I don’t understand what right,left … behaviour is):
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using G400UI.Properties;
using GHIElectronics.TinyCLR.Devices.Display;
using GHIElectronics.TinyCLR.Devices.Gpio.Provider;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.UI;
using GHIElectronics.TinyCLR.UI.Controls;
using GHIElectronics.TinyCLR.UI.Input;
using GHIElectronics.TinyCLR.UI.Media;
using ButtonEventHandler = Bauland.Gadgeteer.ButtonEventHandler;
// ReSharper disable UnusedMember.Global
namespace G400UI
{
class Program : Application
{
private static InputProvider _inputProvider;
private Program(DisplayController d) : base(d) { }
static void Main()
{
// Init button
Bauland.Gadgeteer.Button buttonLeft =
new Bauland.Gadgeteer.Button(FEZRaptor.GpioPin.Socket13.Pin3, FEZRaptor.GpioPin.Socket13.Pin4);
Bauland.Gadgeteer.Button buttonRight =
new Bauland.Gadgeteer.Button(FEZRaptor.GpioPin.Socket12.Pin3, FEZRaptor.GpioPin.Socket12.Pin4);
//Bauland.Gadgeteer.Button buttonUp =
// new Bauland.Gadgeteer.Button(FEZRaptor.GpioPin.Socket11.Pin3, FEZRaptor.GpioPin.Socket11.Pin4);
Bauland.Gadgeteer.Button buttonDown =
new Bauland.Gadgeteer.Button(FEZRaptor.GpioPin.Socket10.Pin3, FEZRaptor.GpioPin.Socket10.Pin4);
var version = new Version(DeviceInformation.Version);
string info = "Device: " + DeviceInformation.DeviceName + " - " + version;
Debug.WriteLine(info);
var displayController = DisplayController.GetDefault();
// Enter the proper display configurations
displayController.ApplySettings(new ParallelDisplayControllerSettings
{
Width = 480,
Height = 272,
PixelClockRate = 20 * 1000 * 1000,
PixelPolarity = false,
OutputEnablePolarity = true,
OutputEnableIsFixed = false,
HorizontalFrontPorch = 2,
HorizontalBackPorch = 2,
HorizontalSyncPulseWidth = 41,
HorizontalSyncPolarity = false,
VerticalFrontPorch = 2,
VerticalBackPorch = 2,
VerticalSyncPulseWidth = 10,
VerticalSyncPolarity = false
});
var app = new Program(displayController);
_inputProvider = app.InputProvider;
buttonLeft.Pressed += Btn_Left_Pressed;
buttonLeft.Released += Btn_Left_Released;
buttonRight.Pressed += Btn_Right_Pressed;
buttonRight.Released += Btn_Right_Released;
//buttonUp.Pressed += Btn_Up_Pressed;
//buttonUp.Released += Btn_Up_Released;
buttonDown.Pressed += Btn_Down_Pressed;
buttonDown.Released += Btn_Down_Released;
app.Run(CreateWindow(displayController));
//// Some needed objects
//var screen = Graphics.FromHdc(displayController.Hdc);
//// Start Drawing (to memroy)
//screen.Clear(Color.Black);
//var brush = new SolidBrush(Color.Green);
//var font = Resources.GetFont(Resources.FontResources.NinaB);
//screen.DrawString(info, font, brush, 20, 20);
//// Flush the memory to the display. This is a very fast operation.
//screen.Flush();
}
private static void Btn_Left_Released(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Left, false, DateTime.UtcNow);
}
private static void Btn_Left_Pressed(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Left, true, DateTime.UtcNow);
}
private static void Btn_Right_Released(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Right, false, DateTime.UtcNow);
}
private static void Btn_Right_Pressed(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Right, true, DateTime.UtcNow);
}
private static void Btn_Up_Released(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Up, false, DateTime.UtcNow);
}
private static void Btn_Up_Pressed(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Up, true, DateTime.UtcNow);
}
private static void Btn_Down_Released(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Down, false, DateTime.UtcNow);
}
private static void Btn_Down_Pressed(object sender, Bauland.Gadgeteer.ButtonEventHandlerArgs args)
{
_inputProvider.RaiseButton(HardwareButton.Down, true, DateTime.UtcNow);
}
private static Window CreateWindow(DisplayController displayController)
{
var window = new Window
{
Height = (int)displayController.ActiveSettings.Height,
Width = (int)displayController.ActiveSettings.Width
};
window.Background = new SolidColorBrush(Color.FromRgb(0, 0, 64));
var font = Resources.GetFont(Resources.FontResources.small);
OnScreenKeyboard.Font = font;
//List
var listBox = new ListBox { Child = { Width = window.Width } };
//Text
for (var i = 0; i < 3; i++)
{
var text = new Text(font, $"Text item {i}");
text.SetMargin(5);
text.ForeColor = Colors.Yellow;
listBox.Items.Add(text);
}
//Button
var j = 0;
var val = new Text(font, "Tap Me");
var btn = new Button
{
Child = val,
Width = 100
};
btn.SetMargin(5);
btn.Click += (s, e) => val.TextContent = "Tap Me " + (j++).ToString();
listBox.Items.Add(btn);
//Textbox
var txt = new TextBox
{
Font = font,
Text = "Text Sample"
};
txt.SetMargin(5);
listBox.Items.Add(txt);
// Text
var label = new Text
{
Font = font,
TextContent = DeviceInformation.DeviceName,
ForeColor = Colors.Yellow
};
listBox.Items.Add(label);
//Setup
window.Child = listBox;
window.Visibility = Visibility.Visible;
return window;
}
}
public class Version
{
private int Major { get; }
private int Minor { get; }
private int Patch { get; }
private int Build { get; }
public Version(ulong version)
{
Major = (int)((version >> 48) & 0x000000000000ffff);
Minor = (int)((version >> 32) & 0x000000000000ffff);
Patch = (int)((version >> 16) & 0x000000000000ffff);
Build = (int)((version >> 00) & 0x000000000000ffff);
}
public override string ToString()
{
return Major + "." + Minor + "." + Patch + "." + Build;
}
}
}