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(); }
private SpotDigitalInterrupt(Cpu.Pin pin, string name = null, Port.ResistorMode internalResistorMode = Port.ResistorMode.Disabled, Port.InterruptMode interruptMode = Port.InterruptMode.InterruptNone, int debounceMilliseconds = -1) { _interrupt = new InterruptPort(pin, false, internalResistorMode, interruptMode); _interrupt.OnInterrupt += ProxyToUserHandler; _name = name ?? "DigitalInterrupt-" + pin; _debounceMilliseconds = debounceMilliseconds; }
/// <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; }
/// <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); }
/// <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(); }
// pin1 > The identifier for the sensor's data bus port // pin2 > The identifier for the sensor's data bus port public DHT11Sensor(Cpu.Pin pin1, Cpu.Pin pin2, Port.ResistorMode resistormode) // : base(pin1, pin2, pullUp) { var resistorMode = resistormode; // Use Disabled for External 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."); } }
// Instantiated via derived class protected DhtSensor(Cpu.Pin pin1, Cpu.Pin pin2, Port.ResistorMode pullUp)///PullUpResistor 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."); } }
/// <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 PushButtonInputPort( Cpu.Pin port, Port.ResistorMode resistor, bool activeLevel) : base(port, false, resistor) { this.ActiveLevel = activeLevel; //consider the button enabled by default this.IsEnabled = true; //subscribe to the heartbeat provider PortHeartbeatBroker.Instance .Subscribe(this); }
/// <summary> /// The interrupt fires on a high edge when the button is pressed by default. /// If using a button other than the built-in one, you should connect pull-down resistors to the switch. /// Lady Ada has an excellent tutorial on this subject: http://www.ladyada.net/learn/arduino/lesson5.html /// </summary> /// <param name="pin">A digital pin connected to the actual push-button.</param> /// <param name="intMode">Defines the type of edge-change triggering the interrupt.</param> /// <param name="target">The event handler called when an interrupt occurs.</param> /// <param name="resistorMode">Internal pullup resistor configuration</param> /// <param name="glitchFilter">Input debouncing filter</param> public PushButton( Cpu.Pin pin, Port.InterruptMode intMode = Port.InterruptMode.InterruptEdgeBoth, 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(); }
/// <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; }
/// <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); }
/// <summary> /// Initialize a new instance of the <see cref="Dht22Sensor"/> class. /// </summary> /// <param name="pin1">The identifier for the sensor's data bus port.</param> /// <param name="pin2">The identifier for the sensor's data bus port.</param> /// <param name="pullUp">The pull-up resistor type.</param> /// <remarks> /// The ports identified by <paramref name="pin1"/> and <paramref name="pin2"/> /// must be wired together. /// </remarks> public Dht22Sensor(Cpu.Pin pin1, Cpu.Pin pin2, Port.ResistorMode pullUp) : base(pin1, pin2, pullUp) { // This constructor is intentionally left blank. }
/// <summary> /// Constructor for debugging state machine /// </summary> /// <param name="thePin"></param> /// <param name="resistorMode"></param> /// <param name="onVal"></param> /// <param name="lcd"></param> public DebouncedOnOffSwitch(Cpu.Pin thePin, Port.ResistorMode resistorMode, bool onVal, EnhancedEmoteLCD lcd) : this(thePin, resistorMode, onVal) { _lcd = lcd; ShowStateOnLcd(); }
/// <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); }
public CPUInputPort(Cpu.Pin inputPin, bool glitchFilter, Port.ResistorMode resister) { this.inputPut = new InputPort(inputPin, glitchFilter, resister); }
private SpotDigitalInput(Cpu.Pin pin, string name = null, Port.ResistorMode internalResistorMode = Port.ResistorMode.Disabled) { _input = new InputPort(pin, false, internalResistorMode); _name = name ?? "DigitalInput-" + pin; }
/// <summary> /// Constructor /// </summary> /// <param name="thePin"></param> /// <param name="resistorMode"></param> /// <param name="onVal">True for low-high, false for high-low</param> /// <param name="bounceTimeMs"></param> /// <param name="longPressWaitMs"></param> /// <exception cref="ArgumentOutOfRangeException"></exception> public DebouncedOnOffSwitch(Cpu.Pin thePin, Port.ResistorMode resistorMode, bool onVal, int bounceTimeMs, int longPressWaitMs) { Port = new InterruptPort(thePin, false, resistorMode, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeBoth); Port.OnInterrupt += DebounceSwitch_OnInterrupt; _onVal = onVal ? 1 : 0; var longPressWaitSpan = new TimeSpan(0, 0, 0, 0, longPressWaitMs); var stateMachine = new StateMachine(Port, _onVal, bounceTimeMs, longPressWaitSpan); stateMachine.ClickResult += stateMachine_ClickResult; #region Commented code // // Create a thread to handle bounces // var debounceThread = new Thread(() => // { // while (true) // { // // Wait on semaphore to start debouncing // _debounceSempahore.WaitOne(); // //_debounceSempahore.Reset(); // Set semaphore to blocked //#if DebugViaPrint // Debug.Print("Thread. State: " + DebounceStateDefs[(int)DebounceState] + "(" + DebounceState + ")"); //#endif // //var elapsedTime = (DateTime.Now - _lastEventTime).Milliseconds; // //if (elapsedTime < _bounceTimeMs) // //{ // // Thread.Sleep(_bounceTimeMs - elapsedTime); // // continue; // //} // Thread.Sleep(_bounceTimeMs); // // Set for appropriate wait state // switch (DebounceState) // { // case DebounceStates.WaitPress: // break; // case DebounceStates.DebouncePress: //#if DebugViaLcd // ShowStateOnLcd(); //#endif // DebounceState = DebounceStates.WaitRelease; //#if DebugViaPrint // Debug.Print("Thread. Change to WaitRelease"); //#endif // break; // case DebounceStates.WaitRelease: // break; // case DebounceStates.DebounceRelease: // DebounceState = DebounceStates.WaitPress; //#if DebugViaPrint // Debug.Print("Thread. Change to WaitPress"); //#endif //#if DebugViaLcd // ShowStateOnLcd(); //#endif // break; // default: // throw new ArgumentOutOfRangeException(); // } // } // }); // debounceThread.Start(); #endregion }
public IgnitionRelay(Cpu.Pin pin, bool initialState, bool glitchFilter, Port.ResistorMode resistor, Sensors.Tachometer tach) : base(pin, initialState, glitchFilter, resistor, -1) { Tachometer = tach; }
/// <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)) { }
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; }