Beispiel #1
0
        private BrickSensorType GetEV3Mode(ColorSensorMode mode)
        {
            BrickSensorType ret = BrickSensorType.EV3_COLOR_M0;

            switch (mode)
            {
            //question is about the various modes and if theyr are supported and how
            case ColorSensorMode.Color:
                ret = BrickSensorType.EV3_COLOR_M2;
                break;

            case ColorSensorMode.Reflection:
                ret = BrickSensorType.EV3_COLOR_M0;
                break;

            case ColorSensorMode.Green:
                ret = BrickSensorType.EV3_COLOR_M3;
                break;

            case ColorSensorMode.Blue:
                ret = BrickSensorType.EV3_COLOR_M4;
                break;

            case ColorSensorMode.Ambient:
                ret = BrickSensorType.EV3_COLOR_M1;
                break;
            }
            return(ret);
        }
Beispiel #2
0
        private SensorType GetEV3Mode(ColorSensorMode mode)
        {
            SensorType ret = SensorType.EV3ColorReflected;

            switch (mode)
            {
            case ColorSensorMode.Color:
                ret = SensorType.EV3ColorColor;
                break;

            case ColorSensorMode.Reflection:
                ret = SensorType.EV3ColorReflected;
                break;

            case ColorSensorMode.Green:
                ret = SensorType.EV3ColorRawReflected;
                break;

            case ColorSensorMode.Blue:
                ret = SensorType.EV3ColorColorComponents;
                break;

            case ColorSensorMode.Ambient:
                ret = SensorType.EV3ColorAmbient;
                break;
            }
            return(ret);
        }
