コード例 #1
0
        private async void TouchSensor_InputChanged(TouchSensor sensor, int value)
        {
            _logger.LogInformation($"TouchSensor {sensor.Id} input changed value:{value}");
            await _largeMotor.Stop();

            _brick.Led.SetValue(LedMode.OrangeFlashing);
        }
コード例 #2
0
ファイル: Scorpio.cs プロジェクト: nagyist/nSt.ScorpioCsharp
        /// <summary>
        /// This is where all sensor and motor properties are initialized
        /// </summary>
        /// <param name="bluetoothPortName"></param>
        public Scorpio(string bluetoothPortName)
        {
            Brick             = new AForgeNxtBrickFacade();
            BluetoothPortName = bluetoothPortName;

            // Sensors:
            // 1
            TouchSensor = new TouchSensor(Brick, NxtBrick.Sensor.First);
            // 2
            LightIntensitySensor = new LightSensor(Brick, NxtBrick.Sensor.Second);
            // 3 (shared)
            SoundLevelSensor = new SoundSensor(Brick, NxtBrick.Sensor.Third);
            SoundRatioSensor = new SoundDbaRatioSensor(Brick, NxtBrick.Sensor.Third);
            // 4
            UltrasonicSensor = new UltrasonicSensor(Brick, NxtBrick.Sensor.Fourth);

            // Motor sensors:
            // 1

            // Motors:
            // A,B,C
            MotorTail  = new Motor(Brick, NxtBrick.Motor.A);
            MotorRight = new Motor(Brick, NxtBrick.Motor.B);
            MotorLeft  = new Motor(Brick, NxtBrick.Motor.C);

            // Walk:
            WalkBehavior = new TwoMotorWalkBehavior(MotorLeft, MotorRight);
        }
コード例 #3
0
    public override void Setup(float startTime)
    {
        room.createBackground();
        addCover();
        addZzz();
        room.addHeartRate(startTime);
        room.addFootboard();
        room.addPerson();


        wiggler = new Wiggler(startTime, timeLength, cover.GetComponent <Sprite>());
        sensor  = new TouchSensor(input, gameObjectFinder);

        prodResponses = new Dictionary <GameObject, ActionResponsePair[]> {
            { zzz, new [] { new ActionResponsePair("catch z", new [] { "that's not going to wake him up" }) } },
            { cover, new [] { new ActionResponsePair("prod him", new[] { "He doesn't want to wake up" }),
                              new ActionResponsePair("prod him until he wakes up", new [] { "OK" }),
                              new ActionResponsePair("expose him to the cold",
                                                     new [] {
                        "you remove the blankets, security and otherwise.",
                        "there are now two distinct halves.",
                        "are they the same person?"
                    }), } },
        };
    }
コード例 #4
0
    public override void Setup(float startTime)
    {
        background.visible(true);
        same.visible(true);
        notSame.visible(true);
        circle.visible(true);
        triangle.visible(true);

        same.setCenterToViewportCoord(0.35f, 0.66f);
        notSame.setCenterToViewportCoord(0.7f, 0.66f);
        circle.setCenterToViewportCoord(0.3f, 0.33f);
        triangle.setCenterToViewportCoord(0.7f, 0.33f);

        // hide the triangle to start
        triangle.visible(false);

        circleCycler = new Cycler(shapeSpeed, 0, startTime);
        circleCycler.AddSprite(circle);

        notSameCycler = new DelayedCycler(0.2f, 4, 1.2f, startTime);
        notSameCycler.AddSprite(notSame);

        wiggler = new Wiggler(startTime, timeLength, new[] { circle, triangle });

        sensor = new TouchSensor(input, gameObjectFinder);
        shapes = new SpriteCollection(new[] { circle, triangle }, camera, sensor);
    }
コード例 #5
0
ファイル: rock.cs プロジェクト: ThomasGaff/Year-3-Uni-Work
        private void rock_Load(object sender, EventArgs e)
        {
            // create brick object and connect it to robot
            brick = new Brick <Sensor, Sensor, Sensor, Sensor>(Connect.Globalvariable.sComPort);
            //brick.Connection.Open();

            // Create touch sensor and connect it to port 2
            sensorTouch   = new TouchSensor();
            brick.Sensor2 = sensorTouch;

            // update form with brick details
            lblConnnection.Text = "Connected to EV3 Robot";

            // Create an IR sensor and connect it to port 4
            sensorDistance = new IRSensor();
            brick.Sensor4  = sensorDistance;

            // Create a colour sensor and connect it to port 3
            sensorColour  = new ColorSensor();
            brick.Sensor3 = sensorColour;

            // Set ports for synchronised motor vehicle
            brick.Vehicle.LeftPort  = MotorPort.OutB;
            brick.Vehicle.RightPort = MotorPort.OutC;
        }
