| |
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Hardware;
using SPL.Script.Engine;
namespace SPLMFConsoleWindow1
{
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
Program myApplication = new Program();
Window mainWindow = myApplication.CreateWindow();
GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);
myApplication.Run(mainWindow);
}
private Window mainWindow;
//########################## Sample Code #################################
private ConsoleWindow _consoleWindow;
private I2CDevice _device = null;
//##########################################################################
public Window CreateWindow()
{
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
//########################## Sample Code #################################
Font font = Resources.GetFont(Resources.FontResources.small);
_consoleWindow = new ConsoleWindow(font);
mainWindow.Child = _consoleWindow;
//##########################################################################
mainWindow.AddHandler(Buttons.ButtonUpEvent, new ButtonEventHandler(OnButtonUp), false);
mainWindow.Visibility = Visibility.Visible;
Buttons.Focus(mainWindow);
//########################## Sample Code #################################
_consoleWindow.WriteLine("Up button -> Go Forwards");
_consoleWindow.WriteLine("Down button -> Go Backwards");
_consoleWindow.WriteLine("Left button -> Turn Left");
_consoleWindow.WriteLine("Right button -> Turn Right");
_consoleWindow.WriteLine("Select button -> Stop");
//##########################################################################
//########################## Sample Code #################################
I2CDevice.Configuration config = new I2CDevice.Configuration(
58,
100
);
_device = new I2CDevice(config);
//##########################################################################
return mainWindow;
}
private void OnButtonUp(object sender, ButtonEventArgs e)
{
//########################## Sample Code #################################
if (e.Button == Microsoft.SPOT.Hardware.Button.VK_SELECT)
{
//Stop
byte[] wBuff = new byte[3];
wBuff[0] = 4;
wBuff[1] = 100; //100-100
wBuff[2] = 100;
I2CDevice.I2CWriteTransaction wTr = _device.CreateWriteTransaction(wBuff);
I2CDevice.I2CTransaction[] wTrArr = new I2CDevice.I2CTransaction[] { wTr };
int count = _device.Execute(wTrArr, 1000);
}
else if (e.Button == Microsoft.SPOT.Hardware.Button.VK_UP)
{
//Go Forwards
byte[] wBuff = new byte[3];
wBuff[0] = 4;
wBuff[1] = 120; //120-100
wBuff[2] = 120;
I2CDevice.I2CWriteTransaction wTr = _device.CreateWriteTransaction(wBuff);
I2CDevice.I2CTransaction[] wTrArr = new I2CDevice.I2CTransaction[] { wTr };
int count = _device.Execute(wTrArr, 1000);
}
else if (e.Button == Microsoft.SPOT.Hardware.Button.VK_DOWN)
{
//Go Backwards
byte[] wBuff = new byte[3];
wBuff[0] = 4;
wBuff[1] = 80;
wBuff[2] = 80;
I2CDevice.I2CWriteTransaction wTr = _device.CreateWriteTransaction(wBuff);
I2CDevice.I2CTransaction[] wTrArr = new I2CDevice.I2CTransaction[] { wTr };
int count = _device.Execute(wTrArr, 1000);
}
else if (e.Button == Microsoft.SPOT.Hardware.Button.VK_LEFT)
{
//Turn Left
byte[] wBuff = new byte[3];
wBuff[0] = 4;
wBuff[1] = 90;
wBuff[2] = 110;
I2CDevice.I2CWriteTransaction wTr = _device.CreateWriteTransaction(wBuff);
I2CDevice.I2CTransaction[] wTrArr = new I2CDevice.I2CTransaction[] { wTr };
int count = _device.Execute(wTrArr, 1000);
}
else if (e.Button == Microsoft.SPOT.Hardware.Button.VK_RIGHT)
{
//Turn Right
byte[] wBuff = new byte[3];
wBuff[0] = 4;
wBuff[1] = 100;
wBuff[2] = 90;
I2CDevice.I2CWriteTransaction wTr = _device.CreateWriteTransaction(wBuff);
I2CDevice.I2CTransaction[] wTrArr = new I2CDevice.I2CTransaction[] { wTr };
int count = _device.Execute(wTrArr, 1000);
}
//##########################################################################
}
}
}
| |