예제 #1
0
        /// <summary>
        /// Constructs a new TouchC8 sensor.
        /// </summary>
        /// <param name="socketNumber">The socket number the sensor is plugged into.</param>
        public TouchC8(int socketNumber)
        {
            this.readBuffer    = new byte[1];
            this.writeBuffer   = new byte[2];
            this.addressBuffer = new byte[1];

            this.socket = GT.Socket.GetSocket(socketNumber, false, this, "I");

            this.reset = new GTI.DigitalOutput(this.socket, GT.Socket.Pin.Six, true, this);


            this.Reset();

            this.device = new GTI.I2CBus(this.socket, TouchC8.I2C_ADDRESS, TouchC8.I2C_CLOCK_RATE, this);

            this.interrupt            = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            this.interrupt.Interrupt += new GTI.InterruptInput.InterruptEventHandler(OnInterrupt);

            this.previousWheelDirection = (Direction)(-1);
            this.previousWheelPosition  = 0;
            this.previousWheelTouched   = false;
            this.previousButton1Touched = false;
            this.previousButton2Touched = false;
            this.previousButton3Touched = false;

            Thread.Sleep(250);

            this.ConfigureSPM();
        }
 private static void TestPinsPresent(Socket socket, int[] pins, char type)
 {
     foreach (int pin in pins)
     {
         if (socket.CpuPins[pin] == Socket.UnspecifiedPin) SocketRegistrationError(socket, "Cpu pin " + pin + " must be specified for socket of type " + type);
     }
 }
예제 #3
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public DisplayN18(int socketNumber)
            : base(WpfMode.Separate)
        {
            this.byteArray  = new byte[1];
            this.shortArray = new ushort[2];
            this.isBgr      = true;

            this.socket = Socket.GetSocket(socketNumber, true, this, null);
            this.socket.EnsureTypeIsSupported('S', this);

            this.resetPin     = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Three, false, this);
            this.backlightPin = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Four, true, this);
            this.rsPin        = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Five, false, this);

            this.spiConfig      = new GTI.SpiConfiguration(false, 0, 0, false, true, 12000);
            this.netMFSpiConfig = new SPI.Configuration(this.socket.CpuPins[6], this.spiConfig.IsChipSelectActiveHigh, this.spiConfig.ChipSelectSetupTime, this.spiConfig.ChipSelectHoldTime, this.spiConfig.IsClockIdleHigh, this.spiConfig.IsClockSamplingEdgeRising, this.spiConfig.ClockRateKHz, this.socket.SPIModule);
            this.spi            = GTI.SpiFactory.Create(this.socket, this.spiConfig, GTI.SpiSharing.Shared, this.socket, Socket.Pin.Six, this);

            this.Reset();

            this.ConfigureDisplay();

            base.OnDisplayConnected("Display N18", 128, 160, DisplayOrientation.Normal, null);

            this.Clear();
        }
예제 #4
0
        private void Initialize(GT.Socket socket)
        {
            spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, 4000);
            spi       = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this);

            ClearBuffers();
        }
예제 #5
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
        public SPlus(int socketNumber, int socketNumberTwo)
        {
            this.sSocket = Socket.GetSocket(socketNumber, true, this, null);
            this.ySocket = Socket.GetSocket(socketNumberTwo, true, this, null);

            this.sSocket.EnsureTypeIsSupported('S', this);
            this.ySocket.EnsureTypeIsSupported('Y', this);

            this.sx1 = Socket.SocketInterfaces.CreateUnnumberedSocket(socketNumber.ToString() + "-" + socketNumberTwo.ToString() + " SPlus1");
            this.sx2 = Socket.SocketInterfaces.CreateUnnumberedSocket(socketNumber.ToString() + "-" + socketNumberTwo.ToString() + " SPlus2");

            this.sx1.SupportedTypes = this.sx2.SupportedTypes = new char[2] {
                'S', 'X'
            };

            for (int i = 3; i <= 6; i++)
            {
                this.sx1.CpuPins[i] = this.sSocket.CpuPins[i];
                this.sx2.CpuPins[i] = this.ySocket.CpuPins[i];
            }

            this.sx1.CpuPins[7] = this.sx2.CpuPins[7] = this.sSocket.CpuPins[7];
            this.sx1.CpuPins[8] = this.sx2.CpuPins[8] = this.sSocket.CpuPins[8];
            this.sx1.CpuPins[9] = this.sx2.CpuPins[9] = this.sSocket.CpuPins[9];
            this.sx1.SPIModule  = this.sx2.SPIModule = this.sSocket.SPIModule;

            Socket.SocketInterfaces.RegisterSocket(this.sx1);
            Socket.SocketInterfaces.RegisterSocket(this.sx2);
        }
예제 #6
0
            public InteropI2CBus(GT.Socket socket, GT.Socket.Pin sdaPin, GT.Socket.Pin sclPin, ushort address, int clockRateKHz, GTM.Module module)
            {
                this.Address      = address;
                this.ClockRateKHz = clockRateKHz;

                this.softwareBus = new SoftwareI2CBus(socket.CpuPins[(int)sclPin], socket.CpuPins[(int)sdaPin]);
            }
 private static void TestPinsPresent(Socket socket, int[] pins, char type)
 {
     for (int i = 0; i < pins.Length; i++)
     {
         if (socket.CpuPins[pins[i]] == Socket.UnspecifiedPin) SocketRegistrationError(socket, "Cpu pin " + pins[i] + " must be specified for socket of type " + type);
     }
 }
 public InteropI2CBus(GT.Socket socket, GT.Socket.Pin sdaPin, GT.Socket.Pin sclPin, ushort address, int clockRateKHz, GTM.Module module)
 {
     this.sdaPin       = socket.CpuPins[(int)sdaPin];
     this.sclPin       = socket.CpuPins[(int)sclPin];
     this.Address      = address;
     this.ClockRateKHz = clockRateKHz;
 }
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public LightningDetectorSPI(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            var socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('S', this);

            _socket = socket;

            socket.ReservePin(Socket.Pin.Three, this);
            socket.ReservePin(Socket.Pin.Six, this);
            socket.ReservePin(Socket.Pin.Seven, this);
            socket.ReservePin(Socket.Pin.Eight, this);
            socket.ReservePin(Socket.Pin.Nine, this);

            // from as3935 datasheet Chip Select (active low)
            // data are sampled on the falling edge of SCLK (CPHA=1)

            spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, false, 2000);

            spi = GTI.SpiFactory.Create(socket, spiConfig, GTI.SpiSharing.Exclusive, socket, Socket.Pin.Six, this);

            Initialize();
        }
예제 #10
0
 public BreakOut()
 {
     socket = GT.Socket.GetSocket(9, true, null, null);
     //this.leftBackwardSensor = GT.SocketInterfaces.DigitalInputFactory.Create(socket, GT.Socket.Pin.Nine, GT.SocketInterfaces.GlitchFilterMode.On, GT.SocketInterfaces.ResistorMode.Disabled, null);
     this.leftForwardSensor  = GT.SocketInterfaces.DigitalInputFactory.Create(socket, GT.Socket.Pin.Four, GT.SocketInterfaces.GlitchFilterMode.On, GT.SocketInterfaces.ResistorMode.Disabled, null);
     this.rightForwardSensor = GT.SocketInterfaces.DigitalInputFactory.Create(socket, GT.Socket.Pin.Five, GT.SocketInterfaces.GlitchFilterMode.On, GT.SocketInterfaces.ResistorMode.Disabled, null);
     //this.rightBackwardSensor = GT.SocketInterfaces.DigitalInputFactory.Create(socket, GT.Socket.Pin.Five, GT.SocketInterfaces.GlitchFilterMode.On, GT.SocketInterfaces.ResistorMode.Disabled, null);
 }