コード例 #6
0
 public SceneTwelve(SceneManager manager) : base(manager)
 {
     timeLength     = 8.0f;
     touchSensor    = new TouchSensor(input, gameObjectFinder);
     background     = new DitheredBlueBackground(resourceFactory);
     fallingGuyProp = new FallingGuyProp();
 }
コード例 #7
0
        public override void Init()
        {
            this.proc = new Thread(new ThreadStart(Loop));

            this.move  = new Movement();
            this.touch = new TouchSensor(SensorPort.In4);
        }
コード例 #8
0
        /// <summary>
        /// This is where all sensor and motor properties are initialized
        /// </summary>
        /// <param name="bluetoothPortName"></param>
        public Scorpio(string bluetoothPortName)
        {
            Brick = new AForgeNxtBrickFacade();
            BluetoothPortName = bluetoothPortName;

            // Sensors:
            // 1
            TouchSensor = new TouchSensor(Brick, NxtBrick.Sensor.First);
            // 2
            LightIntensitySensor = new LightSensor(Brick, NxtBrick.Sensor.Second);
            // 3 (shared)
            SoundLevelSensor = new SoundSensor(Brick, NxtBrick.Sensor.Third);
            SoundRatioSensor = new SoundDbaRatioSensor(Brick, NxtBrick.Sensor.Third);
            // 4
            UltrasonicSensor = new UltrasonicSensor(Brick, NxtBrick.Sensor.Fourth);

            // Motor sensors:
            // 1

            // Motors:
            // A,B,C
            MotorTail = new Motor(Brick, NxtBrick.Motor.A);
            MotorRight = new Motor(Brick, NxtBrick.Motor.B);
            MotorLeft = new Motor(Brick, NxtBrick.Motor.C);

            // Walk:
            WalkBehavior = new TwoMotorWalkBehavior(MotorLeft, MotorRight);
        }
コード例 #9
0
    public override void Setup(float startTime)
    {
        room.addSplitLine();
        room.openEyes();
        room.openEyes();

        var guyLeftPivot  = room.guyLeft.createPivotOnBottomRightCorner();
        var guyRightPivot = room.guyRight.createPivotOnBottomLeftCorner();

        wiggler        = new Wiggler(startTime, timeLength, new[] { guyLeftPivot });
        reverseWiggler = new ReverseWiggler(startTime, timeLength, new[] { guyRightPivot });

        sensor = new TouchSensor(input, gameObjectFinder);

        prodResponses = new Dictionary <GameObject, ActionResponsePair[]> {
            { room.guyLeft.gameObject, new [] {
                  new ActionResponsePair("prod Same", new[] { "it's already awake." }),
                  new ActionResponsePair("prod Same", new[] { "listen to the lyrics." })
              } },
            { room.guyRight.gameObject, new [] {
                  new ActionResponsePair("prod Not Same", new[] { "it's already awake." }),
                  new ActionResponsePair("prod Not Same", new[] { "listen to the lyrics." })
              } },
        };
    }
コード例 #10
0
ファイル: SceneTwelve.cs プロジェクト: absurdhero/tmotmo-full
 public SceneTwelve(SceneManager manager)
     : base(manager)
 {
     timeLength = 8.0f;
     touchSensor = new TouchSensor(input, gameObjectFinder);
     background = new DitheredBlueBackground(resourceFactory);
     fallingGuyProp = new FallingGuyProp();
 }
コード例 #11
0
 public override void Init()
 {
     this.proc  = new Thread(new ThreadStart(Loop));
     this.move  = new Movement();
     this.touch = new TouchSensor(SensorPort.In4);
     this.dist  = new IRSensor(SensorPort.In1, IRMode.Proximity);
     this.rand  = new Random();
 }
コード例 #12
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        TouchSensor touch = other.GetComponent <TouchSensor>();

        if (touch != null /*Touch*/ && other.GetComponent <TouchSensor>().tipped)
        {
            cartTouched = true;
        }
    }
