Ejemplo n.º 1
0
 void Input_Interrupt(InterruptInput sender, bool value)
 {
     if (value == true)
     {
         Click(this);
     }
 }
Ejemplo n.º 2
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;
            }
Ejemplo n.º 3
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
                        }
                    }
                }
            }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
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;
                    }
                }
            }