Пример #1
0
            public static RealTouchCommand Parse(string line)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        return(null);
                    }

                    string[] parts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length < 2)
                    {
                        return(null);
                    }


                    TimeSpan timestamp = ParseDuration(parts[0]);

                    RealTouchCommand command = null;

                    switch (parts[1])
                    {
                    case "V":
                        command = new RealTouchVectorMovementCommand();
                        break;

                    case "P":
                        command = new RealTouchPeriodicMovementCommand();
                        break;

                    case "S":
                        command = new RealTouchStopCommand();
                        break;

                    default:
                        return(null);
                    }

                    if (command.MinParametersCount > parts.Length - 2)
                    {
                        return(null);
                    }

                    command.TimeStamp = timestamp;
                    command.Init(parts, 2);

                    return(command);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Could not parse line '{0}': {1}", line, e.Message);
                    return(null);
                }
            }
Пример #2
0
            public override RealTouchCommand Merge(RealTouchCommand last)
            {
                RealTouchVectorMovementCommand previous = (RealTouchVectorMovementCommand)last;

                return(new RealTouchVectorMovementCommand
                {
                    Axis = Axis,
                    Direction = Direction,
                    TimeStamp = previous.TimeStamp,
                    Duration = (TimeStamp + Duration) - previous.TimeStamp,
                    Magnitude = Magnitude
                });
            }
Пример #3
0
            protected override bool ContinuesInternal(RealTouchCommand last)
            {
                RealTouchVectorMovementCommand previous = (RealTouchVectorMovementCommand)last;

                if (previous.Direction != Direction)
                {
                    return(false);
                }
                if (Math.Abs((previous.TimeStamp + previous.Duration - TimeStamp).TotalMilliseconds) > 50)
                {
                    return(false);
                }
                if (Math.Abs(previous.Magnitude - Magnitude) > 10)
                {
                    return(false);
                }

                return(true);
            }