コード例 #13
0
        public override void Init()
        {
            this.proc = new Thread(new ThreadStart(Loop));

            this.move  = new Movement();
            this.touch = new TouchSensor(SensorPort.In4);
            this.dist  = new IRSensor(SensorPort.In1, IRMode.Proximity);
            this.color = new EV3ColorSensor(SensorPort.In2, ColorMode.Color);
        }
コード例 #14
0
ファイル: Continued.cs プロジェクト: absurdhero/tmotmo-full
 public override void Setup(float startTime)
 {
     originalBGColor = Camera.main.backgroundColor;
     Camera.main.backgroundColor = Color.black;
     touch = new TouchSensor(input, new GameObjectFinder());
     var layout = GameObject.Find("Layout").GetComponent<Layout>();
     messageBox = layout.messageBox;
     messageBox.setMessage("Insert Disk 2");
     messageBox.show();
 }
コード例 #15
0
    public override void Setup(float startTime)
    {
        originalBGColor             = Camera.main.backgroundColor;
        Camera.main.backgroundColor = Color.black;
        touch = new TouchSensor(input, new GameObjectFinder());
        var layout = GameObject.Find("Layout").GetComponent <Layout>();

        messageBox = layout.messageBox;
        messageBox.setMessage("Insert Disk 2");
        messageBox.show();
    }
コード例 #16
0
    // Cycles through displaying a sequence of action-response pairs for each object that is touched.
    // Calls onComplete when it reaches the end of a cycle with the object for which the sequence was completed.
    public void hintWhenTouched(Action<Sprite> onComplete, TouchSensor sensor, float currentTime, Dictionary<Sprite, ActionResponsePair[]> interactions)
    {
        //if (!sensor.hasTaps()) return; // only act on touches

        // if there was an interaction but a dialog has not shown yet...
        if (currentTime <= actionPrintedAt + promptTime && touchedObject != null) {
            // ignore a tap if it's been at least a half second since prompting
            if (sensor.hasTaps() && currentTime > actionPrintedAt + 0.5f) {
                return;
            }
            // ignore touches of the same object before the first dialog is shown
            if (touchedObject != null && sensor.insideSprite(Camera.main, touchedObject, TouchSensor.allPhases)) {
                return;
            }
        }

        // if a dialog was just shown, let it sit there for a moment
        if (currentTime <= actionPrintedAt + promptTime + 0.5f) {
            return;
        }

        // cycle through remaining dialogs
        if (remainingMessages.Count > 0) {
            if (sensor.hasTaps()) {
                messageBox.setMessage(remainingMessages[0]);
                remainingMessages.RemoveAt(0);
                actionPrintedAt = currentTime - promptTime;
                Debug.Log("tapped. messages remaining: " + remainingMessages.Count);
            }
            return;
        }

        // start an action-dialog sequence if they touched an interactive object

        touchedObject = detectObjectInteraction(sensor, interactions);

        if (touchedObject == null) return;

        var message = interactions[touchedObject][0];
        var action = message.action;
        var responses = message.responses;
        actionPrintedAt = currentTime;
        print(action, responses[0]);

        var restOfresponses = new List<string>(responses).Skip(1).ToList();
        hint(action, restOfresponses);

        if (interactions[touchedObject].Length > 1) {
            interactions[touchedObject] = interactions[touchedObject].Skip(1).ToArray();
        } else {
            target = touchedObject;
            this.onComplete = onComplete;
        }
    }
コード例 #17
0
ファイル: SceneTwo.cs プロジェクト: nagyistoce/tmotmo
    public override void Setup(float startTime)
    {
        room.createBackground();
        room.addZzz();
        room.addHeartRate(startTime);
        room.addFootboard();
        room.addCover();
        room.addPerson();

        wiggler = new Wiggler(startTime, timeLength, room.cover);
        sensor = new TouchSensor(input);
    }
コード例 #18
0
 private void Awake()
 {
     touchsensor      = gameObject.GetComponent <TouchSensor>();
     button           = gameObject.GetComponent <ButtonSensor>();
     rfidsensor       = gameObject.GetComponent <RFIDReader>();
     objectposition   = gameObject.GetComponent <PositionReader>();
     lightcontroller  = gameObject.GetComponent <LightController>();
     soundemitter     = gameObject.GetComponent <SoundEmitterController>();
     motorcontroller  = gameObject.GetComponent <MotorController>();
     videoemitter     = gameObject.GetComponent <VideoEmitterController>();
     effectcontroller = gameObject.GetComponent <EffectController>();
 }
