Main EV3 brick interface
コード例 #1
0
		private void TryToConnect(object sender, RoutedEventArgs e)
		{
			Overlay.Show("Connecting");

			ConnControl.Visibility = Visibility.Visible;

			var conType = CreateConnection();

			Dispatcher.Invoke(new Action(async () =>
			{
				if (conType != null)
				{
					_brick = new Brick(conType, true);
					_brick.BrickChanged += _brick_BrickChanged;
					try
					{
						await _brick.ConnectAsync();
						ConnControl.Visibility = Visibility.Collapsed;

						ConnTypeRun.Text = ConnControl.GetConnectionType().ToString();

					}
					catch (Exception)
					{
						MessageBox.Show("Could not connect", "Error", MessageBoxButton.OK);
					}
				}
				else
				{
					MessageBox.Show("Invalid connection type for this device", "Error", MessageBoxButton.OK);
				}

				Overlay.Hide();
			}));
		}
コード例 #2
0
ファイル: Activity1.cs プロジェクト: BananaScheriff/legoev3
		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Main);

			_output = FindViewById<TextView>(Resource.Id.output);
			_ports = FindViewById<TextView>(Resource.Id.ports);

			FindViewById<Button>(Resource.Id.connect).Click += connect_Click;
			FindViewById<Button>(Resource.Id.disconnect).Click += disconnect_Click;
			FindViewById<Button>(Resource.Id.playTone).Click += playTone_Click;
			FindViewById<Button>(Resource.Id.getFwVersion).Click += getFwVersion_Click;
			FindViewById<Button>(Resource.Id.turnMotorAtPower).Click += turnMotorAtPower_Click;
			FindViewById<Button>(Resource.Id.turnMotorAtSpeed).Click += turnMotorAtSpeed_Click;
			FindViewById<Button>(Resource.Id.stepMotorAtPower).Click += stepMotorAtPower_Click;
			FindViewById<Button>(Resource.Id.stepMotorAtSpeed).Click += stepMotorAtSpeed_Click;
			FindViewById<Button>(Resource.Id.timeMotorAtPower).Click += timeMotorAtPower_Click;
			FindViewById<Button>(Resource.Id.timeMotorAtSpeed).Click += timeMotorAtSpeed_Click;

			FindViewById<Button>(Resource.Id.stopMotor).Click += stopMotor_Click;
			FindViewById<Button>(Resource.Id.setLed).Click += setLed_Click;
			FindViewById<Button>(Resource.Id.playSound).Click += playSound_Click;
			FindViewById<Button>(Resource.Id.draw).Click += draw_Click;
			FindViewById<Button>(Resource.Id.batchNoReply).Click += batchNoReply_Click;
			FindViewById<Button>(Resource.Id.batchReply).Click += batchReply_Click;


			_brick = new Brick(new BluetoothCommunication());
			//_brick = new Brick(new NetworkCommunication("192.168.2.237"));
			_brick.BrickChanged += brick_BrickChanged;
		}
コード例 #3
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _brick = new Brick(new BluetoothCommunication("COM6"));
            _brick.BrickChanged += _brick_BrickChanged;
            await _brick.ConnectAsync();
            await _brick.DirectCommand.PlayToneAsync(100, 3, 300);

        }
コード例 #4
0
		private async void Window_Loaded(object sender, RoutedEventArgs e)
		{
			// TODO: Update port value with the connected port on your machine
			_brick = new Brick(new BluetoothCommunication("COM6"));
			_brick.BrickChanged += _brick_BrickChanged;
			await _brick.ConnectAsync();
			await _brick.DirectCommand.SetMotorPolarity(OutputPort.B | OutputPort.C, Polarity.Backward);
			await _brick.DirectCommand.StopMotorAsync(OutputPort.All, false);
		}
コード例 #5
0
 // Stuff that happens when the program is loaded
 private async void Grid_Loaded(object sender, RoutedEventArgs e)
 {
     //connect to brick via bluetooth
     _brick = new Brick(new BluetoothCommunication("COM3"));
     _brick.BrickChanged += _brick_BrickChanged;
     await _brick.ConnectAsync();
     await _brick.DirectCommand.PlayToneAsync(50, 1000, 300);
     // Add comma seperated titles to list
     LogList.Add("buttonpressed,xcoordinate,ycoordinate");
 }
コード例 #6
0
		public void Update(Brick brick)
		{
			_sensorType = brick.Ports[BrickInputPort].Type;

			SensorDataStackPanel.Visibility = IsInvalidSensorOrWrongPort() ? Visibility.Collapsed : Visibility.Visible;

			RawRun.Text = brick.Ports[BrickInputPort].RawValue.ToString(CultureInfo.InvariantCulture);
			SiRun.Text = brick.Ports[BrickInputPort].SIValue.ToString(CultureInfo.InvariantCulture);
			PercentageRun.Text = brick.Ports[BrickInputPort].PercentValue.ToString(CultureInfo.InvariantCulture);

			UpdateUx();
		}
コード例 #7
0
		private async void Connect_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				_brick = new Brick(new BluetoothCommunication());
				//_brick = new Brick(new NetworkCommunication("192.168.2.237"));
				_brick.BrickChanged += brick_BrickChanged;
				await _brick.ConnectAsync();
				Output.Text = "Connected";
			}
			catch(Exception ex)
			{
				MessageBox.Show("Failed to connect: " + ex);
			}
		}