예제 #11
0
 // This example implements a driver in managed code for a simple Gadgeteer module.  This module uses a
 // single GTI.InterruptInput to interact with a button that can be in either of two states: pressed or released.
 // The example code shows the recommended code pattern for exposing a property (IsPressed).
 // The example also uses the recommended code pattern for exposing two events: Pressed and Released.
 // The triple-slash "///" comments shown will be used in the build process to create an XML file named
 // GTM.BrainardTechnologies.MAX31865. This file will provide IntelliSense and documentation for the
 // interface and make it easier for developers to use the MAX31865 module.
 // -- CHANGE FOR MICRO FRAMEWORK 4.2 and higher --
 // If you want to use Serial, SPI, or DaisyLink (which includes GTI.SoftwareI2C), 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.
 // Note: A constructor summary is auto-generated by the doc builder.
 /// <summary></summary>
 /// <param name="socketNumber">The socket that this module is plugged in to.</param>
 /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
 public MAX31865(int socketNumber)
 {
     // This finds the Socket instance from the user-specified socket number.
     // This will generate user-friendly error messages if the socket is invalid.
     // If there is more than one socket on this module, then instead of "null" for the last parameter,
     // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
     _socket = Socket.GetSocket(socketNumber, true, this, null);
     _socket.EnsureTypeIsSupported('S', this);
 }
예제 #12
0
        // Interrupt event
        //public event InterruptHandler InterruptEvent;
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public IO60P16(int socketNumber)
        {
            _socket = Socket.GetSocket(socketNumber, true, this, null);
            char[] types = new char[] { 'X', 'Y' };
            _socket.EnsureTypeIsSupported(types, this);

            i2c = new GHIOSH.Hardware.SoftwareI2CBus((Cpu.Pin)_socket.CpuPins[4], (Cpu.Pin)_socket.CpuPins[5]);
            i2cdevice = i2c.CreateI2CDevice(DEV_ADDR, 100);
        }
예제 #13
0
        // This example implements a driver in managed code for a simple Gadgeteer module.  This module uses a
        // single GTI.InterruptInput to interact with a button that can be in either of two states: pressed or released.
        // The example code shows the recommended code pattern for exposing a property (IsPressed).
        // The example also uses the recommended code pattern for exposing two events: Pressed and Released.
        // The triple-slash "///" comments shown will be used in the build process to create an XML file named
        // GTM.BrainardTechnologies.MAX31865. This file will provide IntelliSense and documentation for the
        // interface and make it easier for developers to use the MAX31865 module.

        // -- CHANGE FOR MICRO FRAMEWORK 4.2 and higher --
        // If you want to use Serial, SPI, or DaisyLink (which includes GTI.SoftwareI2C), 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.

        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
        public MAX31865(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            _socket = Socket.GetSocket(socketNumber, true, this, null);
            _socket.EnsureTypeIsSupported('S', this);
        }
예제 #14
0
 public Sim900Modem(int port, GTM.Display_HD44780 display)
 {
     this.display = display;
     socket = GT.Socket.GetSocket(port, true, null, null);
     powerPin = new GTI.DigitalOutput(socket, GT.Socket.Pin.Three, false, null);
     serial = new System.IO.Ports.SerialPort("COM2", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
     serial.ReadTimeout = 1000;
     serial.Open();
     bufferd = new byte[32];
 }
예제 #15
0
        bool NativeI2CWriteRead(GT.Socket socket, GT.Socket.Pin sda, GT.Socket.Pin scl, byte address, byte[] write, int writeOffset, int writeLen, byte[] read, int readOffset, int readLen, out int numWritten, out int numRead)
        {
            // implement this method if you support NativeI2CWriteRead for faster DaisyLink performance
            // otherwise, the DaisyLink I2C interface will be supported in Gadgeteer.dll in managed code.

            return(GHI.OSHW.Hardware.SoftwareI2CBus.DirectI2CWriteRead(socket.CpuPins[(int)scl], socket.CpuPins[(int)sda], 100, address, write, writeOffset, writeLen, read, readOffset, readLen, out numWritten, out numRead));

            //numRead = 0;
            //numWritten = 0;
            //return false;
        }
예제 #16
0
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public FEZtive(int socketNumber)
        {
            _socket = Socket.GetSocket(socketNumber, true, this, null);

            _socket.EnsureTypeIsSupported('S', this);

            Red   = new Color(127, 0, 0);
            Blue  = new Color(0, 0, 127);
            Green = new Color(0, 127, 0);
            White = new Color(127, 127, 127);
            Black = new Color(0, 0, 0);
        }
예제 #17
0
        // The triple-slash "///" comments shown will be used in the build process to create an XML file named
        // GTM.DevhammerEnterprises.StarBoard. This file will provide IntelliSense and documentation for the
        // interface and make it easier for developers to use the StarBoard module.

        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public StarBoard(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            socket = Socket.GetSocket(socketNumber, true, this, "S");
            socket.EnsureTypeIsSupported('S', this);

            int NumberOfLeds = 13;

            // Initialize the strip : the SPI_Module of the current socket and 800Khz model and using the linear human perceived luminosity PWM conversion factor of 2.25
            MyWS2811Strip = new WS2811Led(NumberOfLeds, socket.SPIModule, WS2811Led.WS2811Speed.S800KHZ, 2.25);
        }
예제 #18
0
파일: Program.cs 프로젝트: Sarcares/PL_FEZ3
// -------------------------------- Sensori -------------------------------- //
        private void InitSensors()
        {
            Mainboard.SetDebugLED(true);
            Gadgeteer.Socket socket = Gadgeteer.Socket.GetSocket(8, true, null, null);
            buzzer = new PWM(Cpu.PWMChannel.PWM_4, 1000, 0.5, false);
            buzzer.Stop();
            orizzontal_mov         = extender.CreatePwmOutput(Gadgeteer.Socket.Pin.Seven);
            vertical_mov           = extender.CreatePwmOutput(Gadgeteer.Socket.Pin.Nine);
            current_orizzontal_pos = 0.075;
            current_vertical_pos   = 0.075;
            orizzontal_mov.Set(50, current_orizzontal_pos);
            Thread.Sleep(2000);
            vertical_mov.Set(50, current_vertical_pos);
        }
예제 #19
0
        void InputThread()
        {
            GT.Socket socket = GT.Socket.GetSocket(5, true, null, null);
            //Mainboard.TurnOnLed(6);

            DigitalInput p7 = DigitalInputFactory.Create(socket, GT.Socket.Pin.Three, GlitchFilterMode.Off, ResistorMode.PullDown, breakout);
            //Mainboard.TurnOnLed(7);

            DigitalInput p8 = DigitalInputFactory.Create(socket, GT.Socket.Pin.Four, GlitchFilterMode.Off, ResistorMode.PullDown, breakout);
            //Mainboard.TurnOnLed(8);

            DigitalInput p9 = DigitalInputFactory.Create(socket, GT.Socket.Pin.Five, GlitchFilterMode.Off, ResistorMode.PullDown, breakout);

            //Mainboard.TurnOnLed(9);

            while (true)
            {
                int    spd = 50;
                string cmd = GetCommand(p7, p8, p9);

                //Debug.Print("CMD " + cmd);
                switch (cmd)
                {
                case "STOP":
                    Mainboard.SetMotorSpeed(0, 0);
                    break;

                case "GO":
                    Mainboard.SetMotorSpeed(spd, spd);
                    break;

                case "LEFT":
                    Mainboard.SetMotorSpeed(spd, -spd);
                    break;

                case "RIGHT":
                    Mainboard.SetMotorSpeed(-spd, spd);
                    break;

                case "BACK":
                    Mainboard.SetMotorSpeed(-spd, -spd);
                    break;

                default:
                    Mainboard.SetMotorSpeed(0, 0);
                    break;
                }
            }
        }
 public InizializeDHT()
 {
     this.socket    = GT.Socket.GetSocket(14, true, null, null);
     this.pin6in    = socket.CpuPins[6];
     this.pin7out   = socket.CpuPins[7];
     this.dhtSensor = new Dht11Sensor(pin6in, pin7out, Port.ResistorMode.PullUp);
     this.counterTm = 0;
     this.counterHm = 0;
     this.counterMm = 0;
     this.counterLs = 0;
     this._last_hm  = new HumidityMisure(0, "FAIL");
     this._last_mm  = new MoistureMisure(0, "FAIL");
     this._last_tm  = new TemperatureMisure(0, "FAIL");
     this._last_ls  = new LightMisure(0, "FAIL");
 }
예제 #21
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public PresenceSensor(int socketNumber)
        {
            GT.Socket socket = GT.Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this);

            // These calls will throw GT.Socket.InvalidSocketException if a pin conflict or error is encountered
            this.input = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingEdge, this);
            //this.input.Interrupt += (this._input_Interrupt);
            this.led = GTI.DigitalOutputFactory.Create(socket, GT.Socket.Pin.Four, false, this);

            LEDMode = LEDModes.Off;
            t       = new Thread(monitoringLastTime);
            t.Start();
        }
