Наследование: NativeEventDispatcher
Пример #1
0
 public RelayPort(Cpu.Pin pin, bool initialState, bool glitchFilter, Port.ResistorMode resistor, int timeout)
     : base(pin, initialState, glitchFilter, resistor)
 {
     currentstate = initialState;
     relayThread = new Thread(new ThreadStart(RelayLoop));
     relayThread.Start();
 }
Пример #2
0
        public AnalogInputPin (Cpu.AnalogChannel pin, double updateFrequency = DefaultUpdateFrequency)
            : base (updateFrequency)
		{
            input = new AnalogInput (pin, -1);

            var initialValue = input.Read ();
            
            Analog = AddPort ("Analog", Units.Ratio, initialValue);
        }
Пример #3
0
        public Switch(string switchName, FEZ_Pin.Interrupt IOport, string downScript, string upScript, Port.InterruptMode ActivateState)
        {
            SwitchName = switchName;
            IOPort = IOport;
            DownScript = downScript;
            UpScript = upScript;

            InterruptPort IntButton = new InterruptPort((Cpu.Pin)IOPort, false, Port.ResistorMode.PullUp, ActivateState);
            IntButton.OnInterrupt += new NativeEventHandler(this.Press);
        }
            public ButtonPad(GPIOButtonInputProvider sink, Button button, Cpu.Pin pin, Port.InterruptMode mode)
            {
                _sink     = sink;
                _button   = button;
                _buttonDevice = InputManager.CurrentInputManager.ButtonDevice;

                _port = new InterruptPort( pin, true, Port.ResistorMode.PullUp, mode );

                _port.OnInterrupt += new NativeEventHandler(this.Interrupt);
            }
Пример #5
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;
		}
Пример #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pin">Pin connected to the Ultrasonic sensor</param>
        /// <param name="glitchFilter">Input debouncing filter (default is true)</param>
        /// <param name="resistor">The resistor mode that establishes a default state for the port (default is Disabled)</param>
        /// <param name="period">Period for distance measure</param>
        public Ultrasonic(Cpu.Pin pin,
            bool glitchFilter = true,
            Port.ResistorMode resistor = Port.ResistorMode.Disabled,
            int period = 5000)
        {
            this.trPort = new TristatePort(pin, false, glitchFilter, resistor);
            this.period = period;

            // set duetime as period
            this.timer = new Timer(DistanceMeasureCallback, null, this.period, this.period);
        }
Пример #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pin">Pin connected to the PIR</param>
        /// <param name="glitchFilter">Input debouncing filter (default is true)</param>
        /// <param name="resistor">The resistor mode that establishes a default state for the port (default is Disabled)</param>
        /// <param name="interrupt">Defines the type of edge-change triggering the interrupt (default is InterruptEdgeBoth)</param>
        /// <param name="enabled">Intial Pir enable state</param>
        public Pir(Cpu.Pin pin,
            bool glitchFilter = true,
            Port.ResistorMode resistor = Port.ResistorMode.Disabled,
            Port.InterruptMode interrupt = Port.InterruptMode.InterruptEdgeBoth,
            bool enabled = true)
        {
            this.intPort = new InterruptPort(pin, glitchFilter, resistor, interrupt);
            this.intPort.OnInterrupt += new NativeEventHandler(intPort_OnInterrupt);

            this.Enabled = enabled;
        }
Пример #8
0
        /// <summary>
        /// PushButton constructor.
        /// </summary>
        /// <param name="pin">GPIO input pin</param>
        /// <param name="callback">Callback delegate</param>
        /// <param name="resmode">Resistor mode</param>
        public PushButton(Cpu.Pin pin, NativeEventHandler callback, Port.ResistorMode resmode)
        {
            Port.InterruptMode imode = resmode == Port.ResistorMode.PullUp ?
                Port.InterruptMode.InterruptEdgeLow : Port.InterruptMode.InterruptEdgeHigh;
            m_interruptPort = new InterruptPort(pin, true, resmode, imode);

            if (callback != null) {
                m_interruptPort.OnInterrupt += callback;
            }
            // default behavior is to always clear interrupt
            m_interruptPort.OnInterrupt += new NativeEventHandler((uint port, uint state, DateTime time) => {
                m_interruptPort.ClearInterrupt();
            });
        }
