コード例 #1
0
        // tests all possible addresses to see what modules are connected
        void testAllAddresses(int socket)
        {
            for (ushort n = 1; n <= 127; n++)
            {
                // create a bus for the hypothetical sensor
                GTI.I2CBus sensor = new GTI.I2CBus(GT.Socket.GetSocket(socket, true, null, null), n, 10, null);

                // ask it to perform a range find
                byte[] writeBuffer = new byte[1];
                writeBuffer[0] = 81;
                sensor.Write(writeBuffer, timeout);

                // get the results
                int range = 0;
                DateTime end = System.DateTime.Now.AddMilliseconds(200);  // how long to wait for the sensor to respond
                while (range == 0 && System.DateTime.Now < end)
                {
                    // output is given as a 16bit integer,
                    // the most significant byte comming first
                    byte[] readBuffer = new byte[2];
                    sensor.Read(readBuffer, timeout);
                    range = readBuffer[0] * 256 + readBuffer[1];
                }

                // the range find timed out, so the sensor most likely doesn't exist
                if (range != 0)
                {
                    Debug.Print("Found sensor at address " + n.ToString());
                }
            }
        }
コード例 #2
0
            public IO60P16(Socket socket)
            {
                this.io60Chip = new GTI.I2CBus(socket, 0x20, 100, null);

                this.interrupt            = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, null);
                this.interrupt.Interrupt += this.OnInterrupt;
            }
コード例 #3
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();
        }
コード例 #4
0
        /// <summary>Constructor</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public AccelG248(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('I', this);

            i2c = new GTI.I2CBus(socket, 0x1C, 400, this);

            WriteRegister(0x2A, 1);
        }
コード例 #5
0
ファイル: I2CMotrorDriver.cs プロジェクト: shaga/NETMF_Sample
        /// <summary>
        /// �R���X�g���N�^
        /// </summary>
        /// <param name="socket">�ڑ��\�P�b�g</param>
        /// <param name="addr">�h���C�o���W���[���A�h���X</param>
        public I2CMotrorDriver(GT.Socket socket, ushort addr, byte max = MTR_DRV_MAX_SPEED)
        {
            i2c = new GTI.I2CBus(socket, addr, 100, null);

            if (max < 0 || MTR_DRV_MAX_SPEED < max)
            {
                max = MTR_DRV_MAX_SPEED;
            }

            maxSpeed = max;
        }
コード例 #6
0
ファイル: test.cs プロジェクト: gitsoll/MinIMU-9-Gyro-C--
        // 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 Compass(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 = Socket.GetSocket(socketNumber, true, this, null);

            continuousTimer = new Gadgeteer.Timer(new TimeSpan(0, 0, 0, 0, 200));
            continuousTimer.Tick += new Timer.TickEventHandler(continuousTimer_Tick);

            i2c = new GTI.I2CBus(socket, 0x1E, 100, this);

            dataReady = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullDown, GTI.InterruptMode.RisingEdge, this);
            dataReady.Interrupt += new GTI.InterruptInput.InterruptEventHandler(dataReady_Interrupt);
        }
コード例 #7
0
        // changes the given sensor's address to the given value
        // valid addresses are 1-127
        static void changeAddress(int socketNumber, byte oldAddress, byte newAddress)
        {
            // initialise the I2CBus on a socket
            const int freq = 10;            // the frequency in MHz that the hub will run at
            GT.Socket socket = GT.Socket.GetSocket(socketNumber, true, null, null);
            GTI.I2CBus sensor = new GTI.I2CBus(socket, oldAddress, freq, null);

            // need to send three bytes to the sensor, the first two
            // 170 and 165 instruct it to change the address,
            // the third byte is the new address
            // the reason for the * 2 is that the address is read
            // as 7 bits and then a trailing zero
            byte[] writeBuffer = new byte[3];
            writeBuffer[0] = 170;
            writeBuffer[1] = 165;
            writeBuffer[2] = (byte)(newAddress * 2);

            sensor.Write(writeBuffer, timeout);
        }