예제 #22
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
        public TripWireModule(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            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;

            TripWire1 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire2 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Four, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire3 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Five, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire4 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Six, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire5 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Seven, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire6 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Eight, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            TripWire7 = GTI.DigitalInputFactory.Create(socketA, Socket.Pin.Nine, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
        }
예제 #23
0
            public AnalogSampler(string id, GT.Socket socket_A, SamplerBag samplers)
            {
                _id = id;
                _analogInputPin3 = new GT.Interfaces.AnalogInput(socket_A, GT.Socket.Pin.Three, null);
                _analogInputPin4 = new GT.Interfaces.AnalogInput(socket_A, GT.Socket.Pin.Four, null);
                _analogInputPin5 = new GT.Interfaces.AnalogInput(socket_A, GT.Socket.Pin.Five, null);

                _analogInputPin3.Active = true;
                _analogInputPin4.Active = true;
                _analogInputPin5.Active = true;

                _pin3ProportionSampler = new DoubleSampler(null, _id + "_pin3_proportion");
                samplers.Add(_pin3ProportionSampler);

                _pin4ProportionSampler = new DoubleSampler(null, _id + "_pin4_proportion");
                samplers.Add(_pin4ProportionSampler);

                _pin5ProportionSampler = new DoubleSampler(null, _id + "_pin5_proportion");
                samplers.Add(_pin5ProportionSampler);
            }
        /// <summary>
        /// Creates a ControlRelays object connected to the specified socket number.
        /// </summary>
        /// <param name="socketNumber"></param>
        public ControlRelays(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            try
            {
                socket = Socket.GetSocket(socketNumber, true, this, "XY");
                relay1 = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this);
                relay2 = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this);

                Relay1 = false;
                Relay2 = false;
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #25
0
        public static void setup()
        {
            GT.Socket socket  = GT.Socket.GetSocket(14, true, null, null);
            Cpu.Pin   pin3in  = socket.CpuPins[4];
            Cpu.Pin   pin8out = socket.CpuPins[5];

            /*   D2     D3    */
            Dht11Sensor dhtSensor = new Dht11Sensor(pin3in, pin8out, Port.ResistorMode.PullUp);

            int cnt = 0; /* just a simple counter */

            Debug.Print("----------------------------------------");

            /* loopa e ngjarjeve dhe funksionet */
            while (true)
            {
                cnt++;

                if (dhtSensor.Read())
                {
                    Debug.Print(cnt.ToString() + ":");
                    Debug.Print("----------------------------------------");

                    Debug.Print("Temp Celsius   = " + dhtSensor.Temperature.ToString("F1") + "°C");
                    Debug.Print("Temp Kelvin    = " + dhtSensor.TemperatureKelvin.ToString("F1") + "°K");
                    Debug.Print("Temp Farenhein = " + dhtSensor.TemperatureFarenheit.ToString("F1") + "°F");
                    Debug.Print(String.Empty);

                    Debug.Print("Humidity       = " + dhtSensor.Humidity.ToString("F1") + " %");
                    Debug.Print(String.Empty);

                    Thread.Sleep(2000);
                }
                else
                {
                    /* first time always fail than it correct itself */
                    Debug.Print("DHT sensor Read() failed");
                    Thread.Sleep(2000);
                }
            }
        }
예제 #26
0
        void ProgramStarted()
        {
            /**
             * Iniciliza los modulos conectados con Gadgeteer
             */

            Socket10 = GT.Socket.GetSocket(10, true, null, null);

            vibrationControl = new GT.Interfaces.DigitalOutput(Socket10, GT.Socket.Pin.Four, false, null);

            analogPressureMeter = new GT.Interfaces.AnalogInput(Socket10, GT.Socket.Pin.Three, null);
            analogFlexorMeter   = new GT.Interfaces.AnalogInput(Socket10, GT.Socket.Pin.Five, null);


            matrix = new Adafruit_BicolorMatrix(Socket10);

            graphics = new Graphics(matrix);

            data_manager = new DataManager(sdCard, graphics);

            peripheral_manager = new PeripheralManager(graphics, vibrationControl, analogPressureMeter, analogFlexorMeter);

            /**
             * Determina un timer y una funcion que se ejecuta cada 100 millis
             */
            intervalTimer       = new GT.Timer(100);
            intervalTimer.Tick += new GT.Timer.TickEventHandler(TimerTick);
            intervalTimer.Start();

            /*
             * Se inicializan las variables
             **/

            is_being_pressed = false;
            pressed_times    = 0;

            cycles          = 0;
            vibrationCycles = 0;

            Debug.Print("Program Started!!");
        }
예제 #27
0
        // This method is run when the mainboard is powered up or reset.
        void ProgramStarted()
        {
            /*******************************************************************************************
            *  Modules added in the Program.gadgeteer designer view are used by typing
            *  their name followed by a period, e.g.  button.  or  camera.
            *
            *  Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
            *   button.ButtonPressed +=<tab><tab>
            *
            *  If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
            *   GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
            *   timer.Tick +=<tab><tab>
            *   timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            Socket10       = GT.Socket.GetSocket(10, true, null, null);
            AI_ForceSensor = new GTI.AnalogInput(Socket10, GT.Socket.Pin.Five, null);

            sdCard.SDCardMounted   += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
            sdCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(sdCard_SDCardUnmounted);

            is_being_pressed = false;
            pressed_times    = 0;
            cycles           = 0;

            currentFace = 0;

            sdCard.MountSDCard();
            System.Threading.Thread.Sleep(intervalMillis);

            rootDirectory = sdCard.GetStorageDevice().RootDirectory;

            _pollingTimer       = new GT.Timer(intervalMillis);
            _pollingTimer.Tick += new GT.Timer.TickEventHandler(TimerTick);
            _pollingTimer.Start();
        }
예제 #28
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Bluetooth(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            GT.Socket socket = GT.Socket.GetSocket(socketNumber, true, this, null);

            this.reset      = new GTI.DigitalOutput(socket, GT.Socket.Pin.Six, false, this);
            this.statusInt  = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.serialPort = new GTI.Serial(socket, 38400, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, this);

            //this.statusInt.Interrupt += new GTI.InterruptInput.InterruptEventHandler(statusInt_Interrupt);
            this.serialPort.ReadTimeout = Timeout.Infinite;
            this.serialPort.Open();

            Thread.Sleep(5);
            this.reset.Write(true);

            readerThread = new Thread(new ThreadStart(runReaderThread));
            readerThread.Start();
            Thread.Sleep(500);
        }
예제 #29
0
파일: DisplayS22_43.cs 프로젝트: radtek/MFE
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
        public DisplayS22(int socketNumber)//, int socketNumberTwo)
            : base(DisplayModule.WpfMode.Separate)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('S', this);

            socket.ReservePin(Socket.Pin.Three, this); // reset
            socket.ReservePin(Socket.Pin.Four, this);  // back light
            socket.ReservePin(Socket.Pin.Five, this);  // D/C
            socket.ReservePin(Socket.Pin.Six, this);   // CS
            socket.ReservePin(Socket.Pin.Seven, this); // MOSI
            socket.ReservePin(Socket.Pin.Eight, this); // MISO
            socket.ReservePin(Socket.Pin.Nine, this);  // SCK

            /*
             * Serial peripheral interface (SPI).
             * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line.
             * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.
             */

            pinReset     = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Three, false, this); // pin 3
            pinBacklight = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Four, false, this);  // pin 4
            pinDC        = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Five, false, this);  // pin 5

            spiConfig      = new GTI.SpiConfiguration(false, 0, 0, false, true, spiSpeed);
            netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.IsChipSelectActiveHigh, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.IsClockIdleHigh, spiConfig.IsClockSamplingEdgeRising, spiConfig.ClockRateKHz, socket.SPIModule);
            spi            = GTI.SpiFactory.Create(socket, spiConfig, GTI.SpiSharing.Shared, socket, Socket.Pin.Six, this);

            Reset();
            ConfigureDisplay();
            Clear();
            SetBacklight(true);
        }
