/// <summary> /// Initializes a new instance of the <see cref="RHT03"/> class. /// </summary> /// <param name="socket">The <see cref="Hardware.Socket"/> that the RHT03 Sensor is connected to.</param> public RHT03(Hardware.Socket socket) { try { Hardware.CheckPins(socket, socket.Rst, socket.Int); _portIn = new InterruptPort(socket.Rst, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh); _portIn.OnInterrupt += portIn_OnInterrupt; _portIn.DisableInterrupt(); // Enabled automatically in the previous call _portOut = new TristatePort(socket.Int, false, false, Port.ResistorMode.PullUp); } catch (PinInUseException ex) { throw new PinInUseException(ex.Message); } _pollingTimer = new Timer(UpdateReadings, null, Timeout.Infinite, Timeout.Infinite); InitSensor(); if (SensorError != null) { SensorError(this, "RHT03 Sensor Initialization is complete."); } }
/// <summary> /// Default Constructor. /// </summary> /// <param name="socket">The <see cref="Hardware.Socket"/> that the SHT11 Click is inserted in.</param> public SHT11Click(Hardware.Socket socket) { try { Hardware.CheckPins(socket, socket.Sda, socket.Scl); _dataPort = new TristatePort(socket.Sda, false, true, Port.ResistorMode.PullDown) { Active = true }; _clkPort = new OutputPort(socket.Scl, false); // Reset the SHT11 click and throw DeviceInitialisationException on failure. This will also reset the SHT11 Click to Factory Default Settings in the StatusRegister. if (!Reset(ResetModes.Soft)) { throw new DeviceInitialisationException("Failed to initialize the SHT11 Click."); } _timer = new Timer(HeaterControlDelegate, null, -1, -1); AlarmThresholds = new AlarmThresholds(-40F, 123.8F, 0F, 100F); } // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to caller. catch (PinInUseException ex) { throw new PinInUseException(ex.Message); } }
static void MakePinOutput(TristatePort port) { if (!port.Active) { port.Active = true; } }
static void MakePinInput(TristatePort port) { if (port.Active) { port.Active = false; } }
public NativeDigitalIO(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, Gadgeteer.SocketInterfaces.ResistorMode resistorMode, Module module, Cpu.Pin cpuPin) { if (cpuPin == Cpu.Pin.GPIO_NONE) { throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalIO"); } this._port = new TristatePort(cpuPin, initialState, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); }
/// <summary> /// Internal dispose method /// </summary> /// <param name="disposing">Disposing managed resources</param> protected virtual void Dispose(bool disposing) { if (disposing) { this.timer.Dispose(); this.trPort.Dispose(); this.trPort = null; } }
/// <summary> /// Constructor /// </summary> /// <param name="data">Pin for DATA</param> /// <param name="clk">Pin for CLOCK</param> /// <param name="voltage">Voltage powering sensor</param> public SHT1X(Cpu.Pin data, Cpu.Pin clk, Voltage voltage) { this.clkPort = new OutputPort(clk, false); this.dataPort = new TristatePort(data, false, true, Port.ResistorMode.Disabled); // set as output this.dataPort.Active = true; this.voltage = voltage; }
public NativeDigitalIO(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module, Cpu.Pin cpuPin) { if (cpuPin == Cpu.Pin.GPIO_NONE) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalIO"); } _port = new TristatePort(cpuPin, initialState, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); }
/// <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); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socket">The socket for the digital input/output interface.</param> /// <param name="pin">The pin used by the digital input/output interface.</param> /// <param name="initialState"> /// The initial state to set on the digital input/output interface port. /// This value becomes effective as soon as the port is enabled as an output port. /// </param> /// <param name="glitchFilterMode"> /// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies /// whether to enable the glitch filter on this digital input/output interface. /// </param> /// <param name="resistorMode"> /// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the digital input/output interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself. /// </param> /// <param name="module">The module using this interface, which can be null if unspecified.</param> public DigitalIO(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module) { this.port = new TristatePort(socket.ReservePin(pin, module), initialState, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode); if (this.port == null) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Digital IO functionality. Please try a different socket."); } this.IOMode = IOModes.Input; }
/// <summary> /// Constructor. Needs to interrupt pins to be provided and linked together in Hardware. /// Blocking call for 1s to give sensor time to initialize. /// </summary> public DHT22(Cpu.Pin In, Cpu.Pin Out) { _dht22out = new TristatePort(Out, false, false, Port.ResistorMode.PullUp); _dht22in = new SignalCapture(In, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); if (_dht22out.Active == false) { _dht22out.Active = true; // Make tristateport "output" } _dht22out.Write(true); // "high up" (standby state) Thread.Sleep(1000); // 1s to pass the "unstable status" as per the documentation }
public SoftwareI2C(Cpu.Pin SCL, Cpu.Pin SDA, int clock) { start = false; timeOutTicks = (long)timeOut * TimeSpan.TicksPerMillisecond; // scl = new TristatePort(SCL, false, false, Port.ResistorMode.PullUp); sda = new TristatePort(SDA, false, false, Port.ResistorMode.PullUp); // scl and sda default to input, the next 2 lines make this explicit. MakePinInput(scl); MakePinInput(sda); //i2cSpeed = clock/ 1111???????????????? }
/// <summary> /// Constructor: initializes the Ping class /// </summary> /// <param name="pin">which pin the sensor is connected to</param> /// <param name="period">time between pulses in millisec, minimum of 1000</param> /// <param name="enabled">if true, start pinging immediately, otherwise wait for enable</param> public ParallaxPing(Cpu.Pin pin, int period, bool enabled) { _port = new TristatePort(pin, false, false, ResistorModes.Disabled); // Initially set as disabled. _timer = new ExtendedTimer(TakeMeasurement, null, Timeout.Infinite, period); // Store the current period Period = period; // Set the enabled state Enabled = enabled; }
// 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."); } }
public static void Main() { TristatePort tristatePort = new TristatePort(Cpu.Pin.GPIO_Pin4, false, //initial state false, //no glitch filter Port.ResistorMode.PullUp); Debug.Print("Port is inactive and acts as input port."); Debug.Print("Input = " + tristatePort.Read()); tristatePort.Active = true; Debug.Print("Port is active and acts as output port."); tristatePort.Write(true); }
private DaisyLink(Socket socket, DaisyLinkModule module) : base(socket, i2cDataPin, i2cClockPin, module) { Ready = false; this.Socket = socket; this.ReservedCount = 0; this.NodeCount = 0; // The link pin (port) is initialized as an input. It is only driven during initialization of the daisylinked modules. // Setting the initial state to false insures that the pin will always drive low when Active is set to true. daisyLinkCpuPin = socket.ReservePin(daisyLinkPin, module); daisyLinkResetPort = new TristatePort(daisyLinkCpuPin, false, false, Port.ResistorMode.PullUp); daisyLinkInterruptPort = null; }
// Instantiated via derived class protected DhtSensor(Cpu.Pin pin1, Cpu.Pin pin2, 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> /// IO Provider for SHT11 using GPIO pins /// </summary> /// <param name="Data">GPIO Pin for Data</param> /// <param name="Clock">GPIO Pin for Clock</param> public SHT11_GPIO_IOProvider(Cpu.Pin Data, Cpu.Pin Clock) { try { // Data DataPin = new TristatePort(Data, true, false, Port.ResistorMode.PullUp); if (DataPin.Active == true) { DataPin.Active = false; } // Clock ClockPin = new OutputPort(Clock, false); } catch { throw new Exception("SHT11_GPIO_IOProvider: Failed to initalize Clock and Data pins."); } }
public void InitializePortClass() { myInputPort = new InputPort(Cpu.Pin.GPIO_Pin0, false, Port.ResistorMode.Disabled); myInterruptPort = new InterruptPort(Cpu.Pin.GPIO_Pin1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); myOutputPort = new OutputPort(Cpu.Pin.GPIO_Pin12, false); myTristatePort = new TristatePort(Cpu.Pin.GPIO_Pin2, false, false, Port.ResistorMode.Disabled); }
public static void Main() { //Tristate Port init //Tristate Port set as input mode TristatePort tristate = new TristatePort((Cpu.Pin)(STM32.GPIO.GPIOD_15), false, false, Port.ResistorMode.PullUp); Debug.Print("Port is input port."); Thread.Sleep(1000); //Tristate Port set as output mode tristate.Active = true; Debug.Print("Port is output port"); //Tristate set as high when output mode tristate.Write(true); Debug.Print("Output is high!"); Thread.Sleep(5000); //Tristate set as low when output mode tristate.Write(false); Debug.Print("Output is low"); Thread.Sleep(1000); }
/// <summary> /// Sends a reset pulse on the daisylink chain. This resets all DaisyLink nodes to INIT state, that is, waiting for a DaisyLink message. /// </summary> /// <remarks> /// It is recommended to reboot the mainboard after calling this method because communication to the DaisyLink nodes will fail. /// </remarks> internal void SendResetPulse() { lock (portLock) { if (daisyLinkInterruptPort != null) { daisyLinkInterruptPort.DisableInterrupt(); daisyLinkInterruptPort.Dispose(); // Ask hardware drivers to unreserve this pin daisyLinkInterruptPort = null; } if (daisyLinkResetPort == null) { daisyLinkResetPort = new TristatePort(daisyLinkCpuPin, false, false, Port.ResistorMode.PullUp); } daisyLinkResetPort.Active = true; // Should drive the neighbor bus high Thread.Sleep(2); // 2 milliseconds is definitely more than 1 ms daisyLinkResetPort.Active = false; // Pull-downs should take the neighbor bus back low daisyLinkResetPort.Dispose(); // Remove this pin from the hardware's reserved pin list daisyLinkResetPort = null; } }
/// <summary>Creates a new port by wrapping an existing TristatePort</summary> /// <param name="Port">TristatePort to wrap</param> BidirectionalPort(TristatePort Port) { this.Port = Port; }
/// <summary> /// Initializes the driver for Sparkfun's Wearable Keypad /// </summary> /// <param name="Pin1">Pin P5.1 from the keypad</param> /// <param name="Pin2">Pin P5.2 from the keypad</param> /// <param name="Pin3">Pin P5.3 from the keypad</param> public WearableKeypad(Cpu.Pin Pin1, Cpu.Pin Pin2, Cpu.Pin Pin3) { this._Pin1 = new TristatePort(Pin1, false, false, Port.ResistorMode.PullUp); this._Pin2 = new TristatePort(Pin2, false, false, Port.ResistorMode.PullUp); this._Pin3 = new TristatePort(Pin3, false, false, Port.ResistorMode.PullUp); }
public ParallaxPingSimple(Cpu.Pin pin, int period, bool enabled) { _port = new TristatePort(pin, false, false, ResistorModes.Disabled); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket for this software I2C device interface.</param> /// <param name="sdaPin">The socket pin used for I2C data.</param> /// <param name="sclPin">The socket pin used for I2C clock.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> public SoftwareI2C(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, Module module) { // first check the socket is compatible if (sclPin > Socket.Pin.Five || sdaPin > Socket.Pin.Five) { socket.EnsureTypeIsSupported('Y', module); } else { socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, module); } if (ForceManagedSoftwareI2CImplementation || socket.NativeI2CWriteRead == null) { usingManaged = true; } // then see if we've already reserved the pins and got instances of the ports, otherwise do that. string sdaPinString = socket.ToString() + "___" + sdaPin; if (!ReservedSdaPinPorts.Contains(sdaPinString)) { Cpu.Pin sdaCpuPin = socket.ReservePin(sdaPin, module); if (usingManaged) { sdaPort = new TristatePort(sdaCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled); } ReservedSdaPinPorts.Add(sdaPinString, sdaPort); } else { sdaPort = (TristatePort)ReservedSdaPinPorts[sdaPinString]; } string sclPinString = socket.ToString() + "___" + sclPin; if (!ReservedSclPinPorts.Contains(sclPinString)) { Cpu.Pin sclCpuPin = socket.ReservePin(sclPin, module); if (usingManaged) { sclPort = new TristatePort(sclCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled); } ReservedSclPinPorts.Add(sclPinString, sclPort); } else { sclPort = (TristatePort)ReservedSclPinPorts[sclPinString]; } this.socket = socket; this.sdaPin = sdaPin; this.sclPin = sclPin; if (usingManaged) { lock (SoftwareI2CTimeoutList) { timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now SoftwareI2CTimeoutList.Add(this); if (timeoutThread == null) { threadExit = false; timeoutThread = new Thread(new ThreadStart(TimeoutHandler)); timeoutThread.Start(); } } } }
public TempSensor(Cpu.Pin Input) { IOPin = Input; Triport = new TristatePort(IOPin, false, false, Port.ResistorMode.Disabled); }