You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.4 KiB
122 lines
4.4 KiB
using RobotClientWpf.Utilities;
|
|
using RobotLib.Status;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace RobotClientWpf.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainView.xaml
|
|
/// </summary>
|
|
public partial class MainView : UserControl
|
|
{
|
|
private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
|
|
private ChallengeFactory? challenge;
|
|
private MainWindow? mainWindow;
|
|
private const int AMOUNT_SPEED_ADDED_PER_CLICK = 350;
|
|
private const int TURN_ANGLE_PER_CLICK = 30;
|
|
|
|
public MainView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void InitializeChildView(ChallengeFactory challenge, MainWindow parent)
|
|
{
|
|
this.challenge = challenge;
|
|
this.mainWindow = parent;
|
|
// subscribe to events
|
|
this.challenge.RobotStationary.SplitFlap.SplitFlapDisplayChanged += this.SplitFlap_SplitFlapDisplayChanged;
|
|
this.challenge.RobotMobile.Battery.BatteryChanged += Battery_BatteryChanged;
|
|
this.challenge.RobotMobile.Status.PresentChanged += Status_PresentChanged;
|
|
this.challenge.RobotMobile.Status.StatusChanged += Status_StatusChanged;
|
|
}
|
|
|
|
private void Status_StatusChanged(object? sender, RobotLib.Status.StatusEventArgs e)
|
|
{
|
|
// if status manual is set => reset present counter
|
|
if(e.Status == RoboStatus.Manual || e.Status == RoboStatus.Auto)
|
|
{
|
|
UIAccessHelpers.SetTextboxText(tbPresentCount, "");
|
|
}
|
|
}
|
|
|
|
private void Status_PresentChanged(object? sender, RobotLib.Status.PresentEventArgs e)
|
|
{
|
|
UIAccessHelpers.SetTextboxText(tbPresentCount, e.Present.ToString());
|
|
}
|
|
|
|
private void Battery_BatteryChanged(object? sender, RobotLib.Battery.BatteryEventArgs e)
|
|
{
|
|
UIAccessHelpers.SetTextboxText(tbRoboVoltage, e.Voltage.ToString());
|
|
}
|
|
|
|
public void SplitFlap_SplitFlapDisplayChanged(object? sender, RobotLib.SplitFlap.SplitFlapDisplayEventArgs e)
|
|
{
|
|
UIAccessHelpers.SetTextboxText(this.tbSplitflapText, e.DisplayMessage);
|
|
}
|
|
|
|
private void btnModeAuto_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.SetMobilityMode(true);
|
|
}
|
|
|
|
private void btnModeManual_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.SetMobilityMode(false);
|
|
}
|
|
|
|
private void btnRoboFwd_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.AddSpeed(AMOUNT_SPEED_ADDED_PER_CLICK);
|
|
}
|
|
private void btnRoboBwd_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.AddSpeed(-AMOUNT_SPEED_ADDED_PER_CLICK);
|
|
}
|
|
|
|
private void btnRoboRight_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Turn(TURN_ANGLE_PER_CLICK);
|
|
}
|
|
|
|
private void btnRoboLeft_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Turn(-TURN_ANGLE_PER_CLICK);
|
|
}
|
|
|
|
private void btnStopMove_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Stop();
|
|
}
|
|
|
|
public void HandleKeyDownEvent(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Up)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.AddSpeed(AMOUNT_SPEED_ADDED_PER_CLICK);
|
|
e.Handled = true;
|
|
}
|
|
else if (e.Key == Key.Down)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.AddSpeed(-AMOUNT_SPEED_ADDED_PER_CLICK);
|
|
e.Handled = true;
|
|
}
|
|
else if (e.Key == Key.Left)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Turn(-TURN_ANGLE_PER_CLICK);
|
|
e.Handled = true;
|
|
}
|
|
else if (e.Key == Key.Right)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Turn(TURN_ANGLE_PER_CLICK);
|
|
e.Handled = true;
|
|
}
|
|
else if (e.Key == Key.End)
|
|
{
|
|
this.challenge?.RobotMobile.Movement.Stop();
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|