コード例 #19
0
        public void touchInsideSpriteWhenAnotherSpriteNotInFront()
        {
            var sprite = spriteAt(Vector3.zero);
            expectAndReturnAlpha(sprite, 1.0f);
            var backSprite = spriteAt(Vector3.forward);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject, backSprite.MockObject}));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.True);
        }
コード例 #20
0
        public void touchWhenOnlyOneSpriteBeneathFinger()
        {
            var sprite = spriteAt(Vector3.forward);

            expectAndReturnAlpha(sprite, 1.0f);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject }));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.True);
        }
コード例 #21
0
        public void touchInsideSpriteWhenAnotherSpriteNotInFront()
        {
            var sprite = spriteAt(Vector3.zero);

            expectAndReturnAlpha(sprite, 1.0f);
            var backSprite = spriteAt(Vector3.forward);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject, backSprite.MockObject }));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.True);
        }
コード例 #22
0
        /// <summary>
        /// Repeatedly checks the state of the switch and resets it necessary
        /// </summary>
        private static void MainLoop(Motor motor)
        {
            var touchSensor = new TouchSensor(SensorPort.In1);

            while (true) {

                // there are a few states that the switch and the arm can be in
                // our default is the arm down, and the switch off
                // if someone flips the switch, we'll move our arm up until it completes its motion
                // at that point, the switch will be off again and we'll move the arm back

                // Our "switch" is off when the touch sensor is pressed (inverse)
                var switchStatus = !touchSensor.IsPressed ();

                // When our switch is on, we need to turn it back off
                if (switchStatus) {
                    // if the motor hasn't moved backwards to push the switch off, we'll do that
                    if (motor.GetTachoCount () > -120) {
            //						LcdConsole.WriteLine ("(On) Extending arm");
                        motor.On (-20);
                        System.Threading.Thread.Sleep (50);
                    } else { // if it's moved all the way back, stop pushing it
            //						LcdConsole.WriteLine ("(On) Arm fully extended");
                        motor.Off ();
                    }

                } else { // When it's off, we're happy
                    // if the arm isn't fully retracted, it's time to put it back to zero
                    if (motor.GetTachoCount () < -20) {
            //						LcdConsole.WriteLine ("(Off) Reset the arm");
                        motor.On (20);
                        System.Threading.Thread.Sleep (200);
                    } else { // if it is, we're done
            //						LcdConsole.WriteLine ("(Off) Arm fully reset");
                        motor.Off ();
                    }
                }

                if (switchStatus != PreviouslySwitched && !PreviouslySwitched) {
                    Action<string> foo = delegate(string x) {
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://crappychatws.azurewebsites.net/api/lego");
                        request.Proxy = null;
                        request.GetResponse ();
                        LcdConsole.WriteLine(x);
                    };
                    foo.BeginInvoke ("Someone flipped my switch >_<", null, null);
                }

                PreviouslySwitched = switchStatus;
            }
        }
コード例 #23
0
ファイル: Scorpio.cs プロジェクト: nagyist/nSt.ScorpioCsharp
        /// <summary>
        /// This is where all sensors and motors are stopped
        /// </summary>
        public void DisconnectAll()
        {
            // Stop sensing
            if (LightIntensitySensor.IsSensing())
            {
                LightIntensitySensor.StopSensing();
            }
            if (SoundLevelSensor.IsSensing())
            {
                SoundLevelSensor.StopSensing();
            }
            if (SoundRatioSensor.IsSensing())
            {
                SoundRatioSensor.StopSensing();
            }
            if (UltrasonicSensor.IsSensing())
            {
                UltrasonicSensor.StopSensing();
            }
            if (TouchSensor.IsSensing())
            {
                TouchSensor.StopSensing();
            }
            //TODO clear sensors?

            // Stop behaviors
            if (WalkBehavior.IsWalking)
            {
                WalkBehavior.Stop();
            }

            // Stop motors
            if (MotorTail.IsRunning)
            {
                MotorTail.Stop();
            }
            if (MotorRight.IsRunning)
            {
                MotorRight.Stop();
            }
            if (MotorLeft.IsRunning)
            {
                MotorLeft.Stop();
            }

            System.Threading.Thread.Sleep(1000);

            Brick.Disconnect();
            IsConnectionStarted = false;
        }
コード例 #24
0
        public void touchInsideSpriteWhenTransparentSpriteInFront()
        {
            var sprite = spriteAt(Vector3.forward);
            expectAndReturnAlpha(sprite, 1.0f);

            var frontSprite = spriteAt(Vector3.back);
            expectAndReturnAlpha(frontSprite, 0.0f);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject, frontSprite.MockObject}));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.True);
        }
