Main Site Documentation

Which source code repository should I use


#1

I’ve been dipping into the published source code repositories on by Codeplex and BitBucket and the GHI module libraries seem substantially different, even when they are both titled as V4.3.

For examples, Codeplex Extender.cs looks like this


using GTM = Gadgeteer.Modules;

namespace Gadgeteer.Modules.GHIElectronics
{
    // -- CHANGE FOR MICRO FRAMEWORK 4.2 --
    // If you want to use Serial, SPI, or DaisyLink (which includes GTI.SoftwareI2CBus), you must do a few more steps
    // since these have been moved to separate assemblies for NETMF 4.2 (to reduce the minimum memory footprint of Gadgeteer)
    // 1) add a reference to the assembly (named Gadgeteer.[interfacename])
    // 2) in GadgeteerHardware.xml, uncomment the lines under <Assemblies> so that end user apps using this module also add a reference.

    /// <summary>
    /// Represents a cable extender module which can also be used as a breakout module to interface with custom electronics, or a snooping module to monitor signals on individual pins.
    /// </summary>
    /// /// <example>
    /// <para>The following example uses a <see cref="Extender"/> object to break out individual pins on a Gadgeteer socket. 
    /// This module simply provides the interfaces available on the socket (GPIO, PWM, etc).
    /// </para>
    /// </example>
    public class Extender : GTM.Module
    {
        private Socket ExtenderSocket;

        /// <summary></summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Extender(int socketNumber)
        {
            ExtenderSocket = Socket.GetSocket(socketNumber, true, this, null);
        }

        /// <summary>
        /// The mainboard socket number which this Extender module is plugged into.
        /// </summary>
        public int ExtenderSocketNumber { get { return ExtenderSocket.SocketNumber; } }

        /// <summary>
        /// Returns a digital input interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <param name="glitchFilterMode">
        ///  A value from the <see cref="T:Microsoft.Gadgeteer.SocketInterfaces.GlitchFilterMode"/> enumeration that specifies 
        ///  whether to enable the glitch filter on this interface.
        /// </param>
        /// <param name="resistorMode">The resistor mode for the interface port.</param>
        /// <returns>The interface.</returns>
        /// <exception cref="System.Exception">
        ///  The specified pin has already been reserved on this module.
        /// </exception>
        public SocketInterfaces.DigitalInput SetupDigitalInput(Socket.Pin pin, SocketInterfaces.GlitchFilterMode glitchFilterMode, SocketInterfaces.ResistorMode resistorMode)
        {
            return SocketInterfaces.DigitalInputFactory.Create(ExtenderSocket, pin, glitchFilterMode, resistorMode, this);
        }

        /// <summary>
        /// Returns a digital output interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <param name="initialState">The initial state to place on the interface output port.</param>
        /// <returns>The interface.</returns>
        /// <exception cref="System.Exception">
        ///  The specified pin has already been reserved on this module.
        /// </exception>
        public SocketInterfaces.DigitalOutput SetupDigitalOutput(Socket.Pin pin, bool initialState)
        {
            return SocketInterfaces.DigitalOutputFactory.Create(ExtenderSocket, pin, initialState, this);
        }

        /// <summary>
        /// Returns a digital input/output interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <param name="initialState">
        ///  The initial state to place on the 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="T:Microsoft.Gadgeteer.SocketInterfaces.GlitchFilterMode"/> enumeration that specifies 
        ///  whether to enable the glitch filter on this interface.
        /// </param>
        /// <param name="resistorMode">The resistor mode for the interface port.</param>
        /// <returns>The interface.</returns>
        /// <exception cref="System.Exception">
        ///  The specified pin has already been reserved on this module.
        /// </exception>
        public SocketInterfaces.DigitalIO SetupDigitalIO(Socket.Pin pin, bool initialState, SocketInterfaces.GlitchFilterMode glitchFilterMode, SocketInterfaces.ResistorMode resistorMode)
        {
            return SocketInterfaces.DigitalIOFactory.Create(ExtenderSocket, pin, initialState, glitchFilterMode, resistorMode, this);
        }

        /// <summary>
        /// Returns an interrupt input interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <param name="glitchFilterMode">
        ///  A value from the <see cref="T:Microsoft.Gadgeteer.SocketInterfaces.GlitchFilterMode"/> enumeration that specifies 
        ///  whether to enable the glitch filter on this interface.
        /// </param>
        /// <param name="resistorMode">The resistor mode for the interface port.</param>
        /// <param name="interruptMode">The interrupt mode for the interface port.</param>
        /// <returns>The interface</returns>
        /// <exception cref="System.Exception">
        ///  The specified pin has already been reserved on this module.
        /// </exception>
        public SocketInterfaces.InterruptInput SetupInterruptInput(Socket.Pin pin, SocketInterfaces.GlitchFilterMode glitchFilterMode, SocketInterfaces.ResistorMode resistorMode, SocketInterfaces.InterruptMode interruptMode)
        {
            return SocketInterfaces.InterruptInputFactory.Create(ExtenderSocket, pin, glitchFilterMode, resistorMode, interruptMode, this);
        }

