コード例 #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  = GTI.DigitalOutputFactory.Create(this.socket, GT.Socket.Pin.Six, true, this);

            this.Reset();

            this.device = GTI.I2CBusFactory.Create(this.socket, TouchC8.I2C_ADDRESS, TouchC8.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.previousWheelDirection = (Direction)(-1);
            this.previousWheelPosition  = 0;
            this.previousWheelTouched   = false;
            this.previousButton1Touched = false;
            this.previousButton2Touched = false;
            this.previousButton3Touched = false;

            Thread.Sleep(250);

            this.ConfigureSPM();
        }
コード例 #2
0
ファイル: TouchL12_43.cs プロジェクト: valoni/NETMF-Gadgeteer
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            byte flags = this.ReadRegister(TouchL12.IRQ_SRC);

            if ((flags & 0x8) != 0)
            {
                double    position  = this.GetSliderPosition();
                bool      touched   = this.IsSliderPressed();
                Direction direction = this.GetSliderDirection();

                if (touched != this.previousSliderTouched)
                {
                    this.OnSliderTouched(this, new SliderTouchedEventArgs(touched));
                }

                if (position != this.previousSliderPosition || direction != this.previousSliderDirection)
                {
                    this.OnSliderPositionChanged(this, new SliderPositionChangedEventArgs(direction, position));
                }

                this.previousSliderTouched   = touched;
                this.previousSliderPosition  = position;
                this.previousSliderDirection = direction;
            }
        }
コード例 #3
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public MicroSDCard(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('F', this);

            socket.ReservePin(Socket.Pin.Four, this);
            socket.ReservePin(Socket.Pin.Five, 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);

            RemovableMedia.Insert += this.OnInsert;
            RemovableMedia.Eject  += this.OnEject;

            this.IsCardMounted = false;

            this.cardDetect            = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.cardDetect.Interrupt += this.OnCardDetect;

            if (this.IsCardInserted)
            {
                this.Mount();
            }
        }
コード例 #4
0
ファイル: Gyro_43.cs プロジェクト: EmiiFont/MyShuttle_RC
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Gyro(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('I', this);
            
            this.readBuffer1 = new byte[1];
            this.writeBuffer1 = new byte[1];
            this.writeBuffer2 = new byte[2];
            this.readBuffer8 = new byte[8];

            this.offsetX = 0;
            this.offsetY = 0;
            this.offsetZ = 0;

            this.ready = false;
            this.timer = new GT.Timer(200);
            this.timer.Tick += (a) => this.TakeMeasurement();

            this.i2c = GTI.I2CBusFactory.Create(socket, 0x68, 100, this);
            
            this.interruptInput = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, this);
            this.interruptInput.Interrupt += this.OnInterrupt;

            this.SetFullScaleRange();
        }
コード例 #5
0
ファイル: HubAP5_43.cs プロジェクト: valoni/NETMF-Gadgeteer
            private void OnInterrupt(GTI.InterruptInput sender, bool value)
            {
                ArrayList interruptedPins = new ArrayList();

                byte[] intPorts = this.ReadRegisters(IO60P16.INTERRUPT_PORT_0_REGISTER, 8);
                for (byte i = 0; i < 8; i++)
                {
                    for (int j = 1, k = 0; j <= 128; j <<= 1, k++)
                    {
                        if ((intPorts[i] & j) != 0)
                        {
                            interruptedPins.Add((i << 4) | k);
                        }
                    }
                }

                foreach (int pin in interruptedPins)
                {
                    lock (this.interruptHandlers) {
                        foreach (InterruptRegistraton reg in this.interruptHandlers)
                        {
                            if (reg.pin == pin)
                            {
                                bool val = this.ReadDigital((byte)pin);
                                if ((reg.mode == GTI.InterruptMode.RisingEdge && val) || (reg.mode == GTI.InterruptMode.FallingEdge && !val) || reg.mode == GTI.InterruptMode.RisingAndFallingEdge)
                                {
                                    reg.handler(val);
                                }
                            }
                        }
                    }
                }
            }
コード例 #6
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Gyro(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('I', this);

            this.readBuffer1  = new byte[1];
            this.writeBuffer1 = new byte[1];
            this.writeBuffer2 = new byte[2];
            this.readBuffer8  = new byte[8];

            this.offsetX = 0;
            this.offsetY = 0;
            this.offsetZ = 0;

            this.ready       = false;
            this.timer       = new GT.Timer(200);
            this.timer.Tick += (a) => this.TakeMeasurement();

            this.i2c = GTI.I2CBusFactory.Create(socket, 0x68, 100, this);

            this.interruptInput            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, this);
            this.interruptInput.Interrupt += this.OnInterrupt;

            this.SetFullScaleRange();
        }
コード例 #7
0
        private void _input_Interrupt(GTI.InterruptInput input, bool value)
        {
            //PresenceState buttonState = input.Read() ? PresenceState.SomeoneDetected : PresenceState.NobodyDetected;

            /*switch (buttonState)
             * {
             *  case PresenceState.SomeoneDetected:
             *      if (LEDMode == LEDModes.OnWhilePressed)
             *          TurnLEDOff();
             *      else if (LEDMode == LEDModes.OnWhileReleased)
             *          TurnLEDOn();
             *      else if (LEDMode == LEDModes.ToggleWhenReleased)
             *          ToggleLED();
             *      break;
             *  case PresenceState.NobodyDetected:
             *      if (LEDMode == LEDModes.OnWhilePressed)
             *          TurnLEDOn();
             *      else if (LEDMode == LEDModes.OnWhileReleased)
             *          TurnLEDOff();
             *      else if (LEDMode == LEDModes.ToggleWhenPressed)
             *          ToggleLED();
             *      break;
             * }*/
            /*if (!presence)
             * {
             *  presence = true;
             *  this.OnPresenceEvent(this, presence);
             * }*/
            //lastTime = System.DateTime.Now;
        }
コード例 #8
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="baud">The baud rate to communicate with the module with.</param>
        public Bluetooth(int socketNumber, long baud)
        {
            // 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);

            this.reset      = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Six, false, this);
            this.statusInt  = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.serialPort = GTI.SerialFactory.Create(socket, 38400, GTI.SerialParity.None, GTI.SerialStopBits.One, 8, GTI.HardwareFlowControl.NotRequired, this);

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

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

            // Poundy added:
            Thread.Sleep(5);
            this.SetDeviceBaud(baud);
            this.serialPort.Flush();
            this.serialPort.Close();
            this.serialPort.BaudRate = (int)baud;
            this.serialPort.Open();
            // Poundy

            readerThread = new Thread(new ThreadStart(runReaderThread));
            readerThread.Start();
            Thread.Sleep(500);
        }
コード例 #9
0
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            byte flags = this.ReadRegister(TouchC8.IRQ_SRC);

            if ((flags & 0x8) != 0)
            {
                double    wheelPosition  = this.GetWheelPosition();
                bool      wheelTouched   = this.IsWheelPressed();
                Direction wheelDirection = this.GetWheelDirection();

                if (wheelTouched != this.previousWheelTouched)
                {
                    this.OnWheelTouched(this, new WheelTouchedEventArgs(wheelTouched));
                }

                if (wheelPosition != this.previousWheelPosition || wheelDirection != this.previousWheelDirection)
                {
                    this.OnWheelPositionChanged(this, new WheelPositionChangedEventArgs(wheelDirection, wheelPosition));
                }

                this.previousWheelTouched   = wheelTouched;
                this.previousWheelPosition  = wheelPosition;
                this.previousWheelDirection = wheelDirection;
            }

            if ((flags & 0x4) != 0)
            {
                byte cap     = this.ReadRegister(TouchC8.CAP_STAT_LSB);
                bool button0 = (cap & 0x1) != 0;                 //proximity
                bool button1 = (cap & 0x2) != 0;
                bool button2 = (cap & 0x4) != 0;
                bool button3 = (cap & 0x8) != 0;

                if (button0 != this.previousButton0Touched)
                {
                    this.OnProximityDetected(this, new PromixityDetectedEventArgs(button0));
                }

                if (button1 != this.previousButton1Touched)
                {
                    this.OnButtonTouched(this, new ButtonTouchedEventArgs(Button.Up, button1));
                }

                if (button2 != this.previousButton2Touched)
                {
                    this.OnButtonTouched(this, new ButtonTouchedEventArgs(Button.Middle, button2));
                }

                if (button3 != this.previousButton3Touched)
                {
                    this.OnButtonTouched(this, new ButtonTouchedEventArgs(Button.Down, button3));
                }

                this.previousButton0Touched = button0;
                this.previousButton1Touched = button1;
                this.previousButton2Touched = button2;
                this.previousButton3Touched = button3;
            }
        }
コード例 #10
0
ファイル: MAX31865_43.cs プロジェクト: ianlee74/RTD01-Module
 void _irqPin_Interrupt(GTI.InterruptInput sender, bool value)
 {
     if (DataReadyFarEvent != null)
     {
         DataReadyFarEvent(this, GetTempF());
     }
     if (DataReadyCelEvent != null)
     {
         DataReadyCelEvent(this, GetTempC());
     }
 }
コード例 #11
0
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            if (this.OperatingMode == Mode.LevelDetection)
            {
                this.OnThresholdExceededEvent(this, null);

                if (this.autoResetThresholdDetection)
                {
                    this.ResetThresholdDetection();
                }
            }
        }
コード例 #12
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Button(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

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

            this.currentMode = LedMode.Off;

            this.led              = GTI.DigitalOutputFactory.Create(socket, GT.Socket.Pin.Four, false, this);
            this.input            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.input.Interrupt += this.OnInterrupt;
        }
コード例 #13
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public PIR(int socketNumber)
        {
            var socket = Socket.GetSocket(socketNumber, true, this, null);

            this.onMotionSensed = this.OnMotionSensed;

            this.interrupt            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.interrupt.Interrupt += (a, b) => {
                if (!b)
                {
                    this.OnMotionSensed(this, null);
                }
            };
        }
コード例 #14
0
        private void OnCardDetect(GTI.InterruptInput sender, bool value)
        {
            Thread.Sleep(500);

            if (this.IsCardInserted && !this.IsCardMounted)
            {
                this.Mount();
            }

            if (!this.IsCardInserted && this.IsCardMounted)
            {
                this.Unmount();
            }
        }
コード例 #15
0
ファイル: NRF24_43.cs プロジェクト: KonstantinKolesnik/MFE
        // 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.KKS.NRF24. This file will provide IntelliSense and documentation for the
        // interface and make it easier for developers to use the NRF24 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 NRF24(int socketNumber, int socketNumberTwo)
        {
            // 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);

            // 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.input = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);

            // This registers a handler for the interrupt event of the interrupt input (which is bereleased)
            this.input.Interrupt += this.input_Interrupt;
        }
コード例 #16
0
ファイル: HubAP5_43.cs プロジェクト: valoni/NETMF-Gadgeteer
            public IO60P16(Socket socket)
            {
                this.interruptHandlers = new ArrayList();
                this.write2            = new byte[2];
                this.write1            = new byte[1];
                this.read1             = new byte[1];
                this.pwms = new byte[30] {
                    0x60, 0, 0x61, 1, 0x62, 2, 0x63, 3, 0x64, 4, 0x65, 5, 0x66, 6, 0x67, 7, 0x70, 8, 0x71, 9, 0x72, 10, 0x73, 11, 0x74, 12, 0x75, 13, 0x76, 14
                };

                this.io60Chip = GTI.I2CBusFactory.Create(socket, 0x20, 100, null);

                this.interrupt            = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, null);
                this.interrupt.Interrupt += this.OnInterrupt;
            }
コード例 #17
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Joystick(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('A', this);

            this.inputX           = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Four, this);
            this.inputY           = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Five, this);
            this.input            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.input.Interrupt += (a, b) => this.OnJoystickEvent(this, b ? ButtonState.Released : ButtonState.Pressed);

            this.offsetX = 0;
            this.offsetY = 0;
            this.samples = 5;
        }
コード例 #18
0
ファイル: ButtonS7_43.cs プロジェクト: valoni/NETMF-Gadgeteer
        /// <summary>Constructs a new ButtonS7 instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public ButtonS7(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('Y', this);

            this.buttons = new GTI.DigitalInput[6];
            for (int i = 0; i < 6; i++)
            {
                this.buttons[i] = GTI.DigitalInputFactory.Create(socket, (Socket.Pin)(i + 4), GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            }

            this.enter            = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.enter.Interrupt += this.OnInterrupt;
        }
コード例 #19
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Compass(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('I', this);

            this.writeBuffer1 = new byte[1];
            this.readBuffer6  = new byte[6];

            this.timer       = new GT.Timer(200);
            this.timer.Tick += (a) => this.TakeMeasurement();

            this.dataReady            = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, this);
            this.dataReady.Interrupt += this.OnInterrupt;

            this.i2c = GTI.I2CBusFactory.Create(socket, 0x1E, 100, this);
        }
コード例 #20
0
ファイル: IO60P16_43.cs プロジェクト: valoni/NETMF-Gadgeteer
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public IO60P16(int socketNumber)
        {
            var socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('X', this);

            this.interruptHandlers = new ArrayList();
            this.write2            = new byte[2];
            this.write1            = new byte[1];
            this.read1             = new byte[1];
            this.pwms = new byte[30] {
                0x60, 0, 0x61, 1, 0x62, 2, 0x63, 3, 0x64, 4, 0x65, 5, 0x66, 6, 0x67, 7, 0x70, 8, 0x71, 9, 0x72, 10, 0x73, 11, 0x74, 12, 0x75, 13, 0x76, 14
            };

            this.io60Chip = new GTI.SoftwareI2CBus(socket, Socket.Pin.Five, Socket.Pin.Four, 0x20, 400, this);

            this.interrupt            = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, null);
            this.interrupt.Interrupt += this.OnInterrupt;
        }
コード例 #21
0
        private void OnInterrupt(GTI.InterruptInput input, bool value)
        {
            var state = value ? ButtonState.Released : ButtonState.Pressed;

            switch (state)
            {
            case ButtonState.Released:
                if (this.Mode == LedMode.OnWhilePressed)
                {
                    this.TurnLedOff();
                }
                else if (this.Mode == LedMode.OnWhileReleased)
                {
                    this.TurnLedOn();
                }
                else if (this.Mode == LedMode.ToggleWhenReleased)
                {
                    this.ToggleLED();
                }

                break;

            case ButtonState.Pressed:
                if (this.Mode == LedMode.OnWhilePressed)
                {
                    this.TurnLedOn();
                }
                else if (this.Mode == LedMode.OnWhileReleased)
                {
                    this.TurnLedOff();
                }
                else if (this.Mode == LedMode.ToggleWhenPressed)
                {
                    this.ToggleLED();
                }

                break;
            }

            this.OnButtonEvent(this, state);
        }
コード例 #22
0
ファイル: MAX31865_43.cs プロジェクト: ianlee74/RTD01-Module
        /// <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();
        }
コード例 #23
0
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            this.writeBuffer1[0] = (byte)Register.DXRA;
            this.i2c.WriteRead(this.writeBuffer1, this.readBuffer6);

            int rawX = (this.readBuffer6[0] << 8) | this.readBuffer6[1];
            int rawZ = (this.readBuffer6[2] << 8) | this.readBuffer6[3];
            int rawY = (this.readBuffer6[4] << 8) | this.readBuffer6[5];

            rawX = ((rawX >> 15) == 1 ? -32767 : 0) + (rawX & 0x7FFF);
            rawZ = ((rawZ >> 15) == 1 ? -32767 : 0) + (rawZ & 0x7FFF);
            rawY = ((rawY >> 15) == 1 ? -32767 : 0) + (rawY & 0x7FFF);

            if (rawX == -4096 || rawY == -4096 || rawZ == -4096)
            {
                this.DebugPrint("Invalid data read. Measurement discarded.");

                return;
            }

            this.OnMeasurementComplete(this, new MeasurementCompleteEventArgs(Math.Atan2((double)rawY, (double)rawX) * (180 / 3.14159265) + 180, rawX, rawY, rawZ));
        }
コード例 #24
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Accelerometer(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('I', this);

            this.read1  = new byte[1];
            this.write1 = new byte[1];
            this.autoResetThresholdDetection = false;

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

            this.i2c         = GTI.I2CBusFactory.Create(socket, 0x1D, 50, this);
            this.i2c.Timeout = 1000;

            this.timer       = new GT.Timer(200);
            this.timer.Tick += (a) => this.TakeMeasurement();

            this.OperatingMode    = Mode.Measurement;
            this.MeasurementRange = Range.TwoG;
        }
コード例 #25
0
 private void input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnButtonEvent(this, value ? ButtonState.Released : ButtonState.Pressed);
 }
コード例 #26
0
ファイル: ButtonS7_43.cs プロジェクト: valoni/NETMF-Gadgeteer
 private void OnInterrupt(GTI.InterruptInput input, bool value)
 {
     this.OnEnterEvent(this, value ? EnterStates.Released : EnterStates.Pressed);
 }
コード例 #27
0
ファイル: MAX31865_43.cs プロジェクト: ianlee74/RTD01-Module
        /// <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();
        }
コード例 #28
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="rSocketNumber">The mainboard socket that has the display's R socket connected to it.</param>
        /// <param name="gSocketNumber">The mainboard socket that has the display's G socket connected to it.</param>
        /// <param name="bSocketNumber">The mainboard socket that has the display's B socket connected to it.</param>
        /// <param name="i2cSocketNumber">The mainboard socket that has the display's I socket connected to it.</param>
        public DisplayCP7(int rSocketNumber, int gSocketNumber, int bSocketNumber, int i2cSocketNumber)
            : base(WpfMode.PassThrough)
        {
            var config = new DisplayModule.TimingRequirements()
            {
                UsesCommonSyncPin                 = true, //not the proper property, but we needed it for OutputEnableIsFixed
                CommonSyncPinIsActiveHigh         = true, //not the proper property, but we needed it for OutputEnablePolarity
                HorizontalSyncPulseIsActiveHigh   = true,
                VerticalSyncPulseIsActiveHigh     = true,
                PixelDataIsValidOnClockRisingEdge = false,
                HorizontalSyncPulseWidth          = 1,
                HorizontalBackPorch               = 46,
                HorizontalFrontPorch              = 16,
                VerticalSyncPulseWidth            = 1,
                VerticalBackPorch                 = 23,
                VerticalFrontPorch                = 7,
                MaximumClockSpeed                 = 24000,
            };

            base.OnDisplayConnected("Display CP7", 800, 480, DisplayOrientation.Normal, config);

            var rSocket = Socket.GetSocket(rSocketNumber, true, this, null);
            var gSocket = Socket.GetSocket(gSocketNumber, true, this, null);
            var bSocket = Socket.GetSocket(bSocketNumber, true, this, null);

            rSocket.EnsureTypeIsSupported('R', this);
            gSocket.EnsureTypeIsSupported('G', this);
            bSocket.EnsureTypeIsSupported('B', this);

            this.backlightPin = GTI.DigitalOutputFactory.Create(gSocket, Socket.Pin.Nine, true, this);

            rSocket.ReservePin(Socket.Pin.Three, this);
            rSocket.ReservePin(Socket.Pin.Four, this);
            rSocket.ReservePin(Socket.Pin.Five, this);
            rSocket.ReservePin(Socket.Pin.Six, this);
            rSocket.ReservePin(Socket.Pin.Seven, this);
            rSocket.ReservePin(Socket.Pin.Eight, this);
            rSocket.ReservePin(Socket.Pin.Nine, this);

            gSocket.ReservePin(Socket.Pin.Three, this);
            gSocket.ReservePin(Socket.Pin.Four, this);
            gSocket.ReservePin(Socket.Pin.Five, this);
            gSocket.ReservePin(Socket.Pin.Six, this);
            gSocket.ReservePin(Socket.Pin.Seven, this);
            gSocket.ReservePin(Socket.Pin.Eight, this);

            bSocket.ReservePin(Socket.Pin.Three, this);
            bSocket.ReservePin(Socket.Pin.Four, this);
            bSocket.ReservePin(Socket.Pin.Five, this);
            bSocket.ReservePin(Socket.Pin.Six, this);
            bSocket.ReservePin(Socket.Pin.Seven, this);
            bSocket.ReservePin(Socket.Pin.Eight, this);
            bSocket.ReservePin(Socket.Pin.Nine, this);

            if (i2cSocketNumber == Socket.Unused)
            {
                return;
            }

            this.onScreenPressed   = this.OnScreenPressed;
            this.onScreenReleased  = this.OnScreenReleased;
            this.onHomePressed     = this.OnHomePressed;
            this.onMenuPressed     = this.OnMenuPressed;
            this.onBackPressed     = this.OnBackPressed;
            this.onGestureDetected = this.OnGestureDetected;

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

            this.releaseSent               = false;
            this.transactions              = new I2CDevice.I2CTransaction[2];
            this.resultBuffer              = new byte[1];
            this.addressBuffer             = new byte[1];
            this.i2cBus                    = GTI.I2CBusFactory.Create(i2cSocket, 0x38, 400, this);
            this.touchInterrupt            = GTI.InterruptInputFactory.Create(i2cSocket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.touchInterrupt.Interrupt += (a, b) => this.OnTouchEvent();
        }
コード例 #29
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;
            }
コード例 #30
0
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            this.Read(Register.INT_STATUS);

            this.ready = true;
        }
コード例 #31
0
            /// <summary>
            /// Initializes the DaisyLink bus, resetting all devices on it and assigning them new addresses.  
            /// Any existing GTM.DaisyLinkModule devices will no longer work, and they should be constructed again.
            /// </summary>
            internal void Initialize()
            {
                lock (portLock)
                {
                    bool lastFound = false;
                    byte modulesFound = 0;

                    // Reset all modules in the chain and place the first module into Setup mode
                    SendResetPulse();

                    byte[] data = new byte[2];
                    // For all modules in the chain
                    while (!lastFound)
                    {
                        Address = defaultI2cAddress;
                        daisyLinkBus.LengthErrorBehavior = ErrorBehavior.SuppressException;
                        if (DaisyLinkVersionImplemented != ReadRegister((byte)DaisyLinkRegister.DaisyLinkVersion))
                        {
                            lastFound = true;       // If the correct version can't be read back from a device, there are no more devices in the chain
                        }
                        daisyLinkBus.LengthErrorBehavior = ErrorBehavior.ThrowException;

                        if (modulesFound != 0)      // If a device is left in Standby mode
                        {
                            data[0] = (byte)DaisyLinkRegister.Config;
                            data[1] = (byte)(lastFound ? 1 : 0);

                            Address = (byte)(totalNodeCount + modulesFound);
                            Write(data);     // Enable/disable I2C pull-ups depending on whether last in chain (place module in Active mode)
                        }

                        if (!lastFound)
                        {
                            // Next module in chain is in Setup mode so start setting it up
                            modulesFound++;         // Increase the total number of modules found connected to this socket

                            data[0] = (byte)DaisyLinkRegister.Address;
                            data[1] = (byte)(totalNodeCount + modulesFound);
                            
                            Address = defaultI2cAddress;
                            Write(data);     // Set the I2C ID of the next module in the chain (place module in Standby mode)
                        }
                    }

                    this.StartAddress = (byte)(totalNodeCount + 1);
                    this.NodeCount = modulesFound;
                    this.ReservedCount = 0;
                    totalNodeCount += modulesFound;
                    Ready = true;
                    if (modulesFound != 0)
                    {
                        socketModuleList = new DaisyLinkModule[modulesFound];       // Keep track of all DaisyLinkModules attached to this socket
                        try
                        {
                            daisyLinkInterruptPort = InterruptInputFactory.Create(Socket, daisyLinkPin, GlitchFilterMode.Off, ResistorMode.Disabled, InterruptMode.FallingEdge, null);
                        }

                        catch (Exception e)
                        {
                            throw new Socket.InvalidSocketException("There is an issue connecting the DaisyLink module to socket " + Socket +
                            ". Please check that all modules are connected to the correct sockets or try connecting the DaisyLink module to a different socket", e);
                        }
                        daisyLinkInterruptPort.Interrupt += daisyLinkInterruptPort_OnInterrupt;
                    }
                }
            }
コード例 #32
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="rSocketNumber">The mainboard socket that has the display's R socket connected to it.</param>
        /// <param name="gSocketNumber">The mainboard socket that has the display's G socket connected to it.</param>
        /// <param name="bSocketNumber">The mainboard socket that has the display's B socket connected to it.</param>
        /// <param name="tSocketNumber">The mainboard socket that has the display's T socket connected to it.</param>
        /// <param name="iSocketNumber">The mainboard socket that has the display's I socket connected to it.</param>
        public DisplayNHVN(int rSocketNumber, int gSocketNumber, int bSocketNumber, int tSocketNumber, int iSocketNumber)
            : base(WpfMode.PassThrough)
        {
            if (tSocketNumber != Socket.Unused && iSocketNumber != Socket.Unused)
            {
                throw new InvalidOperationException("The T and I sockets may not be connected at the same time.");
            }

            var rSocket = Socket.GetSocket(rSocketNumber, true, this, null);
            var gSocket = Socket.GetSocket(gSocketNumber, true, this, null);
            var bSocket = Socket.GetSocket(bSocketNumber, true, this, null);

            rSocket.EnsureTypeIsSupported('R', this);
            gSocket.EnsureTypeIsSupported('G', this);
            bSocket.EnsureTypeIsSupported('B', this);

            this.backlightPin = GTI.DigitalOutputFactory.Create(gSocket, Socket.Pin.Nine, true, this);

            rSocket.ReservePin(Socket.Pin.Three, this);
            rSocket.ReservePin(Socket.Pin.Four, this);
            rSocket.ReservePin(Socket.Pin.Five, this);
            rSocket.ReservePin(Socket.Pin.Six, this);
            rSocket.ReservePin(Socket.Pin.Seven, this);
            rSocket.ReservePin(Socket.Pin.Eight, this);
            rSocket.ReservePin(Socket.Pin.Nine, this);

            gSocket.ReservePin(Socket.Pin.Three, this);
            gSocket.ReservePin(Socket.Pin.Four, this);
            gSocket.ReservePin(Socket.Pin.Five, this);
            gSocket.ReservePin(Socket.Pin.Six, this);
            gSocket.ReservePin(Socket.Pin.Seven, this);
            gSocket.ReservePin(Socket.Pin.Eight, this);

            bSocket.ReservePin(Socket.Pin.Three, this);
            bSocket.ReservePin(Socket.Pin.Four, this);
            bSocket.ReservePin(Socket.Pin.Five, this);
            bSocket.ReservePin(Socket.Pin.Six, this);
            bSocket.ReservePin(Socket.Pin.Seven, this);
            bSocket.ReservePin(Socket.Pin.Eight, this);
            bSocket.ReservePin(Socket.Pin.Nine, this);

            if (tSocketNumber != Socket.Unused)
            {
                var tSocket = Socket.GetSocket(tSocketNumber, true, this, null);

                tSocket.EnsureTypeIsSupported('T', this);

                tSocket.ReservePin(Socket.Pin.Four, this);
                tSocket.ReservePin(Socket.Pin.Five, this);
                tSocket.ReservePin(Socket.Pin.Six, this);
                tSocket.ReservePin(Socket.Pin.Seven, this);

                GT.Program.BeginInvoke(new NullParamsDelegate(() => Microsoft.SPOT.Touch.Touch.Initialize(Application.Current)), null);
            }
            else if (iSocketNumber != Socket.Unused)
            {
                var iSocket = Socket.GetSocket(iSocketNumber, true, this, null);

                this.transactions              = new I2CDevice.I2CTransaction[2];
                this.resultBuffer              = new byte[1];
                this.addressBuffer             = new byte[1];
                this.i2cBus                    = GTI.I2CBusFactory.Create(iSocket, 0x38, 400, this);
                this.touchInterrupt            = GTI.InterruptInputFactory.Create(iSocket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
                this.touchInterrupt.Interrupt += (a, b) => this.OnTouchEvent();
            }
        }
コード例 #33
0
 private void EnableInterrupts()
 {
     input = GTI.InterruptInputFactory.Create(_socket, Socket.Pin.Three, GTI.GlitchFilterMode.On,
         GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingEdge, this);
     input.Interrupt += OnInterrupt;
 }
コード例 #34
0
 private void daisyLinkInterruptPort_OnInterrupt(InterruptInput input, bool value)
 {
     byte[] data = new byte[] { (byte)DaisyLinkRegister.Config, 0 }; 
     
     for (byte moduleIndex = 0; moduleIndex < NodeCount; moduleIndex++)
     {
         Address = (byte)(moduleIndex + StartAddress);
         if (0 != (0x80 & ReadRegister((byte)DaisyLinkRegister.Config)))       // If this is the interrupting module
         {                        
             Write(data);                    // Clear the interrupt on the module
             if (socketModuleList[moduleIndex] != null)
             {
                 socketModuleList[moduleIndex].OnDaisyLinkInterrupt(socketModuleList[moduleIndex]);              // Kick off user event (if any) for this module instance
             }
         }
     }
 }
コード例 #35
0
 /// <summary>
 /// Sends a reset pulse on the daisylink chain.  This resets all DaisyLink nodes to INIT state, that is, waiting for a DaisyLink message.
 /// </summary>
 /// <remarks>
 /// It is recommended to reboot the mainboard after calling this method because communication to the DaisyLink nodes will fail.
 /// </remarks>
 internal void SendResetPulse()
 {
     lock (portLock)
     {
         if (daisyLinkInterruptPort != null)
         {
             daisyLinkInterruptPort.Interrupt -= daisyLinkInterruptPort_OnInterrupt;
             daisyLinkInterruptPort.Dispose();       // Ask hardware drivers to unreserve this pin
             daisyLinkInterruptPort = null;
         }
         if (daisyLinkResetPort == null)
         {
             daisyLinkResetPort = DigitalIOFactory.Create(Socket, daisyLinkPin, false, GlitchFilterMode.Off, ResistorMode.PullUp, null);
         }
         daisyLinkResetPort.Mode = IOMode.Output;       // Should drive the neighbor bus high
         Thread.Sleep(2);                        // 2 milliseconds is definitely more than 1 ms
         daisyLinkResetPort.Mode = IOMode.Input;      // Pull-downs should take the neighbor bus back low
         daisyLinkResetPort.Dispose();           // Remove this pin from the hardware's reserved pin list
         daisyLinkResetPort = null;
     }
 }