예제 #30
0
        private uint spiSpeed = 8000; // kHz

        #endregion Fields

        #region Constructors

        //, int socketNumberTwo)
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param>
        public DisplayS22(int socketNumber)
            : base(WPFRenderOptions.Intercept)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('S', this);

            socket.ReservePin(Socket.Pin.Three, this); // reset
            socket.ReservePin(Socket.Pin.Four, this); // back light
            socket.ReservePin(Socket.Pin.Five, this); // D/C
            socket.ReservePin(Socket.Pin.Six, this); // CS
            socket.ReservePin(Socket.Pin.Seven, this); // MOSI
            socket.ReservePin(Socket.Pin.Eight, this); // MISO
            socket.ReservePin(Socket.Pin.Nine, this); // SCK

            /*
             * Serial peripheral interface (SPI).
             * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line.
             * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.
            */

            pinReset = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3
            pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this); // pin 4
            pinDC = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this); // pin 5

            spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, spiSpeed);
            //netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule);
            spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this);

            Reset();
            ConfigureDisplay();
            Clear();
            SetBacklight(true);
        }
예제 #31
0
        /// <summary>Constructor</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public DisplayN18(int socketNumber) : base(WPFRenderOptions.Intercept)
        {
            this.byteArray  = new byte[1];
            this.shortArray = new ushort[2];

            this.socket = Socket.GetSocket(socketNumber, true, this, null);
            this.socket.EnsureTypeIsSupported('S', this);

            this.resetPin     = new GTI.DigitalOutput(this.socket, Socket.Pin.Three, false, this);
            this.backlightPin = new GTI.DigitalOutput(this.socket, Socket.Pin.Four, false, this);
            this.rs           = new GTI.DigitalOutput(this.socket, Socket.Pin.Five, false, this);

            this.spiConfig      = new GTI.SPI.Configuration(false, 0, 0, false, true, 12000);
            this.netMFSpiConfig = new SPI.Configuration(this.socket.CpuPins[6], this.spiConfig.ChipSelectActiveState, this.spiConfig.ChipSelectSetupTime, this.spiConfig.ChipSelectHoldTime, this.spiConfig.ClockIdleState, this.spiConfig.ClockEdge, this.spiConfig.ClockRateKHz, this.socket.SPIModule);
            this.spi            = new GTI.SPI(this.socket, this.spiConfig, GTI.SPI.Sharing.Shared, this.socket, Socket.Pin.Six, this);

            this.Reset();

            this.ConfigureDisplay();

            this.Clear();

            this.SetBacklight(true);
        }
예제 #32
0
        /// <summary>Constructs a new TouchL12 sensor.</summary>
        /// <param name="socketNumber">The socket number the sensor is plugged into.</param>
        public TouchL12(int socketNumber)
        {
            this.readBuffer    = new byte[1];
            this.writeBuffer   = new byte[2];
            this.addressBuffer = new byte[1];

            this.socket = GT.Socket.GetSocket(socketNumber, false, this, "I");
            this.reset  = GTI.DigitalOutputFactory.Create(this.socket, GT.Socket.Pin.Six, true, this);

            this.Reset();

            this.device = GTI.I2CBusFactory.Create(this.socket, TouchL12.I2C_ADDRESS, TouchL12.I2C_CLOCK_RATE, this);

            this.interrupt            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            this.interrupt.Interrupt += this.OnInterrupt;

            this.previousSliderDirection = (Direction)(-1);
            this.previousSliderPosition  = 0;
            this.previousSliderTouched   = false;

            Thread.Sleep(250);

            this.ConfigureSPM();
        }
