Ejemplo n.º 1
0
        public override void LoadFromXml(XmlElement element)
        {
            // base load first
            base.LoadFromXml(element);

            mSensorType = SensorType.Intermediate;
            try
            {
                mSensorType = (SensorType)int.Parse(element.GetAttribute(TAG_PRO_NODE_TYPE));
            }
            catch { }
            if (mSensorType == SensorType.Source)
            {
                initialState = true;
            }

            mSensorMode = SensorMode.Normal;
            try
            {
                mSensorMode = (SensorMode)int.Parse(element.GetAttribute(TAG_PRO_NODE_MODE));
            }
            catch { }

            try
            {
                _id = int.Parse(element.GetAttribute(TAG_PRO_NODE_ID));
            }
            catch { }

            //Hashtable _pros = TransitionCondition;
            //WSNUtil.LoadPNTranProperties(element, ref _pros);
        }
Ejemplo n.º 2
0
        //BME280 allows various modes. See chapter 3.5 "Recommended modes of operation" in the datasheet
        public async Task SetSampling(SensorMode mode, SensorSampling tempSampling, SensorSampling pressSampling,
                                      SensorSampling humSampling, SensorFilter filter, StandbyDuration duration)
        {
            Debug.WriteLine("BME280: Set sampling");
            _measReg.mode   = (uint)mode;
            _measReg.osrs_t = (uint)tempSampling;
            _measReg.osrs_p = (uint)pressSampling;


            _humReg.osrs_h    = (uint)humSampling;
            _configReg.filter = (uint)filter;
            _configReg.t_sb   = (uint)duration;


            // you must make sure to also set REGISTER_CONTROL after setting the
            // CONTROLHUMID register, otherwise the values won't be applied (see DS 5.4.3)
            byte[] WriteBuffer1 = new byte[] {
                (byte)eRegisters.BME280_REGISTER_CONTROLHUMID, (byte)_humReg.Get()
            };
            byte[] WriteBuffer2 = new byte[] {
                (byte)eRegisters.BME280_REGISTER_CONFIG, (byte)_configReg.Get()
            };
            byte[] WriteBuffer3 = new byte[] {
                (byte)eRegisters.BME280_REGISTER_CONTROL, (byte)_measReg.Get()
            };
            bme280.Write(WriteBuffer1);
            bme280.Write(WriteBuffer2);
            bme280.Write(WriteBuffer3);

            await Task.Delay(1);
        }
Ejemplo n.º 3
0
 private void EnableSkeletonRendering()
 {
     this.sensor.SkeletonStream.Enable();
     this.sensor.SkeletonStream.AppChoosesSkeletons = true;
     this.sensor.SkeletonFrameReady += new EventHandler <SkeletonFrameReadyEventArgs>(sensor_SkeletonFrameReadyForSkeletonRendering);
     this.sensorMode = SensorMode.SkeletonRendering;
 }
Ejemplo n.º 4
0
        public void GetSensorState(SensorPort port, out SensorType type, out SensorMode mode, out int raw, out int normalized, out int scaled)
        {
            mre.Reset();
            GetInputState(port);
            if (!mre.WaitOne(1000, false))
            {
                throw new NxtTimeout();
            }

            if (nError > 0)
            {
                throw new InvalidResult();
            }

            if (result[4] != 1)
            {
                throw new InvalidResult();
            }

            type       = (SensorType)result[6];
            mode       = (SensorMode)result[7];
            raw        = Buffer2Word(result, 8);
            normalized = Buffer2Word(result, 10);
            scaled     = Buffer2Word(result, 12);
        }
Ejemplo n.º 5
0
        public void SetNotificationMode(SensorMode mode, byte granularity = 1)
        {
            if (_mode == mode)
            {
                LoggerHelper.Instance.Debug("TiltSensor::SetMode no mode change");
                return;
            }

            if (_mode != SensorMode.NOT_SET)
            {
                if (!Subscribe((byte)_mode, granularity, false))
                {
                    LoggerHelper.Instance.Debug("TiltSensor::SetNotifications - failed to unsubscribe from notifications exception");
                    throw new Exception("Failed to unsubscribe from notifications");
                }
            }

            _mode = mode;

            if (!Subscribe((byte)_mode, granularity, true))
            {
                LoggerHelper.Instance.Debug("TiltSensor::SetNotificationMode - failed to subscribe to notifications");
                throw new Exception("Failed to subscribe to notifications");
            }

            LoggerHelper.Instance.Debug($"TiltSensor::SetNotificationMode mode = {mode}, granularity = {granularity}");
        }
