That would be a task
Do you think I should narrow it down a bit the main window is my crane display this is whre most crashes take place as its the default window.
public class craneview : BaseWindow
{
// Reference to the Desktop window
private Desktop _window;
// Image that represents this window
private Bitmap screen = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
// Fonts
private Font ninaBFont = Resources.GetFont(Resources.FontResources.NinaB);
private Font smallFont = Resources.GetFont(Resources.FontResources.small);
private Font segoeFont = Resources.GetFont(Resources.FontResources.SegoeUI12Bold);
private Font selectedfont = Resources.GetFont(Resources.FontResources.CourierNew32Bold);
private Bitmap uniccrane = Resources.GetBitmap(Resources.BitmapResources.unic);
private Bitmap _task = Resources.GetBitmap(Resources.BitmapResources.taskbar);
private Bitmap _bar = Resources.GetBitmap(Resources.BitmapResources.bargraphG);
private DispatcherTimer loopTimer;
private sbyte ATB = 0, OR = 0;
private float length = (float)1.7;
private float radius = 1;
private float swl = (float)2.45 ;
private float weight = 0, angle = 50;
private string messages;
private int bar = 3;
private Random random = new Random();
AnalogIn pot1 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain2);
AnalogIn pot2 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain3);
AnalogIn pot3 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain6);
// Stops loops from throwing errors on exit
private bool exiting = false;
public craneview(Desktop window)
{
_window = window;
this.TouchDown += OnTouchDown;
loopTimer = new DispatcherTimer();
loopTimer.Tick += Loop;
loopTimer.Interval = new TimeSpan(0, 0, 0, 0, 200); // 16 FPS
loopTimer.Start();
}
/// <summary>
/// Renders the screen bitmap initially.
/// </summary>
/// <param name="dc"></param>
public override void OnRender(DrawingContext dc)
{
dc.DrawImage(screen, 0, 0);
}
/// <summary>
/// Loop that handles the game's logic.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Loop(object sender, EventArgs e)
{
if (exiting) return;
weight = angle = length = 0;
for (int b = 0; b <7; b++)
{
weight += (float)pot1.Read() / 350;
angle += (float)pot2.Read() / 10;
length += (float)pot3.Read() / 300;
}
length /= 8; angle /= 8; weight /= 8;
double limit = 2.45 /( 1 + (length / 3.4));
if (length > 1)
limit = limit * (angle / 90);
swl = (float)limit;
length += 1.7f;
radius = length * (float)(MathEx.Cos(angle * 0.017444));
radius -= 0.3f;
if (swl > 0)
bar = (int)(160 * (weight / swl));
if (bar > 160) bar = 160;
messages = "";
_bar = Resources.GetBitmap(Resources.BitmapResources.bargraphG);
if (ATB == 1)
messages = "ATB ON";
if (bar > 120)
{
messages = "APPROACH";
_bar = Resources.GetBitmap(Resources.BitmapResources.bargraphO);
}
if (bar > 140)
{
messages = "OVER LOAD";
_bar = Resources.GetBitmap(Resources.BitmapResources.bargraphR);
}
if (bar > 150)
messages = "CUT OUT";
if (OR == 1)
messages = "OVERRIDE";
UpdateScreen();
}
/// <summary>
/// Update the screen bitmap.
/// </summary>
private void UpdateScreen()
{
screen.Clear();
screen.Scale9Image(0, 0, this.Width, 32, _task, 0, 0, 0, 0, 0xFF);
screen.Scale9Image(350 ,230 - bar , 80, bar, _bar, 0, 0, 0, 0, 0xFF);
screen.DrawImage(0, 32, uniccrane, 0, 0, uniccrane.Width, uniccrane.Height);
screen.DrawText(angle.ToString("F1"), segoeFont, Color.Black, 5, 180);
screen.DrawText(length.ToString("F1"), segoeFont, Color.Black, 165, 170);
screen.DrawText(radius.ToString("F1"), segoeFont, Color.Black, 185, 230);
screen.DrawText(messages, ninaBFont, Color.White, 5, 5);
screen.DrawText(weight.ToString("F3")+ " LOAD", segoeFont, Color.White, 350, 250);
screen.DrawText(swl.ToString("F3")+" SWL", segoeFont, Color.White, 350, 32);
screen.Flush();
}
/// <summary>
/// Get a random number between two values.
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
private int Randomize(int min, int max)
{
return (random.Next() % (max - min)) + min;
}
/// <summary>
/// Exit this window by touch.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTouchDown(object sender, TouchEventArgs e)
{
Exit();
}
/// <summary>
/// Exit this window by button.
protected override void OnButtonDown(ButtonEventArgs e)
{
if (e.Button == Button.VK_SELECT)
Exit();
if (e.Button == Button.VK_UP)
ATB = 1;
if (e.Button == Button.VK_DOWN)
OR = 1;
}
protected override void OnButtonUp(ButtonEventArgs e)
{
if (e.Button == Button.VK_UP)
ATB = 0;
if (e.Button == Button.VK_DOWN)
OR = 0;
}
/// <summary>
/// Exit this window.
/// </summary>
public override void Exit()
{
exiting = true;
loopTimer.Stop();
screen.Clear();
pot1.Dispose();
pot2.Dispose();
pot3.Dispose();
this.Close();
_window.SetFocus();
}
}
Its been running about 2 hours now linked to the debugger (typical)
Cheers