예제 #33
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public NRF24(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('S', this);

            socket.ReservePin(Socket.Pin.Three, this); // IRQ
            socket.ReservePin(Socket.Pin.Five, this); // CSN
            socket.ReservePin(Socket.Pin.Six, this); // CE
            socket.ReservePin(Socket.Pin.Seven, this); // MOSI
            socket.ReservePin(Socket.Pin.Eight, this); // MISO
            socket.ReservePin(Socket.Pin.Nine, this); // SCK

            GTI.SPI.Configuration spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, spiSpeed);
            spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, pinCSN, this);

            pinCE = new GTI.DigitalOutput(socket, Socket.Pin.Six, false, this); // pin 6
            pinIRQ = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            pinIRQ.Interrupt += new GTI.InterruptInput.InterruptEventHandler(pinIRQ_Interrupt);

            // Must allow the radio time to settle else configuration bits will not necessarily stick.
            // This is actually only required following power up but some settling time also appears to
            // be required after resets too. For full coverage, we'll always assume the worst.
            // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped.
            // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure.
            // WARNING: Delay is based on P-variant whereby non-P *may* require different timing.
            //Thread.Sleep(5);
            Thread.Sleep(100);

            IsEnabled = false;

            Initialize();
        }
예제 #34
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public NullModem(int socketNumber)
        {
            this.socketA = Socket.GetSocket(socketNumber, true, this, null);
            this.socketA.EnsureTypeIsSupported('U', this);

            this.socketB = Socket.SocketInterfaces.CreateUnnumberedSocket(socketNumber.ToString() + "-" + " NullModem");
            this.socketB.SupportedTypes = new char[] { 'U' };

            this.socketB.CpuPins[3]              = this.socketA.CpuPins[3];
            this.socketB.CpuPins[4]              = this.socketA.CpuPins[5];
            this.socketB.CpuPins[5]              = this.socketA.CpuPins[4];
            this.socketB.CpuPins[6]              = this.socketA.CpuPins[7];
            this.socketB.CpuPins[7]              = this.socketA.CpuPins[6];
            this.socketB.CpuPins[8]              = this.socketA.CpuPins[8];
            this.socketB.CpuPins[9]              = this.socketA.CpuPins[9];
            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);
        }
예제 #35
0
            private DaisyLink(Socket socket, DaisyLinkModule module)
            {
                Ready = false;
                this.Socket = socket;

                this.ReservedCount = 0;
                this.NodeCount = 0;

                daisyLinkBus = I2CBusFactory.Create(socket, defaultI2cAddress, 10, i2cDataPin, i2cClockPin, module);

                // The link pin (port) is initialized as an input.  It is only driven during initialization of the daisylinked modules.
                daisyLinkResetPort = DigitalIOFactory.Create(socket, daisyLinkPin, false, GlitchFilterMode.Off, ResistorMode.PullUp, module);
                daisyLinkInterruptPort = null;
            }
예제 #36
0
        // Initialises the tunes module to be on the given socket.
        public TunesModule(int socketNumber, DomainModel.Model model)
        {
            socket = GT.Socket.GetSocket(socketNumber, true, null, null);

            pwm = new GTI.PWMOutput(socket, GT.Socket.Pin.Nine, false, null);
        }
예제 #37
0
            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 GTI.DigitalIO(socket, daisyLinkPin, false, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, module);
                daisyLinkInterruptPort = null;
            }
예제 #38
0
        /// <summary>
        /// Tells GadgeteerCore that a pin is being used on this socket.
        /// This is called by Gadgteeer.Interface classes automatically. Gadgeteer.Modules which do not use a Gadgeteer.Interface helper class in using a pin should call this directly.
        /// </summary>
        /// <param name="pin">The socket pin being used</param>
        /// <param name="module">The module using the socket pin (can be null, but if it is not null a more useful error message will be generated).</param>
        /// <returns></returns>
        public Cpu.Pin ReservePin(Socket.Pin pin, Module module)
        {
            if (pin == Pin.None)
            {
                return UnspecifiedPin;
            }

            Cpu.Pin cpuPin = CpuPins[(int)pin];
            if (cpuPin == UnspecifiedPin)
            {
                throw new PinMissingException(this, pin);
            }

            if (cpuPin == UnnumberedPin)
            {
                // bypass checks, return no pin
                return Cpu.Pin.GPIO_NONE;
            }

            // see if this is a display socket and reboot if we need to disable the LCD controller
            if (!(module is Module.DisplayModule) && (SupportsType('R') || SupportsType('G') || SupportsType('B')))
            {
                Program.Mainboard.EnsureRgbSocketPinsAvailable();
            }

            return cpuPin;
        }
예제 #39
0
        /// <summary>Constructs a new RS485 instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public RS485(int socketNumber)
        {
            this.socket = Socket.GetSocket(socketNumber, true, this, null);

            this.socket.EnsureTypeIsSupported('U', this);
        }
예제 #40
0
 internal PinConflictException(Socket socket, Socket.Pin pin, Module module, PinReservation priorReservation)
     : base("\nUnable to configure the " + (module != null ? module + " " : "") + "module using socket " + socket + " (pin " + (int)pin + "). " +
     "There is a conflict with the " + (priorReservation.ReservingModule != null ? priorReservation.ReservingModule + " " : "") + "module using socket " +
     priorReservation.ReservingSocket + " (pin " + priorReservation.ReservingPin + "). Please try using a different combination of sockets.")
 { }