コード例 #8
0
ファイル: Program.cs プロジェクト: BananaScheriff/legoev3
		static async Task Test()
		{
			_brick = new Brick(new UsbCommunication());
			//_brick = new Brick(new BluetoothCommunication("COM5"));
			//_brick = new Brick(new NetworkCommunication("192.168.2.237"));

			_brick.BrickChanged += _brick_BrickChanged;

			System.Console.WriteLine("Connecting...");
			await _brick.ConnectAsync();

			System.Console.WriteLine("Connected...Turning motor...");
			await _brick.DirectCommand.TurnMotorAtSpeedForTimeAsync(OutputPort.A, 0x50, 1000, false);

			System.Console.WriteLine("Motor turned...beeping...");
			await _brick.DirectCommand.PlayToneAsync(0x50, 5000, 500);

			System.Console.WriteLine("Beeped...done!");
		}
コード例 #9
0
		private async void TryToConnect(object sender, RoutedEventArgs e)
		{
			Overlay.Show("Connecting");

			//ApplicationBar.IsVisible = false;
			ConnControl.Visibility = Visibility.Visible;

			var conType = CreateConnection();

			await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
			{
				if (conType != null)
				{
					_brick = new Brick(conType, true);
					_brick.BrickChanged += _brick_BrickChanged;
					try
					{
						await _brick.ConnectAsync();
						ConnControl.Visibility = Visibility.Collapsed;

						ConnTypeRun.Text = ConnControl.GetConnectionType().ToString();
						//ApplicationBar.IsVisible = true;
					}
					catch (Exception)
					{
						new MessageDialog("Could not connect", "Error").ShowAsync();
					}
				}
				else
				{
					MessageDialog dialog = new MessageDialog("Invalid connection type for this device", "Error");

					await dialog.ShowAsync();
				}

				Overlay.Hide();
			});
		}
コード例 #10
0
ファイル: Command.cs プロジェクト: BananaScheriff/legoev3
		internal Command(Brick brick) : this(CommandType.DirectNoReply)
		{
			_brick = brick;
		}
コード例 #11
0
		internal DirectCommand(Brick brick)
		{
			_brick = brick;
		}
コード例 #12
0
		public void Update(Brick brick)
		{
			_motorType = brick.Ports[BrickInputPort].Type;

			UpdateUx();
		}
コード例 #13
0
 public RobotController(RobotData data)
 {
     _data = data;
     _brick = new Brick(new BluetoothCommunication());
     _brick.BrickChanged += _brick_BrickChanged;
 }
コード例 #14
0
        /*************************
        *  METHODS
        *************************/

        /*
         * SetUpBrick prepares the Lego brick to send and reveive signals. 
         */

        private async void SetUpBrick()
        {
            //System.Console.WriteLine("\nIn SetUpBrick()");

            _brick = new Brick(new BluetoothCommunication("COM4"));

            _brick.BrickChanged += _brick_BrickChanged;

            await _brick.ConnectAsync();
            
            await _brick.DirectCommand.PlayToneAsync(100, 1000, 300);
            
            await _brick.DirectCommand.SetMotorPolarity(OutputPort.B | OutputPort.C, Polarity.Forward);
            
            await _brick.DirectCommand.StopMotorAsync(OutputPort.All, false);
            
            _brick.Ports[InputPort.One].SetMode(ColorMode.Reflective);

            //System.Console.WriteLine("Leaving SetUpBrick()\n");
        }
コード例 #15
0
ファイル: MainWindow.xaml.cs プロジェクト: adrianopsf/duoslam
        private async void ConnectClick(object sender, RoutedEventArgs e)
        {

            if (!_connected)
            {
                _brick = new Brick(new BluetoothCommunication("COM3"));
                _brick.BrickChanged += _brick_BrickChanged;
                try
                {
                    await _brick.ConnectAsync();
                    await _brick.DirectCommand.PlayToneAsync(5, 1000, 300);
                    buttonConnect.Background = Brushes.LightGreen;
                    _connected = true;
                    stackControls.Visibility = Visibility.Visible;
                    buttonConnect.Content = "Disconnect";
                    //setmode
                }
                catch (Exception)
                {
                    buttonConnect.Background = Brushes.OrangeRed;
                    MessageBox.Show("No connection :(");
                    _connected = false;
                    stackControls.Visibility = Visibility.Hidden;
                }
            }
            else
            {
                _brick.DirectCommand.PlayToneAsync(7, 200, 300);
                _brick.Disconnect();
                buttonConnect.Background = Brushes.OrangeRed;
                buttonConnect.Content = "Reconnect";
                _connected = false;
                stackControls.Visibility = Visibility.Hidden;
            }


        }
コード例 #16
0
 internal SystemCommand(Brick brick)
 {
     _brick = brick;
 }
コード例 #17
0
		internal SystemCommand(Brick brick)
		{
			_brick = brick;
		}
コード例 #18
0
ファイル: Command.cs プロジェクト: aquaseal/ev3
 internal Command(Brick brick) : this(CommandType.DirectReply)
 {
     _brick = brick;
 }