Пример #9
0
        private float temp; // Temperature

        #endregion Fields

        #region Constructors

        ///PullUpResistor pullUp)
        // Instantiated via derived class
        protected DhtSensor(Cpu.Pin pin1, Cpu.Pin pin2, Port.ResistorMode pullUp)
        {
            var resistorMode = (Port.ResistorMode)pullUp;

            portIn = new InterruptPort(pin2, false, resistorMode, Port.InterruptMode.InterruptEdgeLow);
            portIn.OnInterrupt += new NativeEventHandler(portIn_OnInterrupt);
            portIn.DisableInterrupt();  // Enabled automatically in the previous call

            portOut = new TristatePort(pin1, true, false, resistorMode);

            if (!CheckPins())
            {
                throw new InvalidOperationException("DHT sensor pins are not connected together.");
            }
        }
Пример #10
0
 /// <summary>
 /// Parte l'evento dell'interruzione quando il livello del segnale di interruzione è alto (ovvero quando il pulsante viene premuto).
 /// Se si usa un bottone diverso dal built-in, è necessario collegare delle resistenze di pull-down per l'interruttore .
 /// Lady Ada è un eccelente tutorial su questo argomento: http://www.ladyada.net/learn/arduino/lesson5.html
 /// </summary>
 /// <param name="pin">Un pin digitale collegato al pulsante.</param>
 /// <param name="intMode">Definisce il tipo di cambio di livello innescando l'evento dell'interrupt.</param>
 /// <param name="target">Il gestore di eventi viene invocato quando si verifica un interrupt.</param>
 /// <param name="resistorMode">Configurazione interna della resistenza di pullup.</param>
 /// <param name="glitchFilter">Ingresso filtro antirimbalzo.</param>
 public Pulsante(Cpu.Pin pin, Port.InterruptMode intMode = Port.InterruptMode.InterruptEdgeLow, 
                 NativeEventHandler target = null, Port.ResistorMode resistorMode = Port.ResistorMode.Disabled,
                 bool glitchFilter = true)
 {
     Input = new InterruptPort(pin, glitchFilter, resistorMode, intMode);
     if (target == null)
     {
         Input.OnInterrupt += InternalInterruptHandler;
     }
     else
     {
         Input.OnInterrupt += target;
     }
     Input.EnableInterrupt();
 }
 public static bool AttemptSetTristatePort(
     Cpu.Pin portID, bool initialState, bool glitchFilter, Port.ResistorMode resistor)
 {
     if (triPort == null)
     {
         try
         {
             triPort = new TristatePort(portID, initialState, glitchFilter, resistor);
             return true;
         }
         catch (Exception e)
         {
             Debug.Print("Setting triport request failed:\n" + e);
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Пример #12
0
 public IgnitionRelay(Cpu.Pin pin, bool initialState, bool glitchFilter, Port.ResistorMode resistor, Sensors.Tachometer tach)
     : base(pin, initialState, glitchFilter, resistor, -1)
 {
     Tachometer = tach;
 }
Пример #13
0
 /// <summary>
 /// Creates a new IRQ Port
 /// </summary>
 /// <param name="Pin">The pin number</param>
 /// <param name="GlitchFilter">Turns on or off the glitchfilter</param>
 /// <param name="ResistorMode">Selects the resistor mode</param>
 public IntegratedIRQ(Cpu.Pin Pin, bool GlitchFilter = false, Port.ResistorMode ResistorMode = Port.ResistorMode.Disabled)
 {
     this._Port = new InterruptPort(Pin, GlitchFilter, ResistorMode, Port.InterruptMode.InterruptEdgeBoth);
     this._Port.OnInterrupt += new NativeEventHandler(_Port_OnInterrupt);
 }
Пример #14
0
 public OneCoreInterruptPort(int cpuPort, bool initialState, Port.ResistorMode resistorMode, Port.InterruptMode interruptMode)
 {
     this.port = new InterruptPort((Cpu.Pin)cpuPort, initialState, resistorMode, interruptMode);
     this.port.OnInterrupt += this.InvokeOnOnInterrupt;
 }
Пример #15
0
 public StarterRelay(Cpu.Pin pin, bool initialState, bool glitchFilter, Port.ResistorMode resistor, int timeout, Sensors.Tachometer tach)
     : base(pin, initialState, glitchFilter, resistor, timeout)
 {
     Tachometer = tach;
 }
Пример #16
0
 /// <summary>
 /// Configures the pin as digital input
 /// </summary>
 /// <param name="GlitchFilter">Enables the glitch filter</param>
 /// <param name="Resistor">Enables resistor modes</param>
 public void ConfigureInput(bool GlitchFilter = false, Port.ResistorMode Resistor = Port.ResistorMode.Disabled)
 {
     this.ReleasePin();
     this._In = new InputPort(this.Pin, GlitchFilter, Resistor);
     this.Type = PortType.Input;
 }
 public void SetEdge(Cpu.Pin pin, Port.InterruptMode interruptMode)
 {
     String interrupt = "none";
     Console.WriteLine(interruptMode);
     switch (interruptMode)
     {
         case Port.InterruptMode.InterruptNone:
             break;
         case Port.InterruptMode.InterruptEdgeLow:
             interrupt = "falling";
             break;
         case Port.InterruptMode.InterruptEdgeLevelLow:
             throw new Exception();
         case Port.InterruptMode.InterruptEdgeLevelHigh:
             throw new Exception();
         case Port.InterruptMode.InterruptEdgeHigh:
             interrupt = "rising";
             break;
         case Port.InterruptMode.InterruptEdgeBoth:
             interrupt = "both";
             break;
     }
     File.WriteAllText(GPIO_PATH + "gpio" + ((int)pin) + "/edge", interrupt.ToLower());
 }
Пример #18
0
 public Button(FEZ_Pin.Digital pin, Port.ResistorMode mode = Port.ResistorMode.PullUp)
 {
     interrupt = new InputPort((Cpu.Pin) pin, false, mode);
     thread  = new Thread(Run);
     thread.Start();
 }
Пример #19
0
 /// <summary>
 /// Creates a new GPI Port
 /// </summary>
 /// <param name="Pin">The pin number</param>
 /// <param name="GlitchFilter">Turns on or off the glitchfilter</param>
 /// <param name="ResistorMode">Selects the resistor mode</param>
 public IntegratedGPI(Cpu.Pin Pin, bool GlitchFilter = false, Port.ResistorMode ResistorMode = Port.ResistorMode.Disabled)
 {
     this._Port = new InputPort(Pin, GlitchFilter, ResistorMode);
 }
Пример #20
0
 public void InitJackdepart(Cpu.Pin numInterrupt, Port.InterruptMode front)
 {
     InterruptPort jack = new InterruptPort((Cpu.Pin)numInterrupt, true, Port.ResistorMode.PullUp, front);
     jack.OnInterrupt += new NativeEventHandler(AttendreJack);
 }
Пример #21
0
 /// <summary>Creates a new Bidirectional port</summary>
 /// <param name="PortId">Pin identifier for the GPIO pin</param>
 /// <param name="InitialState">Initial state of the pin</param>
 /// <param name="GlitchFilter">flag to indicate if glitch filtering should be used</param>
 /// <param name="Resistor">Resistor mode to use if supported by underlying hardware</param>
 BidirectionalPort(Cpu.Pin PortId, bool InitialState, bool GlitchFilter, Port.ResistorMode Resistor)
     : this(new TristatePort(PortId, InitialState, GlitchFilter, Resistor))
 {
 }
Пример #22
0
 /// <summary>Constructs a new button definition</summary>
 /// <remarks>
 /// The resistor mode can influence the detection of an up/down press.
 /// Setting it incorrectly can cause unexpected results. Check with the
 /// hardware design schematics or documentation for best results. 
 /// </remarks>
 /// <param name="Button">The button value to assign to the GPIO pin.</param>
 /// <param name="AutoRepeat">Boolean flag to indicate if this button should auto-repeat</param>
 /// <param name="ResistorMode">
 /// Resistor mode to configure for the GPIO pin [may be ignored on hardware that
 /// does not support dynamic configuration ]
 /// </param>
 /// <param name="InterruptMode">
 /// Interrupt mode to configure for the GPIO pin [may be ignored on hardware that
 /// does not support dynamic configuration ]
 /// </param>
 public ButtonDefinition( Microsoft.SPOT.Hardware.Button Button
     , bool AutoRepeat
     , Port.ResistorMode ResistorMode
     , Port.InterruptMode InterruptMode
     )
 {
     this._Button = Button;
     this._Pin = Pin;
     this._AutoRepeat = AutoRepeat;
     this._ResistorMode = ResistorMode;
     this._InterruptMode = InterruptMode;
 }
        /// <summary>
        /// Create and open an instance of an input port,
        /// with embedded auto-repeat capabilities
        /// </summary>
        /// <param name="port">The I/O pin selected for the input</param>
        /// <param name="resistor">The resistor wired-logic easing</param>
        /// <param name="activeLevel">The level on which the input has to be considered active</param>
        public AutoRepeatInputPort(
            Cpu.Pin port,
            Port.ResistorMode resistor,
            bool activeLevel)
            : base(port, false, resistor)
        {
            this.ActiveLevel = activeLevel;

            //create, then start the working thread
            this._workingThread = new Thread(this.Worker);
            this._workingThread.Start();
        }
Пример #24
0
 public CPUInputPort(Cpu.Pin inputPin, bool glitchFilter, Port.ResistorMode resister)
 {
     this.inputPut = new InputPort(inputPin, glitchFilter, resister);
 }