public static void ParseResponse(string response, IArduinoService caller)
        {
            string[] data;
            switch (response[0])
            {
            case '0':
                data = response.Split(':');

                int lane = int.Parse(data[0]);
                int time = int.Parse(data[1]);
                caller.OnUpdateTimes(lane, time);
                break;

            case 'S':
                caller.OnSessionStarted();
                break;

            case 'L':
                caller.OnLaneSet();
                break;

            case 'M':
                data = response.Split(':');
                int minTime = int.Parse(data[1]);
                caller.OnMinTimeSet(minTime);
                break;

            case 'P':
                caller.OnRelaySet();
                break;
            }
        }
        public TrackConnectionViewModel()
        {
            _trackConnection = new TrackConnection();
            _arduinoService  = Container.Resolve <IArduinoService>();

            ConnectToTrackCommand = new ConnectToTrackCommand(this);
            AddLaneCommand        = new AddLaneCommand(this);
            RemoveLaneCommand     = new RemoveLaneCommand(this);
        }
        public FreePracticeViewModel()
        {
            _freePractice   = new FreePractice();
            _arduinoService = Container.Resolve <IArduinoService>();

            EndFreePracticeCommand = new EndFreePracticeCommand(this);

            _arduinoService.UpdateTimes += OnUpdateTimes;

            _arduinoService.StartSession();
        }
示例#4
0
        public RaceViewModel()
        {
            _application    = Container.Resolve <Application>();
            _race           = Container.Resolve <Race>();
            _arduinoService = Container.Resolve <IArduinoService>();

            StartResumeRaceCommand = new StartResumeRaceCommand(this);
            TrackCallCommand       = new TrackCallCommand(this);
            GoToResultsCommand     = new GoToResultsCommand(this);

            CurrentGroup = "A";
            CurrentHeat  = 1;
            TimeLeft     = _race.WarmUpTime;

            _raceTimer          = new DispatcherTimer();
            _raceTimer.Tick    += RaceTimerTick;
            _raceTimer.Interval = TimeSpan.FromSeconds(1);

            for (var i = 0; i < _race.Racers.Count; i++)
            {
                _race.Racers[i].Position = i + 1;
            }

            _groupedRacers = _race.Racers
                             .Select((x, i) => new { Index = i, Value = x })
                             .GroupBy(x => x.Index / _application.LanesSet)
                             .Select((x, i) => new { Index = i, Value = x.Select(v => v.Value).ToList() })
                             .ToDictionary(x => groupLabels[x.Index], x => x.Value);

            changeSequence = laneSequences[_application.LanesSet];

            for (var i = 0; i < CurrentRacers.Count; i++)
            {
                CurrentRacers[i].CurrentLane = changeSequence[i];
            }

            _arduinoService.UpdateTimes += OnUpdateTimes;

            WarmUpSession = true;
            LaneChange    = false;
        }
示例#5
0
        public static void SetLane(int lane, int pin, IArduinoService caller)
        {
            string command = $"!{(int)TrackCommands.SetLane:00}{pin:00}{lane:00}.";

            caller.Write(command);
        }
示例#6
0
        public static void StopSession(IArduinoService caller)
        {
            string command = $"!{(int)TrackCommands.StopSession:00}.";

            caller.Write(command);
        }
示例#7
0
        public static void SetRelay(int relayPin, IArduinoService caller)
        {
            string command = $"!{(int) TrackCommands.SetRelay:00}{relayPin:00}.";

            caller.Write(command);
        }
示例#8
0
        public static void SetMinTime(int minTime, IArduinoService caller)
        {
            string command = $"!{(int) TrackCommands.SetMinTime:00}{minTime:0000}.";

            caller.Write(command);
        }