using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using winforms = System.Windows.Forms;
using Microsoft.Ccr.Core;
using Microsoft.Dss.ServiceModel.Dssp;
namespace Robotics
.RoboBoard
{
partial class RoboBoardForm
: Form
{
RoboBoardEvents _eventsPort
;
enum PanelState
{ Idle, GPS, MKSensor, ExtenderBoard, RawData, Control
};
public Int16
[] MK_analog
= new Int16
[32];
public string[] Mk_analog_name
= new string[32];
public Int16 Control_alt
;
public Int16 Control_roll
;
public Int16 Control_nick
;
public Int16 Control_gier
;
public Int16 Control_gas
;
int panelstate
= (int)PanelState
.Idle;
public RoboBoardForm
(RoboBoardEvents EventsPort
)
{
_eventsPort
= EventsPort
;
InitializeComponent
();
// UpdateStatus("<unknown>");
}
public void UpdateStatus
(string Status
) {
toolStripStatusLabel1
.Text = Status
;
}
/// <summary>
/// posts the instace of the form to the main process
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RoboBoardForm_Load
(object sender, EventArgs e
)
{
_eventsPort
.Post(new OnLoad
(this));
}
/// <summary>
/// Invalidate the Panel area and trigger a repaint
/// </summary>
/// <param name="Command"></param>
public void MonitorCommand
(string Command
)
{
MainPanel
.Invalidate();
}
/// <summary>
/// update data value
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
/// <param name="name"></param>
public void MonitorMKSensor
(int index, Int16
value,
string name
)
{
if (index
> 31) return;
MK_analog
[index
] = value;
if (name
== "") return;
Mk_analog_name
[index
] = name
;
}
public void MonitorMKSensorUpdate
()
{
MainPanel
.Invalidate();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainPanel_Paint
(object sender, PaintEventArgs e
)
{
int i
;
Graphics dc
= e
.Graphics;
Font stdFont
= new Font
("Arial",
10);
SolidBrush stdBrush
= new SolidBrush
(Color
.Green);
Font sensorFont
= new Font
("Arial",
8);
SolidBrush sensorBrush
= new SolidBrush
(Color
.Black);
switch (panelstate
)
{
case (int)PanelState
.Control:
dc
.DrawString("Control Data Monitor", stdFont, stdBrush,
2,
2);
dc
.DrawString("Nick", sensorFont, sensorBrush,
10,
14);
dc
.DrawString(Control_nick
.ToString(), sensorFont, sensorBrush,
200,
14);
dc
.DrawString("Roll", sensorFont, sensorBrush,
10,
24);
dc
.DrawString(Control_roll
.ToString(), sensorFont, sensorBrush,
200,
24);
dc
.DrawString("Gier", sensorFont, sensorBrush,
10,
34);
dc
.DrawString(Control_gier
.ToString(), sensorFont, sensorBrush,
200,
34);
dc
.DrawString("Gas", sensorFont, sensorBrush,
10,
44);
dc
.DrawString(Control_gas
.ToString(), sensorFont, sensorBrush,
200,
44);
dc
.DrawString("Altitute", sensorFont, sensorBrush,
10,
54);
dc
.DrawString(Control_alt
.ToString(), sensorFont, sensorBrush,
200,
54);
break;
case (int)PanelState
.RawData:
dc
.DrawString("Raw Data", stdFont, stdBrush,
2,
2);
break;
case (int)PanelState
.ExtenderBoard:
dc
.DrawString("Extender Board Data", stdFont, stdBrush,
2,
2);
break;
case (int)PanelState
.GPS:
dc
.DrawString("GPS Data", stdFont, stdBrush,
10,
10);
break;
case (int)PanelState
.MKSensor:
dc
.DrawString("Mikrokopter Sensors", stdFont, stdBrush,
2,
2);
for (i
= 0; i
< 32; i
++)
{
if (Mk_analog_name
[i
] == null)
{
dc
.DrawString("<unknown>", sensorFont, sensorBrush,
10,
(float)(14 + (i
* 10)));
}
else
{
dc
.DrawString(Mk_analog_name
[i
], sensorFont, sensorBrush,
10,
(float)(14 + (i
* 10)));
}
dc
.DrawString(MK_analog
[i
].ToString(), sensorFont, sensorBrush,
200,
(float)(14 + (i
* 10)));
}
break;
case (int)PanelState
.Idle:
dc
.DrawString("Select Mode (no mode selected)", stdFont, stdBrush,
2,
2);
break;
default:
dc
.DrawString("Select Mode", stdFont, stdBrush,
2,
2);
break;
}
}
private void toolStripButton1_Click
(object sender, EventArgs e
)
{
panelstate
= (int)PanelState
.GPS;
MainPanel
.Invalidate();
}
private void toolStripButton2_Click
(object sender, EventArgs e
)
{
panelstate
= (int)PanelState
.MKSensor;
MainPanel
.Invalidate();
}
private void toolStripButton3_Click
(object sender, EventArgs e
)
{
panelstate
= (int)PanelState
.Control;
MainPanel
.Invalidate();
}
}
class RoboBoardEvents
:PortSet
<OnLoad,OnClosed
>
{
}
class RoboBoardEvent
{
private RoboBoardForm _rbForm
;
public RoboBoardForm RoboBoardForm
{
get { return _rbForm
; }
set { _rbForm
= value; }
}
public RoboBoardEvent
(RoboBoardForm rbForm
)
{
_rbForm
= rbForm
;
}
}
class OnLoad
: RoboBoardEvent
{
public OnLoad
(RoboBoardForm form
)
: base(form
)
{
}
}
class OnClosed
: RoboBoardEvent
{
public OnClosed
(RoboBoardForm form
)
: base(form
)
{
}
}
}