예제 #41
0
            public static void ThrowIfOutOfRange(Socket.Pin pin, Socket.Pin from, Socket.Pin to, string iface, Module module)
            {
                if (pin >= from && pin <= to)
                    return;

                string message = "Cannot use " + iface + " interface on pin " + pin + " - pin must be in range " + from + " to " + to + ".";
                if (module != null)
                    message = "Module " + module + ": ";

                throw new InvalidSocketException(message);
            }
            /// <summary>
            /// Registers a socket.  Should be used by mainboards and socket-providing modules during initialization.
            /// </summary>
            /// <param name="socket">The socket to register</param>
            public static void RegisterSocket(Socket socket)
            {
                if (DoRegistrationChecks)
                {
                    if (socket.CpuPins == null || socket.CpuPins.Length != 11) SocketRegistrationError(socket, "CpuPins array must be of length 11");
                    if (socket.SupportedTypes == null || socket.SupportedTypes.Length == 0) SocketRegistrationError(socket, "SupportedTypes list is null/empty");
                    foreach (char type in socket.SupportedTypes)
                    {
                        switch (type)
                        {
                            case 'A':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type);
                                if (socket.AnalogInputIndirector == null)
                                {
                                    if (socket.AnalogInput3 == Cpu.AnalogChannel.ANALOG_NONE || socket.AnalogInput4 == Cpu.AnalogChannel.ANALOG_NONE || socket.AnalogInput5 == Cpu.AnalogChannel.ANALOG_NONE) SocketRegistrationError(socket, "Socket of type A must support analog input functionality on pins 3, 4 and 5");
                                    if (socket.AnalogInputScale == double.MinValue || socket.AnalogInputOffset == double.MinValue || socket.AnalogInputPrecisionInBits == int.MinValue) SocketRegistrationError(socket, "Socket of type A must provide analog input scale/offset through calling SocketInterfaces.SetAnalogInputFactors");
                                }
                                break;
                            case 'C':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type);
                                break;
                            case 'D':
                                TestPinsPresent(socket, new int[] { 3, 6, 7 }, type);
                                break;
                            case 'E':
                                TestPinsPresent(socket, new int[] { 6, 7, 8, 9 }, type);
                                break;
                            case 'F':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                break;
                            case 'H':
                                TestPinsPresent(socket, new int[] { 3 }, type);
                                break;
                            case 'I':
                                TestPinsPresent(socket, new int[] { 3, 6, 8, 9 }, type);
                                break;
                            case 'K':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7 }, type);
                                if (socket.SerialIndirector == null)
                                {
                                    if (socket.SerialPortName == null) SocketRegistrationError(socket, "Socket of type K must specify serial port name");
                                }
                                break;
                            case 'O':
                                TestPinsPresent(socket, new int[] { 3, 4, 5 }, type);
                                if (socket.AnalogOutput == null) SocketRegistrationError(socket, "Socket of type O must support analog output functionality");
                                break;
                            case 'P':
                                TestPinsPresent(socket, new int[] { 3, 6, 7, 8, 9 }, type);
                                if (socket.PwmOutputIndirector == null)
                                {
                                    if (socket.PWM7 == Cpu.PWMChannel.PWM_NONE || socket.PWM8 == Cpu.PWMChannel.PWM_NONE || socket.PWM9 == Cpu.PWMChannel.PWM_NONE) SocketRegistrationError(socket, "Socket of type P must support PWM functionality");
                                }
                                break;
                            case 'S':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                if (socket.SpiIndirector == null)
                                {
                                    if (socket.SPIModule == Socket.SocketInterfaces.SPIMissing) SocketRegistrationError(socket, "Socket of type S must specify SPI module number");
                                }
                                break;
                            case 'T':
                                TestPinsPresent(socket, new int[] { 4, 5, 6, 7 }, type);
                                break;
                            case 'U':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type);
                                if (socket.SerialIndirector == null)
                                {
                                    if (socket.SerialPortName == null) SocketRegistrationError(socket, "Socket of type U must specify serial port name");
                                }
                                break;
                            case 'R':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                break;
                            case 'G':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                break;
                            case 'B':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                break;
                            case 'X':
                                TestPinsPresent(socket, new int[] { 3, 4, 5 }, type);
                                break;
                            case 'Y':
                                TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type);
                                break;
                            case 'Z':
                                // manufacturer specific socket - no tests
                                break;
                            case '*':
                                // * is a special case  - daisylink modules don't actually declare their new socket in code, instead reusing the mainboard socket number 
                                // so we don't need the below, but it doesnt hurt to leave it in
                                TestPinsPresent(socket, new int[] { 3, 4, 5 }, type);
                                break;
                            default:
                                SocketRegistrationError(socket, "Socket type '" + type + "' is not supported by Gadgeteer");
                                break;
                        }
                    }
                }

                lock (Socket._sockets)
                {
                    if (Socket.GetSocket(socket.SocketNumber, false, null, null) != null) throw new Socket.InvalidSocketException("Cannot register socket - socket number " + socket.SocketNumber + " already used");
                    Socket._sockets.Add(socket);
                    socket._registered = true;
                }
            }
예제 #43
0
파일: Display.cs 프로젝트: radtek/MFE
        /// <summary>Constructor</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Display(ModelType model, int socketNumber)
            : base(WPFRenderOptions.Intercept)
        {
            #region UTFT
            ushort[] dsx = { 239, 239, 239, 239, 239, 239, 175, 175, 239, 127, 127, 239, 271, 479, 239, 239, 239, 239, 239, 239, 479, 319, 239, 175, 127, 239, 239, 319, 319 };
            ushort[] dsy = { 319, 399, 319, 319, 319, 319, 219, 219, 399, 159, 127, 319, 479, 799, 319, 319, 319, 319, 319, 319, 799, 479, 319, 219, 159, 319, 319, 479, 479 };
            byte[]   dtm = { 16, 16, 16, 8, 8, 16, 8, (byte)DisplayTransferMode.SERIAL_4PIN, 16, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, 16, 16, 16, 8, 16, (byte)DisplayTransferMode.LATCHED_16, 8, 16, 8, 16, 16, 16, 8, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_4PIN, 16, 16 };

            disp_x_size           = dsx[(byte)model];
            disp_y_size           = dsy[(byte)model];
            display_transfer_mode = dtm[(byte)model];
            display_model         = (byte)model;

            if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_4PIN)
            {
                display_transfer_mode = 1;
                display_serial_mode   = (byte)DisplayTransferMode.SERIAL_4PIN;
            }
            if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_5PIN)
            {
                display_transfer_mode = 1;
                display_serial_mode   = (byte)DisplayTransferMode.SERIAL_5PIN;
            }

            if (display_transfer_mode != 1)
            {
                //_set_direction_registers(display_transfer_mode);
                //P_RS = portOutputRegister(digitalPinToPort(RS));
                //B_RS = digitalPinToBitMask(RS);
                //P_WR = portOutputRegister(digitalPinToPort(WR));
                //B_WR = digitalPinToBitMask(WR);
                //P_CS = portOutputRegister(digitalPinToPort(CS));
                //B_CS = digitalPinToBitMask(CS);
                //P_RST = portOutputRegister(digitalPinToPort(RST));
                //B_RST = digitalPinToBitMask(RST);
                //if (display_transfer_mode == LATCHED_16)
                //{
                //    P_ALE = portOutputRegister(digitalPinToPort(SER));
                //    B_ALE = digitalPinToBitMask(SER);
                //    pinMode(SER, OUTPUT);
                //    cbi(P_ALE, B_ALE);
                //    pinMode(8, OUTPUT);
                //    digitalWrite(8, LOW);
                //}
                //pinMode(RS, OUTPUT);
                //pinMode(WR, OUTPUT);
                //pinMode(CS, OUTPUT);
                //pinMode(RST, OUTPUT);
            }
            else
            {
                //P_SDA = portOutputRegister(digitalPinToPort(RS));
                //B_SDA = digitalPinToBitMask(RS);
                //P_SCL = portOutputRegister(digitalPinToPort(WR));
                //B_SCL = digitalPinToBitMask(WR);
                //P_CS = portOutputRegister(digitalPinToPort(CS));
                //B_CS = digitalPinToBitMask(CS);
                //P_RST = portOutputRegister(digitalPinToPort(RST));
                //B_RST = digitalPinToBitMask(RST);
                //if (display_serial_mode != SERIAL_4PIN)
                //{
                //    P_RS = portOutputRegister(digitalPinToPort(SER));
                //    B_RS = digitalPinToBitMask(SER);
                //    pinMode(SER, OUTPUT);
                //}
                //pinMode(RS, OUTPUT);
                //pinMode(WR, OUTPUT);
                //pinMode(CS, OUTPUT);
                //pinMode(RST, OUTPUT);
            }
            #endregion

            socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('S', this);

            /*
             * Serial peripheral interface (SPI).
             * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line.
             * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.
             */

            pinReset     = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3
            pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this);  // pin 4
            pinDc        = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this);  // pin 5

            spiConfig      = new GTI.SPI.Configuration(false, 0, 0, false, true, 12000);
            netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule);
            spi            = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this);

            Reset();
            ConfigureDisplay();
            Clear();
            SetBacklight(true);
        }
 /// <summary>
 /// Set the scale and offset used by <see cref="Microsoft.SPOT.Hardware.AnalogInput.Read"/> to transform the raw value into a voltage between 0 and 3.3V, and the precision in bits.
 /// </summary>
 /// <param name="scale">The multiplicative scale factor.</param>
 /// <param name="offset">The additive offset.</param>
 /// <param name="precisionInBits">The number of bits precision by this analog input socket.</param>
 /// <param name="socket">The socket being configured.</param>
 public static void SetAnalogInputFactors(Socket socket, double scale, double offset, int precisionInBits)
 {
     socket.AnalogInputScale = scale;
     socket.AnalogInputOffset = offset;
     socket.AnalogInputPrecisionInBits = precisionInBits;
 }
