Exemple #1
0
        // Gets called when view is pushed to the screen
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // declare back button
            var backBtn = UIButton.FromType(UIButtonType.System);

            backBtn.Frame = new CGRect(10, 10, 50, 10 + h);
            backBtn.SetTitle("Back", UIControlState.Normal);

            backBtn.TouchUpInside += async(sender, e) =>
            {
                // Disconnect from device and switch back to previous view
                await BluetoothDevice.Disconnect(Peripheral, 1000);

                ViewController viewController = new ViewController();
                PresentViewController(viewController, true, null);
            };

            // declare red color slider
            UISlider redColorSlider = new UISlider
            {
                Frame      = new CGRect(10, 50, View.Bounds.Width - 20, 40),
                MaxValue   = max,
                MinValue   = min,
                Continuous = true,
                Value      = max / 2
            };

            // declare the green color slider
            UISlider greenColorSlider = new UISlider
            {
                Frame      = new CGRect(10, 100, View.Bounds.Width - 20, 40),
                MaxValue   = max,
                MinValue   = min,
                Continuous = true,
                Value      = max / 2
            };

            // declare the blue color slider
            UISlider blueColorSlider = new UISlider
            {
                Frame      = new CGRect(10, 150, View.Bounds.Width - 20, 40),
                MaxValue   = max,
                MinValue   = min,
                Continuous = true,
                Value      = max / 2
            };

            redColorSlider.ValueChanged += (sendaa, e) =>
            {
                // When the red color slider's value changed: send the sphero the color command with the three color slider's given colors
                var colorCommand = new FLEDCommand((int)redColorSlider.Value, (int)greenColorSlider.Value, (int)blueColorSlider.Value, 0);
                this.BluetoothDevice.SendCommand(Peripheral, colorCommand);
            };

            greenColorSlider.ValueChanged += (sendee, e) =>
            {
                // When the green color slider's value changed: send the sphero the color command with the three color slider's given colors
                var colorCommand = new FLEDCommand((int)redColorSlider.Value, (int)greenColorSlider.Value, (int)blueColorSlider.Value, 0);
                this.BluetoothDevice.SendCommand(Peripheral, colorCommand);
            };

            blueColorSlider.ValueChanged += (sendii, e) =>
            {
                // When the blue color slider's value changed: send the sphero the color command with the three color slider's given colors
                var colorCommand = new FLEDCommand((int)redColorSlider.Value, (int)greenColorSlider.Value, (int)blueColorSlider.Value, 0);
                this.BluetoothDevice.SendCommand(Peripheral, colorCommand);
            };

            // Create circle object
            circle = new Circle(new CGRect(10, 200, View.Bounds.Width - 20, View.Bounds.Height - 200), 5);

            // This is the interactive circle
            touchCircle = new Circle(new CGRect((circle.Frame.Width / 2) - 25, (circle.Frame.Height / 2) - 25 + 200, 50, 50), 2);
            touchCircle.UserInteractionEnabled = true;

            // Add the button to the screen.
            View.AddSubview(backBtn);
            // Add the sliders to the screen
            View.AddSubview(redColorSlider);
            View.AddSubview(greenColorSlider);
            View.AddSubview(blueColorSlider);
            // Add back circle to screen
            View.AddSubview(circle);
            // Add starting position of frontCircle to screen
            View.AddSubview(touchCircle);
        }