Ejemplo n.º 6
0
        protected override void OnEnable()
        {
            base.OnEnable();
            previousDetectedObjects = new HashSet <GameObject>();
            triggerStayLag          = new Dictionary <Collider2D, int>();
            oldDetectionMode        = DetectionMode;
            oldRequiresLineOfSight  = RequiresLineOfSight;
            collidersToRemove       = new List <Collider2D>();
            collidersToIncrement    = new List <Collider2D>();

            if (!checkForTriggers())
            {
                Debug.LogWarning("Trigger Sensor cannot detect anything if there are no triggers on the same GameObject.", gameObject);
            }
            if (GetComponent <Rigidbody2D>() == null)
            {
                Debug.LogWarning("In order to detect GameObjects properly the TriggerSensor must itself have a RigidBody. Recommend adding a kinematic RigidBody.");
            }
            else if (GetComponent <Rigidbody2D>().sleepMode != RigidbodySleepMode2D.NeverSleep)
            {
                Debug.LogWarning("The rigidbody which owns the trigger collider should have its 'Sleeping Mode' parameter set to 'Never Sleep'");
            }

            StartCoroutine(LineOfSightRoutine());
        }
Ejemplo n.º 7
0
        // Use this for initialization
        void Start()
        {
            validateData    = new Regex("(-)*([0-9])+.([0-9])+");
            framerateFilter = new CircularList <float>(60);

            lastUpdate          = System.DateTime.Now;
            actualRotation      = Quaternion.identity;
            baselineRotation    = Quaternion.identity;
            invBaselineRotation = Quaternion.identity;
            lastRotation        = Quaternion.identity;

            headActualRotation      = Quaternion.identity;
            headBaselineRotation    = Quaternion.identity;
            headInvBaselineRotation = Quaternion.identity;

            //Icredibly enough the Unity orientation methods work OK in Japan
            Input.gyro.enabled    = true;
            orientationFilter     = new CircularList <Quaternion>(FilterSize);
            headOrientationFilter = new CircularList <Quaternion>(FilterSize);

            StartCoroutine(FPS());
            CommToAndroid.CallAndroidMethod("setGameObject", this.name);

            if (SystemInfo.deviceType == DeviceType.Handheld)
            {
                SensorMode currentSensor = (SensorMode)System.Enum.Parse(typeof(SensorMode), CommToAndroid.CallAndroidMethod <string>("getSensorMode"));
                if (currentSensor != SourceIMU)
                {
                    SetSourceIMU(SourceIMU);
                }
            }
        }
Ejemplo n.º 8
0
        protected string GetPNId(SensorType type, SensorMode mode)
        {
            string pnId = null;

            do
            {
                if (type < 0 || mode < 0)
                {
                    break;
                }

                switch (type)
                {
                case SensorType.Source:
                case SensorType.Sink:
                    pnId = type.ToString();
                    break;

                default:
                    pnId = mode.ToString();
                    break;
                } // switch
            } while (false);

            return(pnId);
        }
Ejemplo n.º 9
0
        public SmartKinectSensor(KinectSensor sensor)
        {
            this.sensor       = sensor;
            this.skeletonData = new Skeleton[this.sensor.SkeletonStream.FrameSkeletonArrayLength];

            this.skeletonController = new SkeletonController(this.sensor);
            this.sensorMode         = SensorMode.Disabled;
        }