        /// <summary>
        /// Returns an analog input interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <returns>The interface.</returns>
        public SocketInterfaces.AnalogInput SetupAnalogInput(Socket.Pin pin)
        {
            return SocketInterfaces.AnalogInputFactory.Create(ExtenderSocket, pin, this);
        }

        // TODO:  Determine whether AnalogOutput should be added to Gadgeteer.SocketInterfaces


        /// <summary>
        /// Returns an analog output interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to assign to the interface.</param>
        /// <returns>The interface.</returns>
        public SocketInterfaces.AnalogOutput SetupAnalogOutput(Socket.Pin pin)
        {
            return SocketInterfaces.AnalogOutputFactory.Create(ExtenderSocket, pin, this);
        }

        /// <summary>
        ///  Returns an pulse width modulation (PWM) output interface associated with the specified pin on this module.
        /// </summary>
        /// <param name="pin">The pin to use for the PWM interface.</param>
        /// <returns>The PWM interface.</returns>
        public SocketInterfaces.PwmOutput SetupPWMOutput(Socket.Pin pin)
        {
            return SocketInterfaces.PwmOutputFactory.Create(ExtenderSocket, pin, false, this);
        }
    }
}

I know it says // – CHANGE FOR MICRO FRAMEWORK 4.2 – at the top but it’s from the 4.3 source.

However, BitBucket looks like this:


using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.SocketInterfaces;

namespace Gadgeteer.Modules.GHIElectronics
{
    /// <summary>
    /// An Extender module for Microsoft .NET Gadgeteer.
    /// </summary>
    public class Extender : GTM.Module
    {
        private Socket socketA;
        private Socket socketB;

        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Extender(int socketNumber)
        {
            this.socketA = Socket.GetSocket(socketNumber, true, this, null);

            this.socketB = Socket.SocketInterfaces.CreateUnnumberedSocket(socketNumber.ToString() + "-" + " Extender");
            this.socketB.SupportedTypes = this.socketA.SupportedTypes;

            for (int i = 3; i < 10; i++)
                this.socketB.CpuPins[i] = this.socketA.CpuPins[i];

            this.socketB.SerialPortName = this.socketA.SerialPortName;
            this.socketB.SPIModule = this.socketA.SPIModule;
            this.socketB.AnalogOutput5 = this.socketA.AnalogOutput5;
            this.socketB.AnalogInput3 = this.socketA.AnalogInput3;
            this.socketB.AnalogInput4 = this.socketA.AnalogInput4;
            this.socketB.AnalogInput5 = this.socketA.AnalogInput5;
            this.socketB.PWM7 = this.socketA.PWM7;
            this.socketB.PWM8 = this.socketA.PWM8;
            this.socketB.PWM9 = this.socketA.PWM9;
            this.socketB.AnalogInputIndirector = this.socketA.AnalogInputIndirector;
            this.socketB.AnalogOutputIndirector = this.socketA.AnalogOutputIndirector;
            this.socketB.DigitalInputIndirector = this.socketA.DigitalInputIndirector;
            this.socketB.DigitalIOIndirector = this.socketA.DigitalIOIndirector;
            this.socketB.DigitalOutputIndirector = this.socketA.DigitalOutputIndirector;
            this.socketB.I2CBusIndirector = this.socketA.I2CBusIndirector;
            this.socketB.InterruptIndirector = this.socketA.InterruptIndirector;
            this.socketB.PwmOutputIndirector = this.socketA.PwmOutputIndirector;
            this.socketB.SpiIndirector = this.socketA.SpiIndirector;
            this.socketB.SerialIndirector = this.socketA.SerialIndirector;

            Socket.SocketInterfaces.RegisterSocket(this.socketB);
        }

        /// <summary>
        /// Returns the socket number for socket on the module.
        /// </summary>
        public int ExtenderSocketB { get { return this.socketB.SocketNumber; } }

        /// <summary>
        /// Creates a digital input on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <param name="glitchFilterMode">The glitch filter mode for the interface.</param>
        /// <param name="resistorMode">The resistor mode for the interface.</param>
        /// <returns>The new interface.</returns>
        public GTI.DigitalInput CreateDigitalInput(Socket.Pin pin, GTI.GlitchFilterMode glitchFilterMode, GTI.ResistorMode resistorMode)
        {
            return GTI.DigitalInputFactory.Create(this.socketB, pin, glitchFilterMode, resistorMode, this);
        }