コード例 #25
0
        public Robot(Brick brick, ILogger <Robot> logger)
        {
            _brick  = brick;
            _logger = logger;

            //first find all devices and wire up events before connecting
            _largeMotor  = _brick.FindDevice <LargeMotor>("largeMotorId");
            _touchSensor = _brick.FindDevice <TouchSensor>("touchSensorId");
            _touchSensor.InputChanged += TouchSensor_InputChanged;

            _brick.Buttons.Up.Clicked += Button_Clicked;

            //monitor the battery level
            _brick.Battery.Mode          = BatteryMode.Level;
            _brick.Battery.ValueChanged += Battery_ValueChanged;
        }
コード例 #26
0
 public override void buildFitness(Unit unitInput, List <GameObject> unitObjectsInput)
 {
     base.buildFitness(unitInput, unitObjectsInput);
     foreach (GameObject obj in unitObjects)
     {
         if (obj.tag == "Goal")
         {
             goal = obj;
         }
         if (obj.tag == "Focus")
         {
             focus = obj;
             ts    = obj.GetComponent <TouchSensor>();
         }
     }
 }
コード例 #27
0
        public void noTouchWhenAllSpritesAreTransparent()
        {
            var sprite = spriteAt(Vector3.forward);

            expectAndReturnAlpha(sprite, 0.0f);

            var frontSprite = spriteAt(Vector3.back);

            expectAndReturnAlpha(frontSprite, 0.0f);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject, frontSprite.MockObject }));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.False);
        }
コード例 #28
0
ファイル: TitleScene.cs プロジェクト: absurdhero/tmotmo-full
    public override void Update()
    {
        var touch = new TouchSensor(input, gameObjectFinder);

        if (touch.insideSprite(Camera.main, buyMusic)) {
            Application.OpenURL("http://itunes.apple.com/us/album/same-not-same-ep/id533347009");
        }
        else if (touch.insideSprite(Camera.main, news)) {
            Application.OpenURL("http://themakingofthemakingof.com");
        }
        else if (touch.hasTaps()) {
            endScene();
        }

        if (cycle_title.Complete()) {
            animateStartButton();
        }

        cycle_title.Update(Time.time);
    }
コード例 #29
0
ファイル: SceneThree.cs プロジェクト: absurdhero/tmotmo-full
    public override void Setup(float startTime)
    {
        room.addSplitLine();
        room.openEyes();
        room.openEyes();

        var guyLeftPivot = room.guyLeft.createPivotOnBottomRightCorner();
        var guyRightPivot = room.guyRight.createPivotOnBottomLeftCorner();
        wiggler = new Wiggler(startTime, timeLength, new[] {guyLeftPivot});
        reverseWiggler = new ReverseWiggler(startTime, timeLength, new[] {guyRightPivot});

        sensor = new TouchSensor(input, gameObjectFinder);

        prodResponses = new Dictionary<GameObject, ActionResponsePair[]> {
                {room.guyLeft.gameObject, new [] {
                    new ActionResponsePair("prod Same",   new[] {"it's already awake."}),
                    new ActionResponsePair("prod Same",   new[] {"listen to the lyrics."})}},
                {room.guyRight.gameObject, new [] {
                    new ActionResponsePair("prod Not Same", new[] {"it's already awake."}),
                    new ActionResponsePair("prod Not Same", new[] {"listen to the lyrics."})}},
        };
    }
コード例 #30
0
ファイル: Program.cs プロジェクト: ubuntuuser/robots
 public static void Main(string[] args)
 {
     Console.WriteLine ("Resetting the motors");
     TouchSensor ts = new TouchSensor(SensorPort.In2);
     Motor motorFwd = new Motor(MotorPort.OutB);
     Motor motorTurn = new Motor(MotorPort.OutC);
     Motor motorSwitch = new Motor(MotorPort.OutA);
     Motor motorArm = new Motor(MotorPort.OutD);
     motorArm.On (-60);
     ButtonEvents buts = new ButtonEvents();
     bool keepGoing = true;
     while (keepGoing) {
         buts.EscapePressed += () => {
             keepGoing = false;
         };
         if (ts.IsPressed ()) {
             keepGoing = false;
         }
     }
     motorArm.Off ();
     switchMode ();
     keepGoing = true;
     TouchSensor ts2 = new TouchSensor(SensorPort.In4);
     motorArm.On (-60);
     while (keepGoing) {
         buts.EscapePressed += () => {
             keepGoing = false;
         };
         if (ts2.IsPressed ()) {
             keepGoing = false;
         }
     }
     motorArm.Off ();
     switchMode ();
     motorArm.ResetTacho ();
     motorFwd.ResetTacho ();
     motorSwitch.ResetTacho ();
     motorTurn.ResetTacho ();
 }
