コード例 #1
0
ファイル: LegoNXTEncoder.cs プロジェクト: yingted/Myro
        /// <summary>
        /// Handle sensor update message from NXT
        /// </summary>
        public void SensorNotificationHandler(legoNXT.Configure notify)
        {
            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }

            //update time
            _state.TimeStamp = DateTime.Now;

            int newReading = notify.Body.MotorSensorPort[_state.HardwareIdentifier - 1];

            //increment counter (and account for any missing ticks
            if (Math.Abs(newReading - _state.CurrentReading) <= 3)
            {
                _state.TicksSinceReset += Math.Abs(newReading - _state.CurrentReading);
            }
            else
            {
                _state.TicksSinceReset++;
            }

            //Update angle
            _state.CurrentReading = newReading;

            //notify subscribers on any state change
            encoder.UpdateTickCount updateHeader = new encoder.UpdateTickCount(new encoder.UpdateTickCountRequest(DateTime.Now, _state.TicksSinceReset));
            SendNotification <encoder.UpdateTickCount>(_subMgrPort, updateHeader);
        }
コード例 #2
0
ファイル: LegoNXTContactSensor.cs プロジェクト: yingted/Myro
        /// <summary>
        /// Handle sensor update message from NXT
        /// </summary>
        private void SensorNotificationHandler(nxt.Configure notify)
        {
            //update state
            foreach (bumper.ContactSensor sensor in _bumperConfigState.ContactSensorArrayState.Sensors)
            {
                bool newContactValue;
                LegoNxtBumperConfig bumperConfig = GetBumperConfig(sensor.HardwareIdentifier);
                if (bumperConfig == null)
                {
                    // Old logic works only for touch sensor
                    newContactValue = (notify.Body.SensorPort[sensor.HardwareIdentifier - 1] == 1) ? true : false;
                }
                else
                {
                    newContactValue = ((notify.Body.SensorPort[sensor.HardwareIdentifier - 1] >= bumperConfig.ThresholdLow) &&
                                       (notify.Body.SensorPort[sensor.HardwareIdentifier - 1] <= bumperConfig.ThresholdHigh));
                }

                bool changed = (sensor.Pressed != newContactValue);
                sensor.TimeStamp = DateTime.Now;
                sensor.Pressed   = newContactValue;

                if (changed)
                {
                    //notify subscribers on any bumper pressed or unpressed
                    SendNotification <bumper.Update>(_subMgrPort, sensor);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Handle sensor update message from NXT
        /// </summary>
        public void SensorNotificationHandler(legoNXT.Configure notify)
        {
            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }

            //update time
            _state.TimeStamp = DateTime.Now;

            //Update reading
            _state.SoundReading = notify.Body.SensorPort[_state.HardwareIdentifier - 1];

            //notify subscribers on any state change
            SendNotification <Replace>(_subMgrPort, new Replace(_state));
        }
コード例 #4
0
        /// <summary>
        /// Handle sensor update message from NXT
        /// </summary>
        public void SensorNotificationHandler(legoNXT.Configure notify)
        {
            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }

            if (beeping)
            {
                return;
            }

            if (notify.Body.MotorOutputPort[_state.Motor1Port - 1] < 0 &&
                notify.Body.MotorOutputPort[_state.Motor2Port - 1] < 0)
            {
                SpawnIterator(ToneHandler);
            }
        }