        /// <summary>
        /// Creates a digital output on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <param name="initialState">The initial state for the interface.</param>
        /// <returns>The new interface.</returns>
        public GTI.DigitalOutput CreateDigitalOutput(Socket.Pin pin, bool initialState)
        {
            return GTI.DigitalOutputFactory.Create(this.socketB, pin, initialState, this);
        }

        /// <summary>
        /// Creates a digital input/output on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <param name="initialState">The initial state for the interface.</param>
        /// <param name="glitchFilterMode">The glitch filter mode for the interface.</param>
        /// <param name="resistorMode">The resistor mode for the interface.</param>
        /// <returns>The new interface.</returns>
        public GTI.DigitalIO CreateDigitalIO(Socket.Pin pin, bool initialState, GTI.GlitchFilterMode glitchFilterMode, GTI.ResistorMode resistorMode)
        {
            return GTI.DigitalIOFactory.Create(this.socketB, pin, initialState, glitchFilterMode, resistorMode, this);
        }

        /// <summary>
        /// Creates an interrupt input on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <param name="glitchFilterMode">The glitch filter mode for the interface.</param>
        /// <param name="resistorMode">The resistor mode for the interface.</param>
        /// <param name="interruptMode">The interrupt mode for the interface.</param>
        /// <returns>The new interface.</returns>
        public GTI.InterruptInput CreateInterruptInput(Socket.Pin pin, GTI.GlitchFilterMode glitchFilterMode, GTI.ResistorMode resistorMode, GTI.InterruptMode interruptMode)
        {
            return GTI.InterruptInputFactory.Create(this.socketB, pin, glitchFilterMode, resistorMode, interruptMode, this);
        }

        /// <summary>
        /// Creates an analog input on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <returns>The new interface.</returns>
        public GTI.AnalogInput CreateAnalogInput(Socket.Pin pin)
        {
            return GTI.AnalogInputFactory.Create(this.socketB, pin, this);
        }

        /// <summary>
        /// Creates an analog output on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <returns>The new interface.</returns>
        public GTI.AnalogOutput CreateAnalogOutput(Socket.Pin pin)
        {
            return GTI.AnalogOutputFactory.Create(this.socketB, pin, this);
        }

        /// <summary>
        /// Creates a pwm output on the given pin.
        /// </summary>
        /// <param name="pin">The pin to create the interface on.</param>
        /// <returns>The new interface.</returns>
        public GTI.PwmOutput CreatePwmOutput(Socket.Pin pin)
        {
            return GTI.PwmOutputFactory.Create(this.socketB, pin, false, this);
        }
    }
}

Now, the latest SDK contains the methods seen in the BitBucket source, so is the Codeplex completely out of date now and should I just use the BitBucket source for everything?


#2

@ Jason - Bit Bucket is now the proper place to find all of our available sources. The various Code Plex repositories we have are no longer updated. The change is discussed more in https://www.ghielectronics.com/community/forum/topic?id=16470 We will be updating the Code Plex repositories to point to Bit Bucket soon.


#3

@ John - Thanks for the confirmation, and link to original article.

Related to the Extender, do you guys have an example of using it to extract two pins, one output and one input? I’ve had to use


OutputPort receiveClock;
InputPort receiveData;
OutputPort receiveLatch;

OutputPort transmitClock;
OutputPort transmitLatch;
OutputPort transmitData;

var ext = GT.Socket.GetSocket(8, true, extender, (string)null);

receiveClock = new OutputPort((Cpu.Pin)ext.CpuPins[3], false); // Pin 2
receiveData = new InputPort((Cpu.Pin)ext.CpuPins[4], false, Port.ResistorMode.Disabled); // Pin 7
receiveLatch = new OutputPort((Cpu.Pin)ext.CpuPins[5], false); // Pin 1

transmitClock = new OutputPort((Cpu.Pin)ext.CpuPins[6], false); // Pin 11
transmitLatch = new OutputPort((Cpu.Pin)ext.CpuPins[7], false); // Pin 12
transmitData = new OutputPort((Cpu.Pin)ext.CpuPins[8], false); // Pin 14

as I’ve really struggled using


extender.CreateDigitalInput(...);

and


extender.CreateDigitalOutput(...);

including #using statements and required references?

Many thanks.


#4

@ Jason - The below code should work:


using GT = Gadgeteer;

namespace GadgeteerApp1
{
    public partial class Program
    {
        void ProgramStarted()
        {
            var input = extender.CreateDigitalInput(GT.Socket.Pin.Three, GT.SocketInterfaces.GlitchFilterMode.Off, GT.SocketInterfaces.ResistorMode.Disabled);
            var output = extender.CreateDigitalOutput(GT.Socket.Pin.Four, false);
        }
    }
}

The references will be taken care of for you when you drag an extender onto the designer.


#5

@ John - Many thanks. I’ll give it a try and feedback.

J.