コード例 #31
0
ファイル: Program.cs プロジェクト: karagulamos/msint
        public static void RunTouchDetectionTest(int testNumber)
        {
            var doneText = $"Test {testNumber} Done.";
            var failText = $"Test {testNumber} Failed.";

            var sensor = new TouchSensor(new XTouchDevice());

            Contract.Assert(sensor.GetTouchCount() == 4, failText);

            sensor = new TouchSensor(new YTouchDevice());
            Contract.Assert(sensor.GetTouchCount() == 3, failText);

            sensor = new TouchSensor(new ZTouchDevice());
            Contract.Assert(sensor.GetTouchCount() == 0, failText);

            sensor = new TouchSensor(new OneTouchDevice());
            Contract.Assert(sensor.GetTouchCount() == 1, failText);

            sensor = new TouchSensor(new SparseTouchDevice());
            Contract.Assert(sensor.GetTouchCount() == 8, failText);

            Console.WriteLine(doneText);
        }
コード例 #32
0
    public override void Update()
    {
        var touch = new TouchSensor(input, gameObjectFinder);

        if (touch.insideSprite(Camera.main, buyMusic))
        {
            Application.OpenURL("http://itunes.apple.com/us/album/same-not-same-ep/id533347009");
        }
        else if (touch.insideSprite(Camera.main, news))
        {
            Application.OpenURL("http://themakingofthemakingof.com");
        }
        else if (touch.hasTaps())
        {
            endScene();
        }

        if (cycle_title.Complete())
        {
            animateStartButton();
        }

        cycle_title.Update(Time.time);
    }
コード例 #33
0
 private Sprite detectObjectInteraction(TouchSensor sensor, Dictionary<Sprite, ActionResponsePair[]> interactions)
 {
     Sprite touched = null;
     foreach(var sprite in interactions.Keys) {
         if (sensor.insideSprite(Camera.main, sprite, new[] {TouchInput.TouchPhase.Began})) {
             touched = sprite;
         }
     }
     return touched;
 }
コード例 #34
0
 public bool touchedBed(TouchSensor touch)
 {
     return(touch.insideSprite(Camera.main, cover.GetComponent <Sprite>(), new[] { TouchPhase.Began }));
 }
コード例 #35
0
        static void Main()
        {
            var distance = new DistanceSensor(Netduino3.GpioPin.D8);
            //SoundSensor sound = new SoundSensor(Netduino3.AdcChannel.A0);
            LightSensor       light  = new LightSensor(Netduino3.AdcChannel.A1);
            RotaryAngleSensor rotary = new RotaryAngleSensor(Netduino3.AdcChannel.A2);
            TemperatureSensor temp   = new TemperatureSensor(Netduino3.AdcChannel.A3);
            TouchSensor       touch  = new TouchSensor(Netduino3.GpioPin.D2);
            LedSocket         led    = new LedSocket(Netduino3.GpioPin.D3);
            Button            btn    = new Button(Netduino3.GpioPin.D5);
            Relay             rly    = new Relay(Netduino3.GpioPin.D6);
            Buzzer            buzz   = new Buzzer(Netduino3.GpioPin.D7);
            //var rgb = new LcdRgbBacklight();
            //rgb.EnableDisplay(true);
            Random rnd     = new Random();
            int    counter = 0;
            bool   Touched = false;

            while (true)
            {
                counter++;
                Thread.Sleep(100);
                //rgb.GoHome();
                //rgb.SetCursor(0, 0);
                //rgb.Clear();
                //Debug.WriteLine("sound:"+sound.ReadLevel());
                Debug.WriteLine("light:" + light.ReadLightLevel());
                Debug.WriteLine("rotary:" + rotary.GetAngle());
                Debug.WriteLine("temp:" + temp.ReadTemperature());
                Debug.WriteLine("distance:" + distance.MeasureInCentimeters() + "cm");
                if (touch.IsTouched() && !Touched)
                {
                    Touched = true;
                    //rgb.Write("turn on light");
                    led.TurnOn();
                }
                else if (!touch.IsTouched() && Touched)
                {
                    Touched = false;
                    //rgb.Write("turn off light");
                    led.TurnOff();
                }
                if (btn.IsPressed())
                {
                    rly.TurnOn();
                    buzz.TurnOn();
                }
                else
                {
                    buzz.TurnOff();
                    rly.TurnOff();
                }

                /*
                 * if (counter > 50)
                 * {
                 *  rgb.SetBacklightRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
                 *  counter = 0;
                 * }*/
            }
        }