Ejemplo n.º 10
0
        internal TiltSensor(IConnection connection, Ports port)
        {
            _connection = connection;
            _port       = port;
            _mode       = SensorMode.NOT_SET;

            LoggerHelper.Instance.Debug("TiltSensor constructor called");
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonoBrick.EV3.Sensor"/> class.
 /// </summary>
 /// <param name="mode">Mode to use.</param>
 public Sensor(SensorMode mode)
 {
     this.mode = mode;
     if (Connection != null && Connection.IsConnected)
     {
         Initialize();
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonoBrick.EV3.Sensor"/> class.
 /// </summary>
 public Sensor()
 {
     mode = SensorMode.Mode0;
     if (Connection != null && Connection.IsConnected)
     {
         Initialize();
     }
 }
Ejemplo n.º 13
0
        void Update()
        {
            // If one of these properties is changed at runtime then the list of DetectedObjects will be changed immediately. This code ensures
            // that the relevant sensor events are fired.
            if (oldDetectionMode != DetectionMode || oldRequiresLineOfSight != RequiresLineOfSight)
            {
                sensorDetectionEvents();
                oldDetectionMode       = DetectionMode;
                oldRequiresLineOfSight = RequiresLineOfSight;
            }

            // Increment triggerStayLag for each detected collider, if it is increased above a threshold this means its
            // no longer calling OnTriggerStay and should be removed from the list of detected colliders.
            collidersToRemove.Clear();
            collidersToIncrement.Clear();
            var colliderStayLagEnumerator = triggerStayLag.GetEnumerator();

            while (colliderStayLagEnumerator.MoveNext())
            {
                var c = colliderStayLagEnumerator.Current.Key;
                int currentCount;
                triggerStayLag.TryGetValue(c, out currentCount);
                if (currentCount >= 10)
                {
                    collidersToRemove.Add(c);
                }
                else
                {
                    collidersToIncrement.Add(c);
                }
            }

            for (int i = 0; i < collidersToRemove.Count; i++)
            {
                removeCollider(collidersToRemove[i]);
            }
            for (int i = 0; i < collidersToIncrement.Count; i++)
            {
                var c = collidersToIncrement[i];
                int currentCount;
                triggerStayLag.TryGetValue(c, out currentCount);
                triggerStayLag[c] = currentCount + 1;
            }

            if (RequiresLineOfSight && LineOfSightUpdateMode == UpdateMode.FixedInterval)
            {
                timer += Time.deltaTime;
                if (timer > CheckLineOfSightInterval)
                {
                    testSensor();
                    timer = 0f;
                }
            }
            else
            {
                timer = 0f;
            }
        }
Ejemplo n.º 14
0
        public SmartKinectSensor()
        {
            // RBakerFlag -> Need error handling for this.
            this.sensor       = KinectSensor.KinectSensors[0];
            this.skeletonData = new Skeleton[this.sensor.SkeletonStream.FrameSkeletonArrayLength];

            this.skeletonController = new SkeletonController(this.sensor);
            this.sensorMode         = SensorMode.Disabled;
        }
Ejemplo n.º 15
0
 private void EnableFullImageSkeletonRendering()
 {
     this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
     this.sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
     this.sensor.SkeletonStream.Enable();
     this.sensor.SkeletonStream.AppChoosesSkeletons = true;
     this.sensor.AllFramesReady += new EventHandler <AllFramesReadyEventArgs>(sensor_AllFramesReadyForFullImageSkeletonRendering);
     this.sensorMode             = SensorMode.FullImageSkeletonRendering;
 }
Ejemplo n.º 16
0
        public void SetSourceIMU(SensorMode imu)
        {
            SourceIMU = imu;
            if (SourceIMU != SensorMode.External)
            {
                CommToAndroid.CallAndroidMethod("setSensorMode", SourceIMU.ToString());
            }

            updateCount = 0;
            sensorChangedSetBaseline = false;
        }
Ejemplo n.º 17
0
        private void WakeSensor()
        {
            SendBytes(WAKECMD);

            _sensorOperationStatus = SensorOperationStatus.Active;
            _sensorMode            = SensorMode.Active;

            if (!_listening)
            {
                StartListening();
            }
        }
Ejemplo n.º 18
0
        public void SetInputMode(SensorPort nPort, SensorType nType, SensorMode nMode)
        {
            byte[] data = new byte[5];

            data[0] = 0x80;
            data[1] = 0x05;
            data[2] = (byte)nPort;
            data[3] = (byte)nType;
            data[4] = (byte)nMode;

            Tx(data);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 设置主传感器工作模式
        /// </summary>
        /// <param name="longAddress"></param>
        /// <param name="mode"></param>
        /// <param name="sensorCode"></param>
        /// <returns></returns>
        public bool WritePVSensorMode(long longAddress, SensorMode mode, SensorCode sensorCode)
        {
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1,
                Address     = longAddress,
                Command     = 0x84,
                DataContent = new byte[] { (byte)mode, (byte)sensorCode },
            };
            ResponsePacket response = Request(request);

            return(response != null);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Set sensor's type and mode.
        /// </summary>
        ///
        /// <param name="sensor">Sensor to set type of.</param>
        /// <param name="type">Sensor's type.</param>
        /// <param name="mode">Sensor's mode.</param>
        ///
        /// <returns>Returns <b>true</b> if command was executed successfully or <b>false</b> otherwise.</returns>
        ///
        public bool SetSensorMode(Sensor sensor, SensorType type, SensorMode mode)
        {
            byte[] command = new byte[5];

            // prepare message
            command[0] = (byte)NXTCommandType.DirectCommand;
            command[1] = (byte)NXTDirectCommand.SetInputMode;
            command[2] = (byte)sensor;
            command[3] = (byte)type;
            command[4] = (byte)mode;

            return(SendCommand(command, new byte[3]));
        }
 public LogicThreatSensor(Segment segment, Int64 x, Int64 y, Int64 z, UInt16 cubeType, Byte flags, UInt16 value)
     : base(segment, x, y, z, cubeType, flags, value)
 {
     // We'll remove this once we can safely serialize data and store the mode seperately
     if (TerrainData.mEntries[cubeType]?.GetValue(value)?.Key == "APlusMalware.LogicLasers.ThreatLevelSensor")
     {
         _mode = SensorMode.ThreatLevel;
     }
     else
     {
         _mode = SensorMode.Countdown;
     }
 }
Ejemplo n.º 22
0
        private void UpdateSensor()
        {
            // If one of these properties is changed at runtime then the list of DetectedObjects will be changed immediately. This code ensures
            // that the relevant sensor events are fired.
            if (_oldDetectionMode != DetectionMode || _oldRequiresLineOfSight != RequiresLineOfSight)
            {
                SensorDetectionEvents();
                _oldDetectionMode       = DetectionMode;
                _oldRequiresLineOfSight = RequiresLineOfSight;
            }

            // Increment triggerStayLag for each detected collider, if it is increased above a threshold this means its
            // no longer calling OnTriggerStay and should be removed from the list of detected colliders.
            _collidersToRemove.Clear();
            _collidersToIncrement.Clear();
            var colliderStayLagEnumerator = _triggerStayLag.Keys.GetEnumerator();

            try {
                while (colliderStayLagEnumerator.MoveNext())
                {
                    var c = colliderStayLagEnumerator.Current;
                    if (c == null)
                    {
                        continue;
                    }
                    _triggerStayLag.TryGetValue(c, out var currentCount);
                    if (currentCount >= 10)
                    {
                        _collidersToRemove.Add(c);
                    }
                    else
                    {
                        _collidersToIncrement.Add(c);
                    }
                }
            }
            finally {
                colliderStayLagEnumerator.Dispose();
            }

            for (int i = 0; i < _collidersToRemove.Count; i++)
            {
                RemoveCollider(_collidersToRemove[i]);
            }
            for (int i = 0; i < _collidersToIncrement.Count; i++)
            {
                var c = _collidersToIncrement[i];
                _triggerStayLag.TryGetValue(c, out var currentCount);
                _triggerStayLag[c] = currentCount + 1;
            }
        }
Ejemplo n.º 23
0
        void SynchSensorMode(string sensorMode)
        {
            SourceIMU = (SensorMode)System.Enum.Parse(typeof(SensorMode), sensorMode);;

            if (SystemInfo.deviceType != DeviceType.Handheld)
            {
                return;
            }

            if (SourceIMU != SensorMode.External)
            {
                CommToAndroid.CallAndroidMethod("setSensorMode", SourceIMU.ToString());
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Updates the sensor type and mode.
        /// </summary>
        /// <param name='sensorType'>
        /// Sensor type.
        /// </param>
        /// <param name='sensorMode'>
        /// Sensor mode.
        /// </param>
        protected void UpdateTypeAndMode(SensorType sensorType, SensorMode sensorMode)
        {
            Type = sensorType;
            Mode = sensorMode;
            var command = new Command(CommandType.DirecCommand, CommandByte.SetInputMode, true);

            command.Append((byte)port);
            command.Append((byte)Type);
            command.Append((byte)Mode);
            connection.Send(command);
            var reply = connection.Receive();

            Error.CheckForError(reply, 3);
        }
Ejemplo n.º 25
0
        private void HardWakeSensor()
        {
            if (_sleepGPIOPin != null)
            {
                _sensorOperationStatus = SensorOperationStatus.Active;
                _sensorMode            = SensorMode.Active;

                _sleepGPIOPin.Write(GpioPinValue.High);

                if (!_listening)
                {
                    StartListening();
                }
            }
        }
			/// <summary>
			/// Gets the sensor type and mode.
			/// </summary>
			/// <param name="type">Type.</param>
			/// <param name="mode">Mode.</param>
			protected void GetTypeAndMode(out SensorType type, out SensorMode mode){
				if(!isInitialized)
					Initialize();
				var command = new Command(2,0,200,true);
				command.Append(ByteCodes.InputDevice);
				command.Append(InputSubCodes.GetTypeMode);
				command.Append(this.DaisyChainLayer);
				command.Append(this.Port);
				
				command.Append((byte)0, VariableScope.Global);
				command.Append((byte)1, VariableScope.Global);
				var reply = Connection.SendAndReceive(command);
				Error.CheckForError(reply,200);
				type = (SensorType) reply.GetByte(3);
				mode = (SensorMode) reply.GetByte(4);
			}
Ejemplo n.º 27
0
        /// <summary>
        /// Sets the sensor mode
        /// </summary>
        /// <param name="mode">Mode to use.</param>
        protected virtual void SetMode(SensorMode mode)
        {
            isInitialized = true;
            this.mode     = mode;
            var command = new Command(4, 0, 123, true);

            command.Append(ByteCodes.InputReadSI);
            command.Append(this.DaisyChainLayer);
            command.Append(this.Port);
            command.Append(0, ConstantParameterType.Value);
            command.Append(mode);
            command.Append((byte)0, VariableScope.Global);
            var reply = Connection.SendAndReceive(command);

            Error.CheckForError(reply, 123);
        }
Ejemplo n.º 28
0
        private static void SensorDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            //!If serial port is not open, do not process.
            if (myPort.IsOpen == false)
            {
                return;
            }

            try
            {
                //! Read the received data.
                // string data = myPort.ReadExisting();
                var    numOfBytes  = myPort.BytesToRead;
                byte[] sensorsData = new byte[numOfBytes];
                myPort.Read(sensorsData, 0, numOfBytes);

                setSensorData(sensorsData);

                /*
                 * this.debug("Reception");
                 * foreach (var item in sensorsData)
                 * {
                 *  this.debug(item.ToString());
                 * }*/

                if (sensorDataHandler != null)
                {
                    sensorDataHandler(sensorData);
                }
            }
            catch (Exception ex)
            {
                debug("error");
            }

            flagReceive = true;

            if (sensorMode == SensorMode.BumpsAndWheelDrop)
            {
                sensorMode = SensorMode.LightBumper;
            }
            else
            {
                sensorMode = SensorMode.BumpsAndWheelDrop;
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 设置主传感器工作模式
        /// </summary>
        /// <param name="longAddress"></param>
        /// <param name="mode"></param>
        /// <param name="sensorCode"></param>
        /// <returns></returns>
        public bool WritePVSensorMode(SensorMode mode, SensorCode sensorCode)
        {
            if (_ID == null)
            {
                return(false);
            }
            bool ret = _HartComport.WritePVSensorMode(_ID.LongAddress, mode, sensorCode);

            if (ret)
            {
                _SensorMode = null;
                _SensorCode = null;
                _PVOutput   = null;
                _PVSensor   = null;
            }
            return(ret);
        }
Ejemplo n.º 30
0
        protected override void OnEnable()
        {
            base.OnEnable();
            previousDetectedObjects.Clear();
            isColliderStale.Clear();
            oldDetectionMode       = DetectionMode;
            oldRequiresLineOfSight = RequiresLineOfSight;

            if (!checkForTriggers())
            {
                Debug.LogWarning("Trigger Sensor cannot detect anything if there are no triggers on the same GameObject.", gameObject);
            }
            if (DetectionMode == SensorMode.Colliders && GetComponent <Rigidbody>() == null)
            {
                Debug.LogWarning("In order to detect GameObjects without RigidBodies the TriggerSensor must itself have a RigidBody. Recommend adding a kinematic RigidBody.");
            }
        }
Ejemplo n.º 31
0
 protected override void OnEnable()
 {
     base.OnEnable();
     _previousDetectedObjects = new HashSet <GameObject>();
     _triggerStayLag          = new Dictionary <Collider, int>();
     _oldDetectionMode        = DetectionMode;
     _oldRequiresLineOfSight  = RequiresLineOfSight;
     _collidersToRemove       = new List <Collider>();
     _collidersToIncrement    = new List <Collider>();
     if (!CheckForTriggers())
     {
         Debug.LogWarning("Trigger Sensor cannot detect anything if there are no triggers on the same GameObject.", gameObject);
     }
     if (DetectionMode == SensorMode.Colliders && GetComponent <Rigidbody>() == null)
     {
         Debug.LogWarning("In order to detect GameObjects without RigidBodies the TriggerSensor must itself have a RigidBody. Recommend adding a kinematic RigidBody.");
     }
     //StartCoroutine(LineOfSightRoutine());
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.NXTColorSensor"/> class as a light sensor.
		/// </summary>
		public NXTColorSensor(SensorMode mode) : base ((SensorType)ColorMode.Red,mode){
			
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.NXTColorSensor"/> class.
		/// </summary>
		/// <param name="colorMode">The color mode to use</param>
		/// <param name="mode">The sensor mode to use</param>
		public NXTColorSensor(ColorMode colorMode, SensorMode mode) : base ((SensorType)colorMode,mode){
			
		}
Ejemplo n.º 34
0
        public bool Set(SensorType type, SensorMode mode)
        {
            this.type = type;
            this.mode = mode;

            if (type == SensorType.Sonar)
                type = SensorType.LowSpeed9V;

            byte[] command = new byte[5];
            command[0] = 0x00;
            command[1] = (byte)DirectCommand.SetInputMode;
            command[2] = port;
            command[3] = (byte)type;
            command[4] = (byte)mode;
            return serial_port.Send(command);
        }
			/// <summary>
			/// Sets the sensor mode
			/// </summary>
			/// <param name="mode">Mode to use.</param>
			protected virtual void SetMode(SensorMode mode){
				isInitialized = true;
				this.mode = mode;
				var command = new Command(4,0, 123, true);
				command.Append(ByteCodes.InputReadSI);
				command.Append(this.DaisyChainLayer);
				command.Append(this.Port);
				command.Append(0, ConstantParameterType.Value);
				command.Append(mode);
				command.Append((byte)0, VariableScope.Global);
				var reply = Connection.SendAndReceive(command);
				Error.CheckForError(reply,123);
			}
			/// <summary>
			/// Initializes a new instance of the <see cref="MonoBrick.EV3.Sensor"/> class.
			/// </summary>
			/// <param name="mode">Mode to use.</param>
			public Sensor (SensorMode mode)
			{
				this.mode = mode;
				if(Connection != null && Connection.IsConnected)
					Initialize();	
			}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.CustomSensor"/> class.
		/// </summary>
		/// <param name='type'>
		/// Sensor type
		/// </param>
		/// <param name='mode'>
		/// Sensor mode
		/// </param>
		public CustomSensor(SensorType type, SensorMode mode): base (type, mode) { 
			
		}
		internal async Task SetInputModeAsyncInternal(SensorPort sensorPort, SensorType sensorType, SensorMode sensorMode)
		{
			await brick.SendCommandAsyncInternal(RequestTelegram.SetInputMode(sensorPort, sensorType, sensorMode));
		}
Ejemplo n.º 39
0
 /// <summary>
 /// Set sensor's mode.
 /// </summary>
 /// 
 /// <param name="sensor">Sensor to set mode of.</param>
 /// <param name="mode">Sensor mode to set.</param>
 /// 
 /// <returns>Returns <b>true</b> if command was executed successfully or <b>false</b> otherwise.</returns>
 /// 
 public bool SetSensorMode( Sensor sensor, SensorMode mode )
 {
     return SendCommand( new byte[] { (byte) RCXCommand.SetSensorMore,
         (byte) sensor, (byte) ( (byte) mode << 5 ) }, new byte[1], 1 );
 }
		/// <summary>
		/// Append a sensor mode value
		/// </summary>
		/// <param name="mode">Sensor mode to append</param>
		public void Append (SensorMode mode)
		{
			Append((byte) mode, ParameterFormat.Short);
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.RCXLightSensor"/> class.
		/// </summary>
		/// <param name='sensorMode'>
		/// Sensor mode. Raw, bool, percent...
		/// </param>
		public RCXLightSensor(SensorMode sensorMode) : base(SensorType.Reflection, sensorMode) {}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.NXTLightSensor"/> class.
		/// </summary>
		/// <param name='lightMode'>
		/// Light sensor mode
		/// </param>
		/// <param name='sensorMode'>
		/// Sensor mode. Raw, bool, percent...
		/// </param>
		public NXTLightSensor(LightMode lightMode, SensorMode sensorMode) : base ((SensorType)lightMode, sensorMode){
        
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.TouchSensor"/> class.
		/// </summary>
		/// <param name='sensorMode'>
		/// Sensor mode. Raw, bool, percent...
		/// </param>
		public TouchSensor(SensorMode sensorMode) : base(SensorType.Touch, sensorMode) { }
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.Sensor"/> class.
		/// </summary>
		/// <param name='sensorType'>
		/// Sensor type
		/// </param>
		/// <param name='sensorMode'>
		/// Sensor mode
		/// </param>
		public Sensor(SensorType sensorType, SensorMode sensorMode)
        {
            Mode = sensorMode;
            Type = sensorType;
        }
			/// <summary>
			/// Get device mode name
			/// </summary>
			/// <returns>The device mode name.</returns>
			/// <param name="mode">Mode to get name of.</param>
			protected string GetModeName (SensorMode mode)
			{
				if(!isInitialized)
					Initialize();
				var command = new Command(Command.ShortValueMax,0,201,true);
				command.Append(ByteCodes.InputDevice);
				command.Append(InputSubCodes.GetModeName);
				command.Append(this.DaisyChainLayer);
				command.Append(this.Port);
				command.Append((byte) mode, ConstantParameterType.Value); 
				
				command.Append(Command.ShortValueMax, ConstantParameterType.Value); 
				command.Append((byte)0, VariableScope.Global);
				var reply = Connection.SendAndReceive(command);
				Error.CheckForError(reply,201);
				return reply.GetString(3,(byte) Command.ShortValueMax);
			}
Ejemplo n.º 46
0
        public void GetSensorState(SensorPort port, out SensorType type, out SensorMode mode, out int raw, out int normalized, out int scaled)
        {
            mre.Reset();
            GetInputState(port);
            if (!mre.WaitOne(1000, false))
                throw new NxtTimeout();

            if (nError > 0)
                throw new InvalidResult();

            if (result[4] != 1)
                throw new InvalidResult();

            type = (SensorType)result[6];
            mode = (SensorMode)result[7];
            raw = Buffer2Word(result, 8);
            normalized = Buffer2Word(result, 10);
            scaled = Buffer2Word(result, 12);
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Set sensor's type and mode.
        /// </summary>
        /// 
        /// <param name="sensor">Sensor to set type of.</param>
        /// <param name="type">Sensor's type.</param>
        /// <param name="mode">Sensor's mode.</param>
        /// <param name="waitReply">Wait reply from NXT (safer option) or not (faster option).</param>
        /// 
        /// <returns>Returns <b>true</b> if command was executed successfully or <b>false</b> otherwise.</returns>
        /// 
        public bool SetSensorMode( Sensor sensor, SensorType type, SensorMode mode, bool waitReply )
        {
            byte[] command = new byte[5];

            // prepare message
            command[0] = (byte) ( ( waitReply ) ? NXTCommandType.DirectCommand : NXTCommandType.DirectCommandWithoutReply );
            command[1] = (byte) NXTDirectCommand.SetInputMode;
            command[2] = (byte) sensor;
            command[3] = (byte) type;
            command[4] = (byte) mode;

            return SendCommand( command, new byte[3] );
        }
Ejemplo n.º 48
0
        public void SetInputMode(SensorPort nPort, SensorType nType, SensorMode nMode)
        {
            byte[] data = new byte[5];

            data[0] = 0x80;
            data[1] = 0x05;
            data[2] = (byte)nPort;
            data[3] = (byte)nType;
            data[4] = (byte)nMode;

            Tx(data);
        }
Ejemplo n.º 49
0
		internal SensorBase(SensorType sensorType, SensorMode sensorMode)
		{
			this.sensorMode = sensorMode;
			this.sensorType = sensorType;
		}
		/// <summary>
		/// Updates the sensor type and mode.
		/// </summary>
		/// <param name='sensorType'>
		/// Sensor type.
		/// </param>
		/// <param name='sensorMode'>
		/// Sensor mode.
		/// </param>
		protected void UpdateTypeAndMode(SensorType sensorType, SensorMode sensorMode){
			Type = sensorType;
			Mode = sensorMode;
			var command = new Command(CommandType.DirecCommand, CommandByte.SetInputMode, true);
            command.Append((byte)port);
            command.Append((byte)Type);
            command.Append((byte)Mode);
            connection.Send(command);
            var reply = connection.Receive();
            Error.CheckForError(reply, 3);
        }
Ejemplo n.º 51
0
        /// <summary>
        /// [Native] Set a sensor's state.  This is REQUIRED
        ///  to read realistic values through GetSensorValues().
        /// </summary>
        /// <param name="port">The port of the attached sensor.</param>
        /// <param name="type">The type of the attached sensor.</param>
        /// <param name="mode">The mode of the attached sensor.</param>
        public void SetSensorMode(SensorPort port,
            SensorType type, SensorMode mode)
        {
            byte[] request = new byte[] {
            (byte) (0x00),
            (byte) (DirectCommand.SetInputMode),
            (byte) port,
            (byte) type,
            (byte) mode
            };

            CompleteRequest(request);
            return;
        }
Ejemplo n.º 52
0
 /// <summary>
 /// Set sensor's type and mode.
 /// </summary>
 /// 
 /// <param name="sensor">Sensor to set type of.</param>
 /// <param name="type">Sensor's type.</param>
 /// <param name="mode">Sensor's mode.</param>
 /// 
 /// <returns>Returns <b>true</b> if command was executed successfully or <b>false</b> otherwise.</returns>
 /// 
 public bool SetSensorMode( Sensor sensor, SensorType type, SensorMode mode )
 {
     return SetSensorMode( sensor, type, mode, true );
 }
			/// <summary>
			/// Initializes a new instance of the <see cref="MonoBrick.EV3.Sensor"/> class.
			/// </summary>
			public Sensor ()
			{	
				mode = SensorMode.Mode0;
				if(Connection != null && Connection.IsConnected)
					Initialize();				
			}
		/// <summary>
		/// Set the sensor to be used as a light sensor
		/// </summary>
		public void UseAsLightSensor(SensorMode mode = SensorMode.Percent){
			UpdateTypeAndMode(SensorType.ColorRed,mode);
		}
Ejemplo n.º 55
0
		SetInputModeAsync(SensorPort sensorPort, SensorType sensorType, SensorMode sensorMode)
		{
			return SetInputModeAsyncInternal(sensorPort, sensorType, sensorMode)
#if WINRT
			.AsAsyncAction()
#endif
			;
		}