This repository has been archived on 2019-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
PixelHub/PixelHub-Server/PixelHub/PixelCommand.cs

75 lines
1.9 KiB
C#

using System;
namespace PixelHub
{
public enum PixelWheel
{
None,
Left,
Right,
Both
}
/// <summary>
/// Specifies a single command that is to be sent to a PixelBot.
/// </summary>
public class PixelCommand
{
/// <summary>
/// The wheel(s) that should be operated upon.
/// </summary>
public PixelWheel Wheel { get; set; }
/// <summary>
/// The duration, in milliseconds, that the left wheel should turn for.
/// </summary>
public int DurationLeft { get; set; }
/// <summary>
/// The duration, in milliseconds, that the right wheel should turn for.
/// </summary>
/// <value>The duration right.</value>
public int DurationRight { get; set; }
/// <summary>
/// The duration, in milliseconds, that the wheels should turn for.
/// </summary>
/// <description>
/// This property sets both the <see cref="DurationLeft" /> and <see cref="DurationRight" /> properties.
/// The getter returns the maximum of the two durations.
/// </description>
public int Duration {
get {
return Math.Max(DurationLeft, DurationRight);
}
set {
DurationLeft = value;
DurationRight = value;
}
}
/// <summary>
/// Creates a new <see cref="PixelCommand" /> instance.
/// </summary>
/// <param name="inWheel">The wheel to turn.</param>
/// <param name="inDuration">The duration , in milliseconds, to turn the wheels for.</param>
public PixelCommand(PixelWheel inWheel, int inDuration)
{
Wheel = inWheel;
Duration = inDuration;
}
/// <summary>
/// Compiles the PixelCommand into a raw command string that cna be understood by the PixelBot.
/// </summary>
/// <returns>The compiled command, ready to be sent over the wire to the PixelBot.</returns>
public string AsCompiledCommand()
{
return $"Move:L={DurationLeft},Right={DurationRight}";
}
public override string ToString()
{
return string.Format("PixelCommand: Targets Wheel={0} for Duration={1}ms", Wheel, Duration);
}
}
}