/// <summary>
        /// Construct an SPI device attached to a particular module
        /// </summary>
        /// <param name="SpiModule">The module this device is attached to</param>
        /// <param name="ChipSelect">The chip select pin used by this device</param>
        /// <param name="csMode">The ChipSelectMode to use with this device</param>
        /// <param name="SpeedMHz">The speed to operate this device at</param>
        /// <param name="mode">The SpiMode of this device</param>
        public SpiDevice(Spi SpiModule, Pin ChipSelect, ChipSelectMode csMode = ChipSelectMode.SpiActiveLow, double SpeedMHz = 1, SpiMode mode = SpiMode.Mode00)
        {
            this.ChipSelectMode = csMode;
            this.ChipSelect = ChipSelect;
            this.spi = SpiModule;
            this.Frequency = SpeedMHz;
            this.Mode = mode;

            this.ChipSelect.Mode = PinMode.PushPullOutput;

            spi.Enabled = true;
        }
        /// <summary>
        /// Construct a FLIR Lepton
        /// </summary>
        /// <param name="spi">The Spi module to use</param>
        public FlirLepton(Spi spi)
        {
            this.spi = spi;
            //spi.Mode = SPIMode.Mode11;
            //spi.Frequency = 12;
            //spi.ChipSelect.DigitalValue = true;
            spi.Enabled = true;
            blackFrame = new ushort[height, width];
            for (int i=0;i<height;i++)
            {
                for (int j = 0; j < width; j++)
                    blackFrame[i,j] = (ushort)0xffff;
            }

        }
        /// <summary>
        /// Construct a new instance of a Max7219 device
        /// </summary>
        /// <param name="SpiModule">A reference to the Treehopper SPI module</param>
        /// <param name="LoadPin">The pin attached tot he LOAD input</param>
        /// <param name="Address">The index of the Max7219 device attached to this bus</param>
        /// <param name="SpeedMHz">The SPI speed to use. The maximum is 10 MHz.</param>
        public Max7219(Spi SpiModule, Pin LoadPin, int Address = 0, double SpeedMHz = 1) : base(64, true, false)
        {
            if (SpeedMHz > 10)
                throw new ArgumentOutOfRangeException("SpeedMhz", "The MAX7219 supports a maximum clock rate of 10 MHz.");

            dev = new SpiDevice(SpiModule, LoadPin, SpeedMHz: SpeedMHz, csMode: ChipSelectMode.PulseHighAtEnd);

            this.address = Address;
            sendTest(false);

            ScanLimit = 7;
            sendDecodeMode(0);
            Clear().Wait();
            Shutdown = false;
            setBrightness(1);
        }
示例#4
0
        /// <summary>
        /// Open the TreehopperBoard. The board must be opened before any other methods are called.
        /// </summary>
        public void Open()
        {
            if (usb.Open())
            {
                // If this is a "whole" usb device (libusb-win32, linux libusb)
                // it will have an IUsbDevice interface. If not (WinUSB) the
                // variable will be null indicating this is an interface of a
                // device.
                IUsbDevice wholeUsbDevice = usb as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }

                pinStateBuffer = new byte[64];

                Pins = new List <Pin>();

                // Initialize Pins
                pin1  = new Pin1(this);
                pin2  = new Pin2(this);
                pin3  = new Pin3(this);
                pin4  = new Pin4(this);
                pin5  = new Pin5(this);
                pin6  = new Pin6(this);
                pin7  = new Pin7(this);
                pin8  = new Pin8(this);
                pin9  = new Pin9(this);
                pin10 = new Pin10(this);
                pin11 = new Pin11(this);
                pin12 = new Pin12(this);
                pin13 = new Pin13(this);
                pin14 = new Pin14(this);

                Pins.Add(pin1);
                Pins.Add(pin2);
                Pins.Add(pin3);
                Pins.Add(pin4);
                Pins.Add(pin5);
                Pins.Add(pin6);
                Pins.Add(pin7);
                Pins.Add(pin8);
                Pins.Add(pin9);
                Pins.Add(pin10);
                Pins.Add(pin11);
                Pins.Add(pin12);
                Pins.Add(pin13);
                Pins.Add(pin14);

                SoftPwmMgr = new SoftPwmManager(this);

                // Comparator
                //Comparator1 = new Comparator(1);
                //Comparator2 = new Comparator(2);

                // Initialize modules
                analogOut = new AnalogOut(this);
                i2c       = new I2c(this);
                spi       = new Spi(this);
                //UART = new UART();

                // Initialize endpoint readers/writers
                PinConfig    = usb.OpenEndpointWriter(WriteEndpointID.Ep01);
                pinState     = usb.OpenEndpointReader(ReadEndpointID.Ep01);
                CommsConfig  = usb.OpenEndpointWriter(WriteEndpointID.Ep02);
                CommsReceive = usb.OpenEndpointReader(ReadEndpointID.Ep02);

                // Start reader events
                pinState.DataReceived       += pinState_DataReceived;
                pinState.DataReceivedEnabled = true;
                this.IsConnected             = true;
            }
            else
            {
                if (usb != null)
                {
                    if (usb.IsOpen)
                    {
                        usb.Close();
                    }
                    usb = null;
                }
            }
        }
 /// <summary>
 /// Construct a new 74HC595-type shift register that is directly connected to a Treehopper's SPI port
 /// </summary>
 /// <remarks>
 /// This class supports all 74HC595 shift registers. The name of the class comes from the widely-available TI part.
 /// </remarks>
 public Sn74hc595(Spi spiModule, Pin latchPin, double speedMhz = 1) : base(spiModule, latchPin, 8, SpiMode.Mode00, ChipSelectMode.PulseHighAtEnd, speedMhz)
 {
 }
 /// <summary>
 /// Construct a new instance of the Sn74hc166
 /// </summary>
 /// <param name="spiModule">SPI module to use</param>
 /// <param name="loadPin">latch pin</param>
 public Sn74hc166(Spi spiModule, DigitalOutPin loadPin)
 {
     loadPin.MakeDigitalPushPullOut();
     spiModule.Enabled = true;
 }
 /// <summary>
 /// Construct an STP16CPC26 attached directly to a board SPI module
 /// </summary>
 /// <param name="SpiModule">The board's SPI module</param>
 /// <param name="LatchPin">The pin to use for latches</param>
 /// <param name="OutputEnablePin">The PWM pin to use, allowing controllable global brightness.</param>
 public Stp16cpc26(Spi SpiModule, Pin LatchPin, Pwm OutputEnablePin) : base(SpiModule, LatchPin, 2)
 {
     this.oePwm = OutputEnablePin;
     Start();
 }
 /// <summary>
 /// Construct an STP16CPC26 attached directly to a board SPI module
 /// </summary>
 /// <param name="SpiModule">The board's SPI module</param>
 /// <param name="LatchPin">The pin to use for latches</param>
 /// <param name="OutputEnablePin">The output enable pin, if any, to use.</param>
 public Stp16cpc26(Spi SpiModule, Pin LatchPin, DigitalOutPin OutputEnablePin = null) : base(SpiModule, LatchPin, 2)
 {
     oe = OutputEnablePin;
     Start();
 }