Beispiel #3
0
        private SENSOR_TYPE GetEV3Mode(ColorSensorMode mode)
        {
            SENSOR_TYPE ret = SENSOR_TYPE.EV3_COLOR_REFLECTED; //.EV3_COLOR_M0;

            switch (mode)
            {
            //question is about the various modes and if theyr are supported and how
            case ColorSensorMode.Color:
                ret = SENSOR_TYPE.EV3_COLOR_COLOR;     //BrickSensorType.EV3_COLOR_M2;
                break;

            case ColorSensorMode.Reflection:
                ret = SENSOR_TYPE.EV3_COLOR_REFLECTED;     //BrickSensorType.EV3_COLOR_M0;
                break;

            case ColorSensorMode.Green:
                ret = SENSOR_TYPE.EV3_COLOR_RAW_REFLECTED;     //BrickSensorType.EV3_COLOR_M3;
                break;

            case ColorSensorMode.Blue:
                ret = SENSOR_TYPE.EV3_COLOR_COLOR_COMPONENTS;     //BrickSensorType.EV3_COLOR_M4;
                break;

            case ColorSensorMode.Ambient:
                ret = SENSOR_TYPE.EV3_COLOR_AMBIENT;     //BrickSensorType.EV3_COLOR_M1;
                break;
            }
            return(ret);
        }
		internal async Task SetSensorModeAsyncInternal(ColorSensorMode mode, SensorColor color = SensorColor.Black)
		{
			switch (mode)
			{
				case ColorSensorMode.ColorDetector:
				case ColorSensorMode.Lamp:
					this.sensorType = SensorType.ColorFull;
					break;
				case ColorSensorMode.LightSensor:
					switch (color)
					{
						case SensorColor.Red:
							this.sensorType = SensorType.ColorRed;
							break;
						case SensorColor.Green:
							this.sensorType = SensorType.ColorGreen;
							break;
						case SensorColor.Blue:
							this.sensorType = SensorType.ColorBlue;
							break;
						default:
							this.sensorType = SensorType.ColorNone;
							break;
					}
					break;
			}
			this.colorSensorMode = mode;
			await base.Initialize();
		}
		SetSensorModeAsync(ColorSensorMode mode, SensorColor color)
		{
			return this.SetSensorModeAsyncInternal(mode, color)
#if WINRT
			.AsAsyncAction()
#endif
			;
		}
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public NXTColorSensor(BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     brick     = new Brick();
     Port      = port;
     colorMode = mode;
     brick.BrickPi.Sensor[(int)Port].Type = (BrickSensorType)mode;
     periodRefresh = timeout;
     timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #7
0
 /// <summary>
 /// Initilaize an EV3 Color Sensor
 /// </summary>
 /// <param name="brick"></param>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3ColorSensor(Brick brick, SensorPort port, ColorSensorMode mode, int timeout)
 {
     _brick     = brick;
     Port       = port;
     _colorMode = mode;
     brick.SetSensorType((byte)Port, GetEV3Mode(mode));
     _periodRefresh = timeout;
     _timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #8
0
 /// <summary>
 /// Initilaize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3ColorSensor(BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     brick     = new Brick();
     Port      = port;
     colorMode = mode;
     //set the correct mode
     brick.BrickPi.Sensor[(int)Port].Type = GetEV3Mode(mode);
     periodRefresh = timeout;
     timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #9
0
 /// <summary>
 /// Initilaize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3ColorSensor(BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     brick = new Brick();
     Port = port;
     colorMode = mode;
     //set the correct mode
     brick.BrickPi.Sensor[(int)Port].Type = GetEV3Mode(mode);
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #10
0
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public NXTColorSensor(Brick brick, BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     this.brick = brick;
     Port       = port;
     colorMode  = mode;
     //brick.BrickPi.Sensor[(int)Port].Type = (BrickSensorType)mode;
     brick.set_sensor_type((byte)Port, (SENSOR_TYPE)mode);
     periodRefresh = timeout;
     timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #11
0
 /// <summary>
 /// Initilaize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public EV3ColorSensor(Brick brick, BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     this.brick = brick;
     Port       = port;
     colorMode  = mode;
     //set the correct mode
     //brick.BrickPi.Sensor[(int)Port].Type = GetEV3Mode(mode);
     brick.set_sensor_type((byte)Port, GetEV3Mode(mode));
     periodRefresh = timeout;
     timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
        protected override void Start()
        {
            base.Start();

            mode = ColorSensorMode.None;

            var gamepadNotify = new GameControllerOperations();
            _gamepadPort.Subscribe(gamepadNotify);
            Activate(Arbiter.Receive<UpdateAxes>(true, gamepadNotify, GamePadAxisUpdated));
            Activate(Arbiter.Receive<UpdateButtons>(true, gamepadNotify, ButtonUpdateHandler));
        }
 /// <summary>
 /// Request the Mode to be changed.
 /// </summary>
 /// <param name="mode">Sensor mode - See ColorSensorMode enum.</param>
 public ModeRequest(ColorSensorMode mode)
 {
     this.Mode = mode;
 }
		public ColorSensor() :
			base(SensorType.ColorFull, SensorMode.Raw)
		{
			this.colorSensorMode = ColorSensorMode.ColorDetector;
			colorMatch = new SortedSet<SensorColor>();
		}
Beispiel #15
0
 /// <summary>
 /// Initialize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 public EV3ColorSensor(BrickPortSensor port, ColorSensorMode mode)
     : this(port, mode, 1000)
 {
 }
Beispiel #16
0
 private BrickSensorType GetEV3Mode(ColorSensorMode mode)
 {
     BrickSensorType ret = BrickSensorType.EV3_COLOR_M0;
     switch (mode)
     {
         //question is about the various modes and if theyr are supported and how
         case ColorSensorMode.Color:
             ret = BrickSensorType.EV3_COLOR_M2;
             break;
         case ColorSensorMode.Reflection:
             ret = BrickSensorType.EV3_COLOR_M0;
             break;
         case ColorSensorMode.Green:
             ret = BrickSensorType.EV3_COLOR_M3;
             break;
         case ColorSensorMode.Blue:
             ret = BrickSensorType.EV3_COLOR_M4;
             break;
         case ColorSensorMode.Ambient:
             ret = BrickSensorType.EV3_COLOR_M1;
             break;
     }
     return ret;
 }
Beispiel #17
0
 public void SelectPreviousMode()
 {
     colorMode = ColorMode.Previous();
     return;
 }
Beispiel #18
0
 public void SelectNextMode()
 {
     colorMode = ColorMode.Next();
     return;
 }
Beispiel #19
0
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 /// <param name="timeout">Period in millisecond to check sensor value changes</param>
 public NXTColorSensor(BrickPortSensor port, ColorSensorMode mode, int timeout)
 {
     brick = new Brick();
     Port = port;
     colorMode = mode;
     brick.BrickPi.Sensor[(int)Port].Type = (BrickSensorType)mode;
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Beispiel #20
0
 /// <summary>
 /// Initialize an EV3 Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 public EV3ColorSensor(BrickPortSensor port, ColorSensorMode mode) : this(port, mode, 1000)
 {
 }
Beispiel #21
0
 public void SelectPreviousMode()
 {
     colorMode = ColorMode.Previous();
     return;
 }
Beispiel #22
0
 /// <summary>
 /// Moves to previous mode
 /// </summary>
 public void SelectPreviousMode()
 {
     _colorMode = ColorMode.Previous();
 }
 /// <summary>
 /// Set the LEGO Color Sensor Mode.
 /// </summary>
 /// <param name="mode">Sensor mode - Select from ColorSensorMode enum</param>
 public SetMode(ColorSensorMode mode)
 {
     base.Body = new ModeRequest(mode);
 }
Beispiel #24
0
 /// <summary>
 /// Initialize a NXT Color Sensor
 /// </summary>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 public NXTColorSensor(Brick brick, BrickPortSensor port, ColorSensorMode mode) : this(brick, port, mode, 1000)
 {
 }
Beispiel #25
0
 /// <summary>
 /// constructs a LEGO® MINDSTORMS® EV3 Color Sensor
 /// </summary>
 public ColorSensor(ColorSensorMode mode)
     : base(DeviceType.ColorSensor)
 {
     Mode  = mode;
     Value = new ColorSensorValue(ColorSensorColor.None, Mode);
 }
Beispiel #26
0
 private SensorType GetEV3Mode(ColorSensorMode mode) => mode switch
 {
Beispiel #27
0
 /// <summary>
 /// Moves to next mode
 /// </summary>
 public void SelectNextMode()
 {
     _colorMode = ColorMode.Next();
 }
Beispiel #28
0
 /// <summary>
 /// Initialize an EV3 Color Sensor
 /// </summary>
 /// <param name="brick"></param>
 /// <param name="port">Sensor port</param>
 /// <param name="mode">Color mode</param>
 public EV3ColorSensor(Brick brick, SensorPort port, ColorSensorMode mode) : this(brick, port, mode, 1000)
 {
 }
Beispiel #29
0
 internal ColorSensorValue(int value, ColorSensorMode mode)
 {
     Mode  = mode;
     Color = ColorSensorColor.None;
     Value = value;
 }
 private void setColorSensorState(ColorSensorState state)
 {
     switch (state.SensorMode)
     {
         case ColorSensorMode.Blue:
             mode = ColorSensorMode.Red;
             break;
         case ColorSensorMode.Red:
             mode = ColorSensorMode.Green;
             break;
         case ColorSensorMode.Green:
             mode = ColorSensorMode.Blue;
             break;
         default:
             mode = ColorSensorMode.Green;
             break;
     }
 }
Beispiel #31
0
 public void SelectNextMode()
 {
     colorMode = ColorMode.Next();
     return;
 }
Beispiel #32
0
 internal ColorSensorValue(ColorSensorColor color, ColorSensorMode mode)
 {
     Mode  = mode;
     Color = color;
     Value = (int)color;
 }