コード例 #36
0
 public void hintWhenTouched(Action <GameObject> onCompleted, MessagePromptCoordinator messagePromptCoordinator, TouchSensor touch)
 {
     messagePromptCoordinator.hintWhenTouched(onCompleted, touch, Time.time, interactions);
 }
コード例 #37
0
        public void touchWhenOnlyOneSpriteBeneathFinger()
        {
            var sprite = spriteAt(Vector3.forward);
            expectAndReturnAlpha(sprite, 1.0f);

            var sensor = new TouchSensor(
                inputReturningTouch.MockObject,
                findInScene(new[] { sprite.MockObject}));

            Assert.That(sensor.insideSprite(camera.MockObject, sprite.MockObject), Iz.True);
        }
コード例 #38
0
 public void hintWhenTouched(Action<GameObject> onCompleted, MessagePromptCoordinator messagePromptCoordinator, TouchSensor touch)
 {
     messagePromptCoordinator.hintWhenTouched(onCompleted, touch, Time.time, interactions);
 }
コード例 #39
0
ファイル: HospitalRoom.cs プロジェクト: nagyistoce/tmotmo
 public void hintWhenTouched(Action<Sprite> onCompleted, MessagePromptCoordinator messagePromptCoordinator, TouchSensor touch)
 {
     if (interactions == null) {
         interactions = new Dictionary<Sprite, ActionResponsePair[]> {
             {clipBoard, new [] {new ActionResponsePair("look at chart", new [] {"even the doctors don't understand the test results"})}},
             {zzz,       new [] {new ActionResponsePair("catch z", new [] {"that's not going to wake him up"})}},
             {heartRate, new [] {new ActionResponsePair("look at monitor", new []{"things are stable, for now"})}},
             {cover,     new [] {new ActionResponsePair("prod him", new[] {"He doesn't want to wake up"}),
                                 new ActionResponsePair("prod him until he wakes up", new [] {"OK"}),
                                 new ActionResponsePair("expose him to the cold",
                                     new [] {
                                     "you remove the blankets, security and otherwise.",
                                     "there are now two distinct halves.",
                                     "are they the same person?"}),
                 }},
         };
     }
     messagePromptCoordinator.hintWhenTouched(onCompleted, touch, Time.time, interactions);
 }