コード例 #8
0
ファイル: Ranger.cs プロジェクト: paulinshek/OxfordTeam5
        // Initialises the ranger and starts ranging automatically.
        // The arguemnts should be two arrays of equal length, the first being
        // the socket on the mainboard used by that sensor and the second being
        // the addrses used by that sensor.
        // Once started, the sensors will be labelled 0,1,2,... in the order
        // that they appear in these arrays
        public Ranger(int[] socketNumbers, byte[] addresses)
        {
            numSensors = addresses.Length;
            sensors = new GTI.I2CBus[numSensors];
            ranges = new int[numSensors];

            // create the busses for communicating with the sensors
            for (int i = 0; i < numSensors; i++)
            {
                GT.Socket socket = GT.Socket.GetSocket(socketNumbers[i], true, null, null);
                sensors[i] = new GTI.I2CBus(socket, addresses[i], freq, null);
            }

            // create the ranging thread but don't start it ranging
            rangingThread = new Thread(new ThreadStart(takeRanges));
            isRangingThreadRunning = false;
            Monitor.Enter(this);
            rangingThread.Start();
        }
コード例 #9
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rgbSocketNumber1">The first R,G,B socket</param>
        /// <param name="rgbSocketNumber2">The second R,G,B socket</param>
        /// <param name="rgbSocketNumber3">The third R,G,B socket</param>
        /// <param name="i2cSocketNumber">The I2C socket</param>
        public DisplayCP7(int rgbSocketNumber1, int rgbSocketNumber2, int rgbSocketNumber3, int i2cSocketNumber)
            : base(WPFRenderOptions.Ignore)
        {
            // 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)
            ReserveLCDPins(rgbSocketNumber1, rgbSocketNumber2, rgbSocketNumber3);
            ConfigureLCD();

            Socket i2cSocket = Socket.GetSocket(i2cSocketNumber, true, this, "i2cSocket");

            i2cBus = new GTI.I2CBus(i2cSocket, 0x38, 400, this);

            // This creates an GTI.InterruptInput interface. The interfaces under the GTI namespace provide easy ways to build common modules.
            // This also generates user-friendly error messages automatically, e.g. if the user chooses a socket incompatible with an interrupt input.
            this.touchInterrupt = new GTI.InterruptInput(i2cSocket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);

            // This registers a handler for the interrupt event of the interrupt input (which is bereleased)
            this.touchInterrupt.Interrupt += new GTI.InterruptInput.InterruptEventHandler(this._input_Interrupt);
        }
コード例 #10
0
        /// <summary>
        /// Initializes the temperature probe by specifying the I2C bridge address and clock frequency
        /// </summary>
        /// <param name="bridgeAddress">The I2C address of the DS2482 bridge.</param>
        /// <param name="clockFrequency">The clock rate in kHz of the I2C bus.</param>
        /// <param name="adcResolution">The resolution of the ADC: 9, 10, 11, or 12 bit.</param>
        /// <param name="probe">The probe being initialized.</param>
        public void Initialize(ushort bridgeAddress, int clockFrequency, ADCResolution adcResolution, Module probe)
        {
            this.bridgeAddress = bridgeAddress;
            this.adcResolution = adcResolution;

            switch (adcResolution)
            {
                case ADCResolution.NineBit:
                    temperatureResolution = 8 * minTempResolution;
                    convertionTime = maxConvertionTime / 8;
                    break;
                case ADCResolution.TenBit:
                    temperatureResolution = 4 * minTempResolution;
                    convertionTime = maxConvertionTime / 4;
                    break;
                case ADCResolution.ElevenBit:
                    temperatureResolution = 2 * minTempResolution;
                    convertionTime = maxConvertionTime / 2;
                    break;
                case ADCResolution.TwelveBit:
                    temperatureResolution = minTempResolution;
                    convertionTime = maxConvertionTime;
                    break;
                default:
                    break;
            }

            try
            {
                i2cBus = new I2CBus(socket, bridgeAddress, clockFrequency, probe);

                ResetDS2482();
                ReadDS18B20ROMCode();
                ReadDS18B20PowerSupply();
                ConfigureDS18B20();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #11
0
 public ADS7830(Socket socket)
 {
     this.i2c = new GTI.I2CBus(socket, ADS7830.I2C_ADDRESS, 400, null);
 }