Ejemplo n.º 1
0
        public DigitalInputPin (Cpu.Pin pin, bool glitchFilter = false)
		{
            port = new InterruptPort (pin, glitchFilter, HWPort.ResistorMode.Disabled, HWPort.InterruptMode.InterruptEdgeBoth);

            var initialValue = port.Read () ? 1 : 0;
            
            Output = AddPort ("Output", Units.Digital, initialValue);

            port.OnInterrupt += port_OnInterrupt;
		}
Ejemplo n.º 2
0
        public RotaryEncoder(Cpu.Pin aQuad, Cpu.Pin bQuad, Cpu.Pin momentaryPushbutton)
        {
            //Keyboard kb = Keyboard.Instance;
            //kb.Clear();
            Keyboard2.Clear();
            _aQuad = new InterruptPort(aQuad, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            _bQuad = new InterruptPort(bQuad, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            _momentaryPushbutton = new InterruptPort(momentaryPushbutton, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);

            if (_momentaryPushbutton.Read() == false)
            {
                using (var rtc = new RTC())
                {
                    rtc.ClearCalibration();
                }
            }

            _distanceTraveled = 0;
            _currentDirection = Direction.RotateLeft;
            _sequencePos = 1;
            _ready = true;

            try
            {
                _momentaryPushbutton.OnInterrupt += MomentaryPushbuttonOnInterrupt;
                //_momentaryPushbutton.EnableInterrupt();

                _aQuad.OnInterrupt += AQuadOnInterrupt;
                //_aQuad.EnableInterrupt();
                _bQuad.OnInterrupt += BQuadOnInterrupt;
                //_bQuad.EnableInterrupt();
            }
            catch
            {
                DebugHelper.Print("Button Interrupt Init Failed");
            }
        }
Ejemplo n.º 3
0
        public Axis(string axisID, Cpu.Pin stepPin, Cpu.Pin directionPin, Cpu.Pin limitSwitchPin, bool invertDirectionPinOutput = false)
        {
            this.ID = axisID;
            StepPort = new OutputPort(stepPin, false);
            DirectionPort = new OutputPort(directionPin, false);
            LimitReached = LimitSwitch.None;

            if (limitSwitchPin != Cpu.Pin.GPIO_NONE)
            {
                LimitSwitchPort = new InterruptPort(limitSwitchPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow);
                LimitSwitchPort.OnInterrupt += new NativeEventHandler(LimitSwitchPin_OnInterrupt);

                // Since we're sharing a port for the Min/Max limit switches on each axis, we can only determine which switch is tripped
                // while there is motion (based on direction). If we initialize the axis and find that the switch is tripped, then we don't
                // know which end it is at and the user will need to move the axis off of the switch before the machine can be homed.
                if (LimitSwitchPort.Read() == false) LimitReached = LimitSwitch.Unknown;
            }

            InvertDirectionPinOutput = invertDirectionPinOutput;

            Location = 0;
            LocationUnitsPerStep = 4;       //Should be overwritten when machine sets the resolution
            StepDirection = true;
        }
 public override bool Read()
 {
     return(_port.Read());
 }