コード例 #40
0
        static void Main()
        {
            TouchSensor     touch = new TouchSensor(FEZ.GpioPin.D7);
            LightSensor     light = new LightSensor(FEZ.AdcChannel.A3);
            ServoMotor      servo = new ServoMotor(FEZ.PwmPin.Controller4.Id, FEZ.PwmPin.Controller4.D5);
            Buzzer          buzz  = new Buzzer(FEZ.GpioPin.D4);
            LcdRgbBacklight lcd   = new LcdRgbBacklight();

            host = "192.168.1.152";
            port = 80;

            var buffer = new byte[512];
            var cont   = GpioController.GetDefault();
            var reset  = cont.OpenPin(FEZ.GpioPin.WiFiReset);
            var irq    = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt);
            var spi    = SpiDevice.FromId(FEZ.SpiBus.WiFi, SPWF04SxInterface.GetConnectionSettings(FEZ.GpioPin.WiFiChipSelect));

            connected    = false;
            socketOpened = false;
            garageLed    = cont.OpenPin(FEZ.GpioPin.D2);
            servo.SetPosition(180);
            garageLed.SetDriveMode(GpioPinDriveMode.Output);

            wifi = new SPWF04SxInterface(spi, irq, reset);

            wifi.IndicationReceived += (s, e) => Debug.WriteLine($"WIND: {Program.WindToName(e.Indication)} {e.Message}");
            wifi.ErrorReceived      += (s, e) => Debug.WriteLine($"ERROR: {e.Error} {e.Message}");

            wifi.TurnOn();
            //wifi.JoinNetwork("GHI", "ghi555wifi.");

            lcd.Clear();
            lcd.SetBacklightRGB(100, 100, 100);
            lcd.Write("Time:");

            while (!connected)
            {
                ListenWind();
                Thread.Sleep(200);
            }

            StringBuilder builder = new StringBuilder();

            while (connected)
            {
                if (!socketOpened)
                {
                    id           = wifi.OpenSocket(host, port, SPWF04SxConnectionyType.Tcp, SPWF04SxConnectionSecurityType.None);
                    socketOpened = true;
                }

                var hour   = DateTime.UtcNow.Hour;
                var minute = DateTime.UtcNow.Minute;
                var second = DateTime.UtcNow.Second;
                lcd.SetCursor(7, 1);
                lcd.Write($"{hour}:{minute}:{second}");

                if (touch.IsTouched())
                {
                    wifi.WriteSocket(id, Encoding.UTF8.GetBytes("Someone wants to open the garage"));
                }

                if (light.ReadLightLevel() > 60 && isDoorOpened == true)
                {
                    //Debug.WriteLine(light.ReadLightLevel().ToString());
                    wifi.WriteSocket(id, Encoding.UTF8.GetBytes("Car in the garage"));
                    while (light.ReadLightLevel() > 60)
                    {
                        Thread.Sleep(50);
                    }
                    wifi.WriteSocket(id, Encoding.UTF8.GetBytes("You can close the garage"));
                }

                if (wifi.QuerySocket(id) is var avail && avail > 0)
                {
                    wifi.ReadSocket(id, buffer, 0, Math.Min(avail, buffer.Length));

                    for (var k = 0; k < buffer.Length; k++)
                    {
                        if (buffer[k] != 0)
                        {
                            char result = (char)buffer[k];
                            builder.Append(result);
                            buffer[k] = 0;
                        }
                    }
                    Debug.WriteLine(builder.ToString());
                }
                string command = builder.ToString();
                builder.Clear();

                switch (command)
                {
                case "open":
                    buzz.Beep();
                    servo.SetPosition(0);
                    garageLed.Write(GpioPinValue.High);
                    isDoorOpened = true;
                    break;

                case "close":
                    buzz.Beep();
                    servo.SetPosition(180);
                    garageLed.Write(GpioPinValue.Low);
                    break;

                default:
                    break;
                }
                Thread.Sleep(100);
            }
        }
コード例 #41
0
 public void SetUp()
 {
     mocks = new MockRepository ();
     sensor = mocks.StrictMock<TouchSensor> ();
     prompt = mocks.DynamicMock<Prompt> ();
     messageBox = mocks.DynamicMock<MessageBox> ();
 }
コード例 #42
0
ファイル: SceneTwo.cs プロジェクト: absurdhero/tmotmo-full
    public override void Setup(float startTime)
    {
        room.createBackground();
        addCover();
        addZzz();
        room.addHeartRate(startTime);
        room.addFootboard();
        room.addPerson();

        wiggler = new Wiggler(startTime, timeLength, cover.GetComponent<Sprite>());
        sensor = new TouchSensor(input, gameObjectFinder);

        prodResponses = new Dictionary<GameObject, ActionResponsePair[]> {
            {zzz,       new [] {new ActionResponsePair("catch z", new [] {"that's not going to wake him up"})}},
            {cover,     new [] {new ActionResponsePair("prod him", new[] {"He doesn't want to wake up"}),
                    new ActionResponsePair("prod him until he wakes up", new [] {"OK"}),
                    new ActionResponsePair("expose him to the cold",
                                           new [] {
                        "you remove the blankets, security and otherwise.",
                        "there are now two distinct halves.",
                        "are they the same person?"}),
                }},
        };
    }
コード例 #43
0
ファイル: SceneTwo.cs プロジェクト: absurdhero/tmotmo-full
 public bool touchedBed(TouchSensor touch)
 {
     return touch.insideSprite(Camera.main, cover.GetComponent<Sprite>(), new[] {TouchPhase.Began});
 }
コード例 #44
0
 public static bool belowFinger(this Sprite obj, TouchSensor sensor)
 {
     return sensor.insideSprite(Camera.main, obj, new[] {TouchPhase.Began, TouchPhase.Moved});
 }
コード例 #45
0
ファイル: HospitalRoom.cs プロジェクト: nagyistoce/tmotmo
 public bool touchedBed(TouchSensor touch)
 {
     return touch.insideSprite(Camera.main, cover, new[] {TouchInput.TouchPhase.Began});
 }