예제 #45
0
            /// <summary>
            /// Returns the DaisyLink instance for a given DaisyLink compatible socket.  
            /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, 
            /// which causes the chain to be initialised using the DaisyLink protocol.
            /// </summary>
            /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param>
            /// <param name="module">The daisylink module.</param>
            /// <returns>The DaisyLink instance for that socket</returns>
            public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module)
            {
                lock (portLock)
                {
                    foreach (DaisyLink dl in daisyLinkList)
                    {
                        if (dl.Socket == socket)
                        {
                            return dl;
                        }
                    }

                    DaisyLink daisylink;
                    daisylink = new DaisyLink(socket, module);
                    daisyLinkList.Add(daisylink);
                    daisylink.Initialize();
                    return daisylink;
                }
            }
 private static void SocketRegistrationError(Socket socket, string message)
 {
     Debug.Print("Warning: socket " + socket + " is not compliant with Gadgeteer : " + message);
 }
예제 #47
0
        /*
        private static ArrayList _reservedPins = new ArrayList();

        internal class PinReservation
        {
            public Socket ReservingSocket { get; private set; }
            public Socket.Pin ReservingPin { get; private set; }
            public Cpu.Pin CpuPin { get; private set; }
            public Module ReservingModule { get; private set; }

            public PinReservation(Socket socket, Socket.Pin pin, Cpu.Pin cpuPin, Module module)
            {
                ReservingSocket = socket;
                ReservingModule = module;
                ReservingPin = pin;
                CpuPin = cpuPin;
            }
        }
        */
        /// <summary>
        /// Tells GadgeteerCore that a pin is being used on this socket.
        /// This is called by Gadgteeer.Interface classes automatically.  Gadgeteer.Modules which do not use a Gadgeteer.Interface helper class in using a pin should call this directly.
        /// Note that Gadgeteer allows mainboard pins to be reused across multiple sockets, so the reservation check also checks if the pin is used on a different socket where the pin is shared.
        /// </summary>
        /// <param name="pin">The socket pin being used</param>
        /// <param name="module">The module using the socket pin (can be null, but if it is not null a more useful error message will be generated).</param>
        /// <returns></returns>
        public Cpu.Pin ReservePin(Socket.Pin pin, Module module)
        {
            Cpu.Pin cpuPin = CpuPins[(int)pin];
            if (cpuPin == UnspecifiedPin)
            {
                throw new PinMissingException(this, pin);
            }

            if (cpuPin == UnnumberedPin)
            {
                // bypass checks, return no pin
                return Cpu.Pin.GPIO_NONE;
            }

            /*
            // Check to see if pin is already reserved
            foreach (PinReservation reservation in _reservedPins)
            {
                if (cpuPin == reservation.CpuPin)
                {
                    throw new PinConflictException(this, pin, module, reservation);
                }
            }
            */

            // see if this is a display socket and reboot if we need to disable the LCD controller
            if (!(module is Module.DisplayModule) && (SupportsType('R') || SupportsType('G') || SupportsType('B')))
            {
                Module.DisplayModule.LCDControllerPinReuse();
            }

            //_reservedPins.Add(new PinReservation(this, pin, cpuPin, module));
            return cpuPin;
        }
예제 #48
0
 public Sim900Modem(int port)
 {
     modem = new GTM.Extender(port);
     socket = Socket.GetSocket(port, true, modem, null);
     //serial = new GTI.Serial(socket, 19200, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, modem);
 }
예제 #49
0
 internal PinMissingException(Socket socket, Socket.Pin pin)
     : base("\nPin " + (int)pin + " on socket " + socket + " is not connected to a valid CPU pin.")
 { }
예제 #50
0
 bool NativeI2CWriteRead(GT.Socket socket, GT.Socket.Pin sda, GT.Socket.Pin scl, byte address, byte[] write, int writeOffset, int writeLen, byte[] read, int readOffset, int readLen, out int numWritten, out int numRead)
 {
     return(SoftwareI2CBus.DirectI2CWriteRead(socket.CpuPins[(int)scl], socket.CpuPins[(int)sda], 100, address, write, writeOffset, writeLen, read, readOffset, readLen, out numWritten, out numRead));
 }
예제 #51
0
 public static InvalidSocketException FunctionalityException(Socket socket, string iface)
 {
     return new InvalidSocketException("Socket " + socket + " has an error with its " + iface + " functionality. Please try a different socket.");
 }
예제 #52
0
        /// <summary>Constructor</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Display(ModelType model, int socketNumber)
            : base(WPFRenderOptions.Intercept)
        {
            #region UTFT
            ushort[] dsx = {239, 239, 239, 239, 239, 239, 175, 175, 239, 127, 127, 239, 271, 479, 239, 239, 239, 239, 239, 239, 479, 319, 239, 175, 127, 239, 239, 319, 319};
            ushort[] dsy = {319, 399, 319, 319, 319, 319, 219, 219, 399, 159, 127, 319, 479, 799, 319, 319, 319, 319, 319, 319, 799, 479, 319, 219, 159, 319, 319, 479, 479};
            byte[] dtm = { 16, 16, 16, 8, 8, 16, 8, (byte)DisplayTransferMode.SERIAL_4PIN, 16, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, 16, 16, 16, 8, 16, (byte)DisplayTransferMode.LATCHED_16, 8, 16, 8, 16, 16, 16, 8, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_4PIN, 16, 16 };

            disp_x_size = dsx[(byte)model];
            disp_y_size = dsy[(byte)model];
            display_transfer_mode = dtm[(byte)model];
            display_model = (byte)model;

            if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_4PIN)
            {
                display_transfer_mode = 1;
                display_serial_mode = (byte)DisplayTransferMode.SERIAL_4PIN;
            }
            if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_5PIN)
            {
                display_transfer_mode = 1;
                display_serial_mode = (byte)DisplayTransferMode.SERIAL_5PIN;
            }

            if (display_transfer_mode != 1)
            {
                //_set_direction_registers(display_transfer_mode);
                //P_RS = portOutputRegister(digitalPinToPort(RS));
                //B_RS = digitalPinToBitMask(RS);
                //P_WR = portOutputRegister(digitalPinToPort(WR));
                //B_WR = digitalPinToBitMask(WR);
                //P_CS = portOutputRegister(digitalPinToPort(CS));
                //B_CS = digitalPinToBitMask(CS);
                //P_RST = portOutputRegister(digitalPinToPort(RST));
                //B_RST = digitalPinToBitMask(RST);
                //if (display_transfer_mode == LATCHED_16)
                //{
                //    P_ALE = portOutputRegister(digitalPinToPort(SER));
                //    B_ALE = digitalPinToBitMask(SER);
                //    pinMode(SER, OUTPUT);
                //    cbi(P_ALE, B_ALE);
                //    pinMode(8, OUTPUT);
                //    digitalWrite(8, LOW);
                //}
                //pinMode(RS, OUTPUT);
                //pinMode(WR, OUTPUT);
                //pinMode(CS, OUTPUT);
                //pinMode(RST, OUTPUT);
            }
            else
            {
                //P_SDA = portOutputRegister(digitalPinToPort(RS));
                //B_SDA = digitalPinToBitMask(RS);
                //P_SCL = portOutputRegister(digitalPinToPort(WR));
                //B_SCL = digitalPinToBitMask(WR);
                //P_CS = portOutputRegister(digitalPinToPort(CS));
                //B_CS = digitalPinToBitMask(CS);
                //P_RST = portOutputRegister(digitalPinToPort(RST));
                //B_RST = digitalPinToBitMask(RST);
                //if (display_serial_mode != SERIAL_4PIN)
                //{
                //    P_RS = portOutputRegister(digitalPinToPort(SER));
                //    B_RS = digitalPinToBitMask(SER);
                //    pinMode(SER, OUTPUT);
                //}
                //pinMode(RS, OUTPUT);
                //pinMode(WR, OUTPUT);
                //pinMode(CS, OUTPUT);
                //pinMode(RST, OUTPUT);
            }
            #endregion

            socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('S', this);
            /*
             * Serial peripheral interface (SPI).
             * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line.
             * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.
            */

            pinReset = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3
            pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this); // pin 4
            pinDc = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this); // pin 5

            spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, 12000);
            netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule);
            spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this);

            Reset();
            ConfigureDisplay();
            Clear();
            SetBacklight(true);
        }
예제 #53
0
        /// <summary>
        ///   Initializes SPI connection and control pins
        ///   <param name="irqPin"> IRQ pin as a Socket.Pin
        ///   <param name="cePin"> Chip Enable(CE) pin as a Socket.Pin
        ///   <param name="irqPin"> Chip Select Not(CSN or CS\) pin as a Socket.Pin
        ///   <param name="spiClockRateKHZ"> Clock rate in KHz (i.e. 1000 = 1MHz)
        /// </summary>
        public void Initialize(Socket.Pin irqPin, Socket.Pin csPin, byte config, uint spiClockRateKHZ = 1000)
        {
            _spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, false, spiClockRateKHZ);

            // Chip Select : Active Low
            // Clock : Active High, Data clocked in on rising edge
            //_socket = GTS.GetSocket(6, false, this, null);
            _spi = GTI.SpiFactory.Create(_socket, _spiConfig, GTI.SpiSharing.Shared, _socket, csPin, this);

            // Initialize Chip Enable Port
            _csPin = GTI.DigitalOutputFactory.Create(_socket, Socket.Pin.Four, true, this);

            //            _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            _irqPin.Interrupt += _irqPin_Interrupt;
            _initialized = true;

            _config = config;

            ResetConfig();
        }
 private LedDigital SetupBreakoutOutput(Socket.Pin pin)
 {
     var output = _breakout.CreateDigitalOutput(pin, false);
     return new LedDigital(output);
 }
예제 #55
0
 public PinReservation(Socket socket, Socket.Pin pin, Cpu.Pin cpuPin, Module module)
 {
     ReservingSocket = socket;
     ReservingModule = module;
     ReservingPin = pin;
     CpuPin = cpuPin;
 }
예제 #56
0
            /// <summary>
            /// Returns the DaisyLink instance for a given DaisyLink compatible socket.  
            /// If this is the first call to this method for a given socket, it creates a new DaisyLink instance, 
            /// which causes the chain to be initialised using the DaisyLink protocol.
            /// </summary>
            /// <param name="socket">The socket where the DaisyLink chain of modules is plugged in.</param>
            /// <param name="module">The daisylink module.</param>
            /// <returns>The DaisyLink instance for that socket</returns>
            public static DaisyLink GetDaisyLinkForSocket(Socket socket, DaisyLinkModule module)
            {
                lock (portLock)
                {
                    for (int i = 0; i < daisyLinkList.Count; i++)
                    {
                        if (((DaisyLink)daisyLinkList[i]).Socket == socket)
                            return (DaisyLink)daisyLinkList[i];
                    }

                    DaisyLink daisylink;
                    daisylink = new DaisyLink(socket, module);
                    daisyLinkList.Add(daisylink);
                    daisylink.Initialize();
                    return daisylink;
                }
            }
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public TemperatureProbe(int socketNumber)
        {
            // This finds the Socket instance from the user-specified socket number.
            // This will generate user-friendly error messages if the socket is invalid.
            // If there is more than one socket on this module, then instead of "null" for the last parameter,
            // put text that identifies the socket to the user (e.g. "S" if there is a socket type S)

            socket = Socket.GetSocket(socketNumber, true, this, "I");
        }
        void ProgramStarted()
        {
            client = bluetooth.ClientMode;
            //server = bluetooth.HostMode;
            Thread.Sleep(2000);

            // need a handler for state changes and data recieved.
            bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);
            bluetooth.DataReceived          += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);
            bluetooth.PinRequested          += new Bluetooth.PinRequestedHandler(bluetooth_PinRequest);

            // set up bluetooth module connection parameters
            bluetooth.SetDeviceName("EmotionMingle"); // change this to whatever name you want
            bluetooth.SetPinCode("5678");             //likewise, set whatever PIN you want.
            Thread.Sleep(2000);


            // put the device in pairing mode as part of a normal execution
            client.EnterPairingMode();
            Thread.Sleep(2000);

            // HSU Communication layer
            // MOSI/SDA (TX) --> DIGITAL 0 (RX COM1)
            // SCL/RX (RX) --> DIGITAL 1 (TX COM1)
            //IPN532CommunicationLayer commLayer = new PN532CommunicationHSU(SerialPorts.COM1);

            // SPI Communication layer
            // SCK --> DIGITAL 13 - Socket S Pin9
            // MISO --> DIGITAL 12 - Socket S Pin8
            // MOSI/SDA --> DIGITAL 11 - Socket S Pin7
            // SCL/RX -> DIGITAL 10 - Socket S Pin6
            // IRQ --> DIGITAL 8 - Socket S Pin5

            //SPI.SPI_module spi = GT.Socket.GetSocket(9, true, null, null).SPIModule;
            //Cpu.Pin pin6 = GT.Socket.GetSocket(9, true, null, null).CpuPins[6];
            //Cpu.Pin pin5 = GT.Socket.GetSocket(9, true, null, null).CpuPins[5];

            //IPN532CommunicationLayer commLayer = new PN532CommunicationSPI(spi, pin6, pin5);

            // I2C Communication layer
            // MOSI/SDA --> ANALOG 4 (SDA)
            // SCL/RS --> ANALOG 5 (SCL)
            // IRQ --> DIGITAL 8
            //IPN532CommunicationLayer commLayer = new PN532CommunicationI2C(Cpu.Pin.GPIO_Pin5);

            //nfc = new NfcPN532Reader(commLayer);
            //nfc.TagDetected += nfc_TagDetected;
            //nfc.TagLost += nfc_TagLost;
            //nfc.Open(NfcTagType.MifareUltralight);


            GT.Socket socket = GT.Socket.GetSocket(4, true, null, null);

            Debug.Print("SerialPortName: " + socket.SerialPortName);

            UART = new SerialPort(socket.SerialPortName, 4800);
            UART.Open();

            rnd = new Random();

            Debug.Print("Program Started");
        }