Inheritance: OutputPort
Exemplo n.º 1
0
        public WeatherShield1(Cpu.Pin clockPin, Cpu.Pin dataPin, Byte deviceAddress)
        {
            m_clockPort = new OutputPort(clockPin, false);
            m_dataPort = new TristatePort(dataPin, false, true, Port.ResistorMode.Disabled);
            m_deviceAddress = deviceAddress;

            resetConnection();
        }
        public UltrasonicSensor(Cpu.Pin pin)
        {
            Unit = DistanceUnits.m;
            OperatingTemperature = 20;
            InnerPort = new TristatePort(pin, false, false, Port.ResistorMode.Disabled);

            int initTick = TechnobottsRTC.Ticks;
            Thread.Sleep(50);
            Debug.Print("" + TechnobottsRTC.TickDiffSeconds(initTick));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public NativeDigitalIO(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module, Hardware.Cpu.Pin cpuPin)
        {
            if (cpuPin == Hardware.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 Hardware.TristatePort(cpuPin, initialState, glitchFilterMode == GlitchFilterMode.On, (Hardware.Port.ResistorMode)resistorMode);
        }
Exemplo n.º 5
0
 public SafeOutputPort(Cpu.Pin portId, bool initialState) 
 {
     if (0 == Native.Watchdog.RegisterSafeOutput((uint)portId))
     {
         _out = new TristatePort(portId, initialState, false, Port.ResistorMode.Disabled);
     }
     else
     {
         /* could not safely register this digital output */
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
 public SafeOutputPort(Cpu.Pin portId, bool initialState)
 {
     if (0 == Native.Watchdog.RegisterSafeOutput((uint)portId))
     {
         _out = new TristatePort(portId, initialState, false, Port.ResistorMode.Disabled);
     }
     else
     {
         /* could not safely register this digital output */
     }
 }
        public TemperatureHumiditySensorPro(BaseShield.DigitalPorts port)
            : base(port)
        {
            outputPort = new TristatePort(Pin1, true, false, Port.ResistorMode.PullUp);

            inputPort = new InterruptPort(Pin2, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            inputPort.DisableInterrupt();
            inputPort.OnInterrupt += new NativeEventHandler(inputPort_OnInterrupt);

            dataReceivedEvent = new AutoResetEvent(false);
        }
Exemplo n.º 9
0
        // 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; 
        }
Exemplo n.º 10
0
 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????????????????
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        private float temp; // Temperature

        #endregion Fields

        #region Constructors

        // 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 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;
     }
 }
Exemplo n.º 15
0
        // 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();
                    }
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>Creates a new port by wrapping an existing TristatePort</summary>
 /// <param name="Port">TristatePort to wrap</param>
 BidirectionalPort(TristatePort Port)
 {
     this.Port = Port;
 }
Exemplo n.º 17
0
 static void MakePinInput(TristatePort port)
 {
     if (port.Active)
         port.Active = false;
 }
 public NativeUSSensor(FEZ_Pin.Digital pin)
 {
     InnerPort = new TristatePort((Cpu.Pin)pin, false, false, Port.ResistorMode.PullDown);
 }
Exemplo n.º 19
0
 /// <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);
 }
Exemplo n.º 20
0
 /// <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;
     }
 }
 public UltrasonicSensor(Cpu.Pin pin)
 {
     Unit = DistanceUnits.m;
     OperatingTemperature = 20;
     InnerPort = new TristatePort(pin, false, false, Port.ResistorMode.Disabled);
 }
Exemplo n.º 22
0
 // Pass in the pin to which the rangefinder is attached.
 public PingTest(Cpu.Pin pin)
 {
     _port = new TristatePort(pin, false, false, ResistorModes.Disabled);
 }
Exemplo n.º 23
0
 public TempSensor(Cpu.Pin Input)
 {
     IOPin = Input;
     Triport = new TristatePort(IOPin, false, false, Port.ResistorMode.Disabled);
 }
Exemplo n.º 24
0
 //Pin on the microcontroller that is used to communicate with Ping))) Sensor
 public ParallaxPing(Cpu.Pin pin)
 {
     _pin = new TristatePort(pin, false, false, Port.ResistorMode.Disabled);
 }
Exemplo n.º 25
0
 static void MakePinOutput(TristatePort port)
 {
     if (!port.Active)
         port.Active = true;
 }
Exemplo n.º 26
0
            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 DisposeTristatePort()
        {
            if (triPort != null)
            {
                triPort.Dispose();
            }

            triPort = null;
        }