Exemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="Interrupt"/> event.
        /// </summary>
        /// <param name="sender">The <see cref="InterruptInput"/> object that raised the event.</param>
        /// <param name="value"><b>true</b> if the the value received from the interrupt is greater than zero; otherwise, <b>false</b>.</param>
        protected virtual void OnInterruptEvent(InterruptInput sender, bool value)
        {
            if (this.Interrupt == null)
            {
                return;
            }

            if (this.SynchronousUnsafeEventInvocation)
            {
                try
                {
                    this.Interrupt(sender, value);
                }
                catch
                {
                }
            }
            else
            {
                if (this.onInterrupt == null)
                {
                    this.onInterrupt = new InterruptEventHandler(this.OnInterruptEvent);
                }

                if (Program.CheckAndInvoke(this.Interrupt, this.onInterrupt, sender, value))
                {
                    this.Interrupt(sender, value);
                }
            }
        }
Exemplo n.º 2
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();
        }
        /// <summary>
        /// Raises the <see cref="Interrupt"/> event.
        /// </summary>
        /// <param name="sender">The <see cref="InterruptInput"/> object that raised the event.</param>
        /// <param name="value"><b>true</b> if the the value received from the interrupt is greater than zero; otherwise, <b>false</b>.</param>
        protected virtual void OnInterruptEvent(InterruptInput sender, bool value)
        {
            if (this.Interrupt == null)
            {
                return;
            }

            if (this.SynchronousUnsafeEventInvocation)
            {
                try
                {
                    this.Interrupt(sender, value);
                }
                catch
                {
                }
            }
            else
            {
                if (this.onInterrupt == null)
                {
                    this.onInterrupt = new InterruptEventHandler(this.OnInterruptEvent);
                }

                if (Program.CheckAndInvoke(this.Interrupt, this.onInterrupt, sender, value))
                {
                    this.Interrupt(sender, value);
                }
            }
        }
Exemplo n.º 4
0
            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);
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 5
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;
            }
Exemplo n.º 6
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      = new GTI.DigitalOutput(socket, Socket.Pin.Six, false, this);
            this.statusInt  = new GTI.InterruptInput(socket, 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);

            // 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);
        }
Exemplo n.º 7
0
        private void OnInterrupt(GTI.InterruptInput sender, bool value)
        {
            byte flags = this.ReadRegister(TouchL12.IRQ_SRC);

            if ((flags & 0x8) != 0)
            {
                double    SliderPosition  = this.GetSliderPosition();
                bool      SliderTouched   = this.IsSliderPressed();
                Direction SliderDirection = this.GetSliderDirection();

                if (SliderTouched != this.previousSliderTouched)
                {
                    this.OnSliderEvent(this, SliderTouched);
                }

                if (SliderPosition != this.previousSliderPosition || SliderDirection != this.previousSliderDirection)
                {
                    this.OnSliderPositionEvent(this, SliderPosition, SliderDirection);
                }

                this.previousSliderTouched   = SliderTouched;
                this.previousSliderPosition  = SliderPosition;
                this.previousSliderDirection = SliderDirection;
            }
        }
Exemplo n.º 8
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.OnWheelEvent(this, wheelTouched);
                }

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

                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.OnProximityEvent(this, button0);
                }

                if (button1 != this.previousButton1Touched)
                {
                    this.OnButtonEvent(this, Buttons.Up, button1);
                }

                if (button2 != this.previousButton2Touched)
                {
                    this.OnButtonEvent(this, Buttons.Middle, button2);
                }

                if (button3 != this.previousButton3Touched)
                {
                    this.OnButtonEvent(this, Buttons.Down, button3);
                }

                this.previousButton0Touched = button0;
                this.previousButton1Touched = button1;
                this.previousButton2Touched = button2;
                this.previousButton3Touched = button3;
            }
        }
Exemplo n.º 9
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 Joystick(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            this.inputX           = new GTI.AnalogInput(socket, Socket.Pin.Four, this);
            this.inputY           = new GTI.AnalogInput(socket, Socket.Pin.Five, this);
            this.input            = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.input.Interrupt += new GTI.InterruptInput.InterruptEventHandler(this._input_Interrupt);
            this.offsetX          = 0;
            this.offsetY          = 0;
        }
Exemplo n.º 10
0
        void _sdCardDetect_Interrupt(GTI.InterruptInput sender, bool value)
        {
            Thread.Sleep(500);

            if (IsCardInserted)
            {
                MountSDCard();
            }
            else
            {
                UnmountSDCard();
            }
        }
Exemplo n.º 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 --
        // 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, 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 = new GTI.InterruptInput(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 += new GTI.InterruptInput.InterruptEventHandler(this._input_Interrupt);
        }
Exemplo n.º 12
0
        /// <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] = new GTI.DigitalInput(socket, (Socket.Pin)(i + 4), GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, this);
            }

            this.enter            = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.enter.Interrupt += this.OnInterrupt;
        }
Exemplo n.º 13
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;
            }
Exemplo n.º 14
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 PIR(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);

            // 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.m_motionDetect = new GTI.InterruptInput(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 below)
            this.m_motionDetect.Interrupt += new GTI.InterruptInput.InterruptEventHandler(this._input_Interrupt);
        }
Exemplo n.º 15
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 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);
        }
Exemplo n.º 16
0
 private void daisyLinkInterruptPort_OnInterrupt(GTI.InterruptInput sender, bool value)
 {
     for (byte moduleIndex = 0; moduleIndex < NodeCount; moduleIndex++)
     {
         if (0 != (0x80 & ReadRegister((byte)(moduleIndex + StartAddress), (byte)DaisyLinkRegister.Config)))       // If this is the interrupting module
         {
             byte[] data = new byte[] { (byte)DaisyLinkRegister.Config, 0 };
             Write((byte)(moduleIndex + StartAddress), 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
             }
         }
     }
     //daisyLinkInterruptPort.ClearInterrupt();
 }
Exemplo n.º 17
0
        public RelayX1Plus(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

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

            this.enable = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this);


            // Plus part
            this.input            = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, null);
            this.input.Interrupt +=
                (i, v) =>
            {
                sensorState = this.input.Read();
            };
            sensorState = this.input.Read();
        }
Exemplo n.º 18
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 = new GTI.DigitalIO(Socket, daisyLinkPin, false, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, null);
         }
         daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Output; // Should drive the neighbor bus high
         Thread.Sleep(2);                                          // 2 milliseconds is definitely more than 1 ms
         daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Input;  // Pull-downs should take the neighbor bus back low
         daisyLinkResetPort.Dispose();                             // Remove this pin from the hardware's reserved pin list
         daisyLinkResetPort = null;
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Raises the <see cref="Interrupt"/> event.
        /// </summary>
        /// <param name="sender">The <see cref="InterruptInput"/> object that raised the event.</param>
        /// <param name="value"><b>true</b> if the the value received from the interrupt is greater than zero; otherwise, <b>false</b>.</param>
        protected virtual void OnInterruptEvent(InterruptInput sender, bool value)
        {
            InterruptEventHandler handler = _interruptHandler;

            if (handler == null)
            {
                return;
            }

            if (SynchronousUnsafeEventInvocation)
            {
                try { handler(sender, value); }
                catch { }
            }
            else
            {
                if (Program.CheckAndInvoke(handler, handler, sender, value))
                {
                    handler(sender, value);
                }
            }
        }
Exemplo n.º 20
0
        private void _input_Interrupt(GTI.InterruptInput input, bool value)
        {
            ButtonState buttonState = input.Read() ? ButtonState.Released : ButtonState.Pressed;

            switch (buttonState)
            {
            case ButtonState.Released:
                if (LEDMode == LEDModes.OnWhilePressed)
                {
                    TurnLEDOff();
                }
                else if (LEDMode == LEDModes.OnWhileReleased)
                {
                    TurnLEDOn();
                }
                else if (LEDMode == LEDModes.ToggleWhenReleased)
                {
                    ToggleLED();
                }
                break;

            case ButtonState.Pressed:
                if (LEDMode == LEDModes.OnWhilePressed)
                {
                    TurnLEDOn();
                }
                else if (LEDMode == LEDModes.OnWhileReleased)
                {
                    TurnLEDOff();
                }
                else if (LEDMode == LEDModes.ToggleWhenPressed)
                {
                    ToggleLED();
                }
                break;
            }
            this.OnButtonEvent(this, buttonState);
        }
Exemplo n.º 21
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)
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            this.reset = new GTI.DigitalOutput(socket, Socket.Pin.Six, false, this);
            this.statusInt = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            this.serialPort = new 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);
        }
Exemplo n.º 22
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 SDCard(int socketNumber)
        {
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            socket.EnsureTypeIsSupported('F', this);

            // add Insert/Eject events
            RemovableMedia.Insert += Insert;
            RemovableMedia.Eject  += Eject;

            IsCardMounted = false;

            _sdCardDetect            = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            _sdCardDetect.Interrupt += new GTI.InterruptInput.InterruptEventHandler(_sdCardDetect_Interrupt);

            try
            {
                // Reserve the additional pins used by the SD interface (pin 3 is automatically reserved by initializing the InterruptInput)
                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);

                if (IsCardInserted)
                {
                    MountSDCard();
                }
            }

            catch (Exception e)
            {
                throw new GT.Socket.InvalidSocketException("There is an issue connecting the SD Card module to socket " + socketNumber +
                                                           ". Please check that all modules are connected to the correct sockets or try connecting the SD Card to a different 'F' socket", e);
            }
        }
Exemplo n.º 23
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();
        }
Exemplo n.º 24
0
        private void _input_Interrupt(GTI.InterruptInput input, bool value)
        {
            JoystickState joystickState = value ? JoystickState.Released : JoystickState.Pressed;

            this.OnJoystickEvent(this, joystickState);
        }
Exemplo n.º 25
0
 private void _input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnTouchEvent(this, null);
 }
Exemplo n.º 26
0
 private void _input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnButtonEvent(this, value ? ButtonState.Released : ButtonState.Pressed);
 }
Exemplo n.º 27
0
 public void StopInterruptHandler(InterruptInput.InterruptEventHandler interrupthandler)
 {
     if (interrupt != null)
     {
         interrupt.Interrupt -= new InterruptInput.InterruptEventHandler(interrupthandler);
     }
 }
Exemplo n.º 28
0
 private void OnInterrupt(InterruptInput sender, bool value)
 {
     var time = DateTime.Now;
     _beatQueue.Add(time);
     OnHeartBeat(time);
 }
Exemplo n.º 29
0
 public GroveHeartRateSensor(GT.Socket socket, int sampleSize)
 {
     _beatQueue = new CircularDateQueue(sampleSize);
     _pin = new InterruptInput(socket, Socket.Pin.Three, GlitchFilterMode.Off, ResistorMode.Disabled, InterruptMode.RisingEdge, null);
     _pin.Interrupt += OnInterrupt;
 }
Exemplo n.º 30
0
 void int_pin_Interrupt(InterruptInput sender, bool value)
 {
     PulseDebugLED();
     sender.Read();
     iO60P16.GetStatusPort(1);
 }
Exemplo n.º 31
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;
            }
Exemplo n.º 32
0
 private void _input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnMotion_SensorEvent(this, value ? Motion_SensorState.Ready : Motion_SensorState.Busy);
 }
Exemplo n.º 33
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();

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

                        if (modulesFound != 0)      // If a device is left in Standby mode
                        {
                            byte[] data = new byte[2] { (byte)DaisyLinkRegister.Config, (byte)(lastFound ? 1 : 0) };
                            Write((byte)(totalNodeCount + modulesFound), 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

                            byte[] data = new byte[2] { (byte)DaisyLinkRegister.Address, (byte)(totalNodeCount + modulesFound) };
                            Write(defaultI2cAddress, 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 = new GTI.InterruptInput(Socket, daisyLinkPin, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.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;
                        //daisyLinkInterruptPort.EnableInterrupt();
                    }
                }
            }
Exemplo n.º 34
0
 public void StartInterruptHandler(InterruptInput.InterruptEventHandler interrupthandler)
 {
     interrupt = new InterruptInput(_socket, GT.Socket.Pin.Three, GlitchFilterMode.Off, ResistorMode.Disabled, InterruptMode.RisingEdge, null);
     interrupt.Interrupt += new InterruptInput.InterruptEventHandler(interrupthandler);
 }
Exemplo n.º 35
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();

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

                        if (modulesFound != 0)      // If a device is left in Standby mode
                        {
                            byte[] data = new byte[2] {
                                (byte)DaisyLinkRegister.Config, (byte)(lastFound ? 1 : 0)
                            };
                            Write((byte)(totalNodeCount + modulesFound), 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

                            byte[] data = new byte[2] {
                                (byte)DaisyLinkRegister.Address, (byte)(totalNodeCount + modulesFound)
                            };
                            Write(defaultI2cAddress, 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 = new GTI.InterruptInput(Socket, daisyLinkPin, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.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;
                        //daisyLinkInterruptPort.EnableInterrupt();
                    }
                }
            }
Exemplo n.º 36
0
 //#region Overtemperature handling
 private void overTemperatureInterrupt(GTI.InterruptInput input, bool value)
 {
     this.OnOverTemperatureEvent(this, value ? LimitState.FallenBelow : LimitState.Exceeded);
 }
Exemplo n.º 37
0
 private void OnInterrupt(GTI.InterruptInput input, bool value)
 {
     this.OnEnterEvent(this, value ? EnterStates.Released : EnterStates.Pressed);
 }
Exemplo n.º 38
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 = new GTI.DigitalIO(Socket, daisyLinkPin, false, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, null);
         }
         daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Output;  // Should drive the neighbor bus high
         Thread.Sleep(2);                                           // 2 milliseconds is definitely more than 1 ms
         daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Input;   // Pull-downs should take the neighbor bus back low
         daisyLinkResetPort.Dispose();               // Remove this pin from the hardware's reserved pin list
         daisyLinkResetPort = null;
     }
 }
Exemplo n.º 39
0
        /// <summary>
        /// Raises the <see cref="Interrupt"/> event.
        /// </summary>
        /// <param name="sender">The <see cref="InterruptInput"/> object that raised the event.</param>
        /// <param name="value"><b>true</b> if the the value received from the interrupt is greater than zero; otherwise, <b>false</b>.</param>
        protected virtual void OnInterruptEvent(InterruptInput sender, bool value)
        {
            InterruptEventHandler handler = _interruptHandler;

            if (handler == null)
                return;

            if (SynchronousUnsafeEventInvocation)
            {
                try { handler(sender, value); }
                catch { }
            }
            else
            {
                if (Program.CheckAndInvoke(handler, handler, sender, value))
                    handler(sender, value);
            }
        }