Example #1
0
        public ArduinoModel(TeamDataModel teamData1, TeamDataModel teamData2)
        {
            SetConnection();
            if (_comOK)
            {
                _session        = new ArduinoSession(_connection);
                _keepAliveTimer = new Timer(Constants.keepAliveInterval)
                {
                    AutoReset = true
                };
                _keepAliveTimer.Elapsed += _keepAliveTimer_Elapsed;
                _keepAliveTimer.Start();
                //_session.SetSamplingInterval(400);
                _session.SetDigitalPinMode(Constants.rlimb, PinMode.InputPullup);
                _session.SetDigitalPinMode(Constants.rlimf, PinMode.InputPullup);
                _session.SetDigitalPinMode(Constants.blimb, PinMode.InputPullup);
                _session.SetDigitalPinMode(Constants.blimf, PinMode.InputPullup);
                _session.SetDigitalReportMode(Constants.limitSwitchPort, true);
                var tracker = _session.CreateDigitalStateMonitor(Constants.limitSwitchPort);
                teamData1.TeamControl.BackLimSwitch.Subscribe(tracker);
                teamData1.TeamControl.FrontLimSwitch.Subscribe(tracker);
                teamData2.TeamControl.BackLimSwitch.Subscribe(tracker);
                teamData2.TeamControl.FrontLimSwitch.Subscribe(tracker);

                //use code below to enable event managed pin updates

                //_session.DigitalStateReceived += DigitalStateReceivedHandler;
            }

            //Subscribe to controllable data changes
            //Planned: publish sensor updates using TeamSensor object in teamData
            _teamData1 = teamData1;
            _teamData1.TeamControl.HoverLed.PropertyChanged     += OnLedChanged;
            _teamData1.TeamControl.Obstacle1Led.PropertyChanged += OnLedChanged;
            _teamData1.TeamControl.Obstacle2Led.PropertyChanged += OnLedChanged;
            _teamData1.TeamControl.Platform1Led.PropertyChanged += OnLedChanged;
            _teamData1.TeamControl.Platform2Led.PropertyChanged += OnLedChanged;
            _teamData1.TeamControl.StartLed.PropertyChanged     += OnLedChanged;
            _teamData1.TeamControl.Motor.PropertyChanged        += OnMotorChanged;

            _teamData2 = teamData2;
            _teamData2.TeamControl.HoverLed.PropertyChanged     += OnLedChanged;
            _teamData2.TeamControl.Obstacle1Led.PropertyChanged += OnLedChanged;
            _teamData2.TeamControl.Obstacle2Led.PropertyChanged += OnLedChanged;
            _teamData2.TeamControl.Platform1Led.PropertyChanged += OnLedChanged;
            _teamData2.TeamControl.Platform2Led.PropertyChanged += OnLedChanged;
            _teamData2.TeamControl.StartLed.PropertyChanged     += OnLedChanged;
            _teamData2.TeamControl.Motor.PropertyChanged        += OnMotorChanged;
        }