예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputPin"></param>
        /// <param name="type"></param>
        /// <param name="debounceDuration">in milliseconds</param>
        public PushButton(H.Cpu.Pin inputPin, CircuitTerminationType type, int debounceDuration = 20)
        {
            this.DebounceDuration = new TimeSpan(0, 0, 0, 0, debounceDuration);

            // if we terminate in ground, we need to pull the port high to test for circuit completion, otherwise down.
            H.Port.ResistorMode resistorMode = H.Port.ResistorMode.Disabled;
            switch (type)
            {
            case CircuitTerminationType.CommonGround:
                resistorMode = H.Port.ResistorMode.PullUp;
                break;

            case CircuitTerminationType.High:
                resistorMode = H.Port.ResistorMode.PullDown;
                break;

            case CircuitTerminationType.Floating:
                resistorMode = H.Port.ResistorMode.Disabled;
                break;
            }

            // create the interrupt port from the pin and resistor type
            this.DigitalIn = new H.InterruptPort(inputPin, true, resistorMode, H.Port.InterruptMode.InterruptEdgeBoth);

            // wire up the interrupt handler
            this.DigitalIn.OnInterrupt += DigitalIn_OnInterrupt;
        }
예제 #2
0
        public RotaryEncoderWithButton(H.Cpu.Pin aPhasePin, H.Cpu.Pin bPhasePin,
                                       H.Cpu.Pin buttonPin, CircuitTerminationType buttonCircuitTerminationType, int debounceDuration = 20) : base(aPhasePin, bPhasePin)
        {
            this._button = new PushButton(buttonPin, buttonCircuitTerminationType, debounceDuration);

            this._button.Clicked      += Button_Clicked;
            this._button.PressStarted += Button_PressStarted;
            this._button.PressEnded   += Button_PressEnded;
        }
        protected ushort _numberOfReads         = 0; //

        /// <summary>
        /// LinearHallEffectTachometer driver
        /// </summary>
        /// <param name="inputPin"></param>
        /// <param name="type"></param>
        /// <param name="numberOfMagnets"></param>
        /// <param name="rpmChangeNotificationThreshold"></param>
        public LinearHallEffectTachometer(int inputPin, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                          ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F)

        {
            //this(device.CreateDigitalInputPort(inputPin), type, numberOfMagnets, rpmChangeNotificationThreshold)

            var gpio         = GpioController.GetDefault();
            var DigitalInput = gpio.OpenPin(inputPin);

            DigitalInput.SetDriveMode(GpioPinDriveMode.Input);
            setTachoMeter(DigitalInput, type, numberOfMagnets, rpmChangeNotificationThreshold);
        }
        public LinearHallEffectTachometer(IDigitalInputPort inputPort, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                          ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F)
        {
            NumberOfMagnets = numberOfMagnets;
            RPMChangeNotificationThreshold = rpmChangeNotificationThreshold;

            // if we terminate in ground, we need to pull the port high to test for circuit completion, otherwise down.
            //var resistorMode = (type == CircuitTerminationType.CommonGround) ? H.Port.ResistorMode.PullUp : H.Port.ResistorMode.PullDown;

            // create the interrupt port from the pin and resistor type
            InputPort = inputPort;

            InputPort.Changed += InputPortChanged;
        }
예제 #5
0
        protected ushort _numberOfReads         = 0; //


        public LinearHallEffectTachometer(H.Cpu.Pin inputPin, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                          ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F)
        {
            this._numberOfMagnets = numberOfMagnets;
            this.RPMChangeNotificationThreshold = rpmChangeNotificationThreshold;

            // if we terminate in ground, we need to pull the port high to test for circuit completion, otherwise down.
            //var resistorMode = (type == CircuitTerminationType.CommonGround) ? H.Port.ResistorMode.PullUp : H.Port.ResistorMode.PullDown;

            // create the interrupt port from the pin and resistor type
            this.DigitalIn = new H.InterruptPort(inputPin, true, H.Port.ResistorMode.PullDown, H.Port.InterruptMode.InterruptEdgeHigh);

            // wire up the interrupt handler
            this.DigitalIn.OnInterrupt += DigitalIn_OnInterrupt;
        }
예제 #6
0
        public DipSwitch(H.Cpu.Pin[] switchPins, CircuitTerminationType type)
        {
            //this.DigitalIns = new H.InterruptPort[switchPins.Length];
            //this.IsOn = new bool[switchPins.Length];
            this._switches = new ISwitch[switchPins.Length];

            for (int i = 0; i < switchPins.Length; i++)
            {
                //this.DigitalIns[i] = new H.InterruptPort(switchPins[i], true, resistorMode, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeBoth);
                this._switches[i] = new SpstSwitch(switchPins[i], type);

                // capture the variable. oh, C#...
                int iCopy = i;

                this._switches[i].Changed += (s, e) =>
                {
                    this.HandleSwitchChange(iCopy);
                };
            }
        }
예제 #7
0
        public SpstSwitch(H.Cpu.Pin pin, CircuitTerminationType type)
        {
            // if we terminate in ground, we need to pull the port high to test for circuit completion, otherwise down.
            H.Port.ResistorMode resistorMode = H.Port.ResistorMode.Disabled;
            switch (type)
            {
            case CircuitTerminationType.CommonGround:
                resistorMode = H.Port.ResistorMode.PullUp;
                break;

            case CircuitTerminationType.High:
                resistorMode = H.Port.ResistorMode.PullDown;
                break;

            case CircuitTerminationType.Floating:
                resistorMode = H.Port.ResistorMode.Disabled;
                break;
            }

            this.DigitalIn = new H.InterruptPort(pin, true, resistorMode, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeBoth);

            this.DigitalIn.OnInterrupt += DigitalIn_OnInterrupt;
        }
        protected ushort _numberOfReads         = 0; //

        /// <summary>
        /// LinearHallEffectTachometer driver
        /// </summary>
        /// <param name="inputPin"></param>
        /// <param name="type"></param>
        /// <param name="numberOfMagnets"></param>
        /// <param name="rpmChangeNotificationThreshold"></param>
        public LinearHallEffectTachometer(IIODevice device, IPin inputPin, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                          ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F) :
            this(device.CreateDigitalInputPort(inputPin), type, numberOfMagnets, rpmChangeNotificationThreshold)
        {
        }
 public LinearHallEffectTachometer(GpioPin inputPort, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                   ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F)
 {
     setTachoMeter(inputPort, type,
                   numberOfMagnets, rpmChangeNotificationThreshold);
 }