/// <summary> /// Constructor for LED_APA102 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on Raspi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> public LED_APA102(SpiDevice spiInterface, SPIAddressObject spiAdr) : base(spiInterface, spiAdr, InterfaceConstrains, DriverDefines) { LEDs = new List <RGBset>(); //@todo hier ggf. auf etwas Ressourcenschonenderes umsteigen AddLED(RGBDefines.Black); }
/// <summary> /// Constructor for TLC_5925 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="lePin">Latch enable pin (LE-Pin) to latch the port values to internal register</param> /// <param name="oePin">Output enable pin (optional) disables LED-driver when high, accepts null if not connected</param> public LEDD_TLC5925(SpiDevice spiInterface, SPIAddressObject spiAdr, GpioPin lePin, GpioPin oePin) : base(spiInterface, spiAdr, InterfaceConstrains, DriverDefines) { // Check if an SPI Object is valid if (lePin != null) { LEpin = lePin; if (oePin != null) { // Set Blank Option to Blank Pin OEpin = oePin; LEDSpecifigdefines.BlankOptions = LEDdriverSpecificDefinitions.eLEDBlankOptions.BlankInput; OEpin.Write(GpioPinValue.High); // Set Outputs in Safe State OEpin.SetDriveMode(GpioPinDriveMode.Output); } LEpin.Write(GpioPinValue.Low); LEpin.SetDriveMode(GpioPinDriveMode.Output); PortData = new List <UInt16>(); /// Add first LED to daisy-chain AddLED(0); } else { base.SPIhandle = null; throw new Exception("Missing Handle for LE-Pin"); } }
/// <summary> /// Constructor for DAC_MCP4922 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="syncPin">Sync pin definition to (optional) sync both DAC ports together</param> /// <param name="shdownPin">Shutdown pin (optional) to shutdown DAC-slave </param> public DAC_MCP4922(SpiDevice spiInterface, SPIAddressObject spiAdr, GpioPin syncPin, GpioPin shdownPin) : base(spiInterface, spiAdr, InterfaceConstrains, ConverterDefines) { //@todo Hier noch berücksichtigen und was darauf machen LDACpin = syncPin; SHDNpin = shdownPin; }
/// <summary> /// TimerInitialisation /// </summary> private async void InitAll() { StripeTimer = new DispatcherTimer(); StripeTimer.Interval = TimeSpan.FromMilliseconds(refreshCycle); StripeTimer.Tick += StripeRefresh_Tick; PatternTimer = new DispatcherTimer(); PatternTimer.Interval = TimeSpan.FromMilliseconds(patternPeriod); PatternTimer.Tick += ChangePattern_Tick; GPIOvar = GpioController.GetDefault(); /* Get the default GPIO controller on the system */ await InitSpi(); /* Initialize the SPI controller */ CSadrLEDD = new SPIAddressObject(SPIAddressObject.eCSadrMode.SPIdedicated, null, null, 0); ColorStripe = new LED_APA102(SPIinterface_Demo, CSadrLEDD); // Bei der Instanziierung wird erstes LED-Objekt erstellt. for (int i = 0; i < StripeLen - 1; i++) { ColorStripe.AddLED(RGBDefines.Black); } // LED-Demo StripePattern = new PatternGenerator(StripeLen, 1); StripePattern.AddCurve(PatternGenerator.eCurveType.Sine); StripePattern.AddCurve(PatternGenerator.eCurveType.Pulse); StripePattern.AddCurve(PatternGenerator.eCurveType.Cosine); StripePattern.AddCurve(PatternGenerator.eCurveType.Triangle); StripePattern.AddCurve(PatternGenerator.eCurveType.Sawtooth); StripeTimer.Start(); }
/// <summary> /// Constructor for generic GPIO /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="givenConstrains">Restriction for using the respective device</param> /// <param name="givenSpecs">Specifications of given GPIO-slave</param> public GenreicGPIOslave(SpiDevice spiInterface, SPIAddressObject spiAdr, SPIHardwareConstrains givenConstrains, GPIOspecificDefinitions givenSpecs) : base(spiInterface, spiAdr, givenConstrains) { GPIOdefines = givenSpecs; PortData = new byte[GPIOdefines.NumOfPorts]; ExecuteConfigRun(eConfigRunMode.DeviceConfigOnly); }
private void InitIOModule() { CSadrADC = new SPIAddressObject(SPIAddressObject.eCSadrMode.SPIwithCSdemux, null, CSAdrSelection, HW_ADC_CSadr); CSadrDAC = new SPIAddressObject(SPIAddressObject.eCSadrMode.SPIwithCSdemux, null, CSAdrSelection, HW_DAC_CSadr); CSadrGPIO = new SPIAddressObject(SPIAddressObject.eCSadrMode.SPIwithCSdemux, null, CSAdrSelection, HW_GPIO_CSadr); CSadrLEDD = new SPIAddressObject(SPIAddressObject.eCSadrMode.SPIdedicated, null, null, 0); GSLEDdriver = new LEDD_TLC5941(SPIOInterface, CSadrLEDD, GSLEDdriverLatch, GSLEDdriverMode, GSLEDdriverBlank); DCLEDDriver = new LEDD_TLC5925(SPIOInterface, CSadrLEDD, DCLEDdriverLatch, null); //StatusLED = new LED_APA102(StatusLEDInterface, CSadrLEDD); DACslave = new DAC_MCP4922(SPIOInterface, CSadrDAC, null, null); ADCslave = new ADC_MCP3208(SPIOInterface, CSadrADC); GPIOslave = new GPIO_MCP23S17(SPIOInterface, CSadrGPIO, null, null, 0); }
/// <summary> /// Constructor for DAC_MCP23S17 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="rstPin">Rest pin (optional) to reset device</param> /// <param name="intPin">Interrupt Input pins (optional) for interrupt handling</param> /// <param name="spiBusAddress">Intrinsic SPI-address witch is to be send via SPI message</param> public GPIO_MCP23S17(SpiDevice spiInterface, SPIAddressObject spiAdr, GpioPin rstPin, GpioPin[] intPin, int spiBusAddress) : base(spiInterface, spiAdr, InterfaceConstrains, ConverterDefines) { //@todo Hier noch berücksichtigen Resetpin = rstPin; if (intPin != null) { if (intPin.Length >= 1) { IntApin = intPin[0]; } if (intPin.Length >= 2) { IntBpin = intPin[1]; } } base.SPIbusAddress = spiBusAddress; }
/// <summary> /// Constructor for LEDD_TLC5941 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="xlatPin">Latch enable pin to latch the port-values to internal register</param> /// <param name="modePin">Mode pin defines whether the correction or gray-values are written</param> /// <param name="blankPin">Output enable pin (optional). Disables LED-driver when high, accepts null if not connected</param> public LEDD_TLC5941(SpiDevice spiInterface, SPIAddressObject spiAdr, GpioPin xlatPin, GpioPin modePin, GpioPin blankPin) : base(spiInterface, spiAdr, InterfaceConstrains, DriverDefines) { /// Check if an SPI object is valid if ((xlatPin != null) || (modePin != null)) { XLatPin = xlatPin; ModePin = modePin; if (blankPin != null) { /// Set Blank Option to Blank Pin BlankPin = blankPin; LEDSpecifigdefines.BlankOptions = LEDdriverSpecificDefinitions.eLEDBlankOptions.BlankInput; blankPin.Write(GpioPinValue.High); // Set Outputs in Safe State blankPin.SetDriveMode(GpioPinDriveMode.Output); } XLatPin.Write(GpioPinValue.Low); XLatPin.SetDriveMode(GpioPinDriveMode.Output); ModePin.Write(GpioPinValue.Low); ModePin.SetDriveMode(GpioPinDriveMode.Output); PortData = new List <UInt16[]>(); /// Add first LED Driver to daisy-chain UInt16[] firstData = new ushort[1] { 0 }; AddLED(firstData); } else { base.SPIhandle = null; throw new Exception("Missing Handle for XLAT-Pin and/or Mode-Pin"); } }
/// <summary> /// Constructor for RasPiMultiSlave /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination (optional) to address the slave during transmission of data, /// can be null if no address definition needed</param> /// <param name="givenConstrains">Restriction for the respective device</param> public RaspiMultiSlave(SpiDevice spiInterface, SPIAddressObject spiAdr, SPIHardwareConstrains givenConstrains) { /// check if the SP-interface is defined if (spiInterface != null) { SpiConnectionSettings tempSet = spiInterface.ConnectionSettings; SPIconstrains = givenConstrains; /// Check whether the SPI-configuration meets demanded configuration //@todo Prüfen ob die Abfrage so überhaupt funktioniert if (tempSet.ClockFrequency < SPIconstrains.MinSPIclock) { spiInterface = null; throw new Exception("SPI-Clock doesn't meet the Specification: Clock was set to low"); } if (tempSet.ClockFrequency > SPIconstrains.MaxSPIclock) { spiInterface = null; throw new Exception("SPI-Clock doesn't meet the Specification: Clock was set to high"); } if (tempSet.Mode != SPIconstrains.DemandedSPIMode) { //@todo ggf. hier die Restriktion herausnehmen, wenn SPI on the Fly umkonfiguriert werden kann spiInterface = null; throw new Exception("SPI-Mode doesned meet the Specification"); } if (spiAdr != null) { switch (spiAdr.CSmode) { //@todo Hier prüfen was bei dem Kopieren passiert case SPIAddressObject.eCSadrMode.NoCSPort: case SPIAddressObject.eCSadrMode.SPIdedicated: // no further treatment necessary break; case SPIAddressObject.eCSadrMode.SPIwithGPIO: if (spiAdr.GpioCSpin != null) { throw new Exception("GPIO-Pin for CS use (SPIAddressObject.gpioCSpin) is not defined"); } // Set the CS-Pin high by default spiAdr.GpioCSpin.SetDriveMode(GpioPinDriveMode.Output); this.resetCSsignal(); break; case SPIAddressObject.eCSadrMode.SPIwithCSdemux: if (spiAdr.CSadrPins.Length == 0) { throw new Exception("There are no Address-Pins for CS-Demux specified"); } if (spiAdr.GpioCSpin != null) { spiAdr.GpioCSpin.SetDriveMode(GpioPinDriveMode.Output); } for (int idx = 0; idx < spiAdr.CSadrPins.Length; idx++) { spiAdr.CSadrPins[idx].SetDriveMode(GpioPinDriveMode.Output); } this.resetCSsignal(); break; default: throw new Exception("Some crazy shit just happend. The switch parameter is an enum hence this state should be impossible"); } CSadr = spiAdr; } else { //@todo hier ein Objekt definieren, dass modus ohne CS-Leitung wählt CSadr = new SPIAddressObject(SPIAddressObject.eCSadrMode.NoCSPort, null, null, 0); } /// Memorize SPI-Handle for further usage SPIhandle = spiInterface; } else { throw new Exception("Missing SP-interface-definition"); } }
/// <summary> /// Constructor for MCP_3208 /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> public ADC_MCP3208(SpiDevice spiInterface, SPIAddressObject spiAdr) : base(spiInterface, spiAdr, InterfaceConstrains, ConverterDefines) { /// Nothing to do here }
/// <summary> /// Constructor for LED-driver /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="givenConstrains">Restriction for using the respective device</param> /// <param name="givenSpecs">Specifications of given LED-Slave</param> public GenreicLEDslave(SpiDevice spiInterface, SPIAddressObject spiAdr, SPIHardwareConstrains givenConstrains, LEDdriverSpecificDefinitions givenSpecs) : base(spiInterface, spiAdr, givenConstrains) { LEDSpecifigdefines = givenSpecs; }
/// <summary> /// Constructor for generic ADC /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="givenConstrains">Restriction for using the respective device</param> /// <param name="givenSpecs">Specifications of given ADC-Slave</param> public GenreicADCslave(SpiDevice spiInterface, SPIAddressObject spiAdr, SPIHardwareConstrains givenConstrains, ADCspecificDefinitions givenSpecs) : base(spiInterface, spiAdr, givenConstrains) { ADCdefines = givenSpecs; ADCresults = new Int16[ADCdefines.NumOfADCchannels]; }
/// <summary> /// Constructor for generic DAC /// </summary> /// <param name="spiInterface"> Defines the SP-interface on RasPi board</param> /// <param name="spiAdr">Defines the CS-address combination for addressing the slave</param> /// <param name="givenConstrains">Restriction for using the respective device</param> /// <param name="givenSpecs">Specifications of given DAC-Slave</param> public GenreicDACslave(SpiDevice spiInterface, SPIAddressObject spiAdr, SPIHardwareConstrains givenConstrains, DACspecificDefinitions givenSpecs) : base(spiInterface, spiAdr, givenConstrains) { DACdefines = givenSpecs; DACvalues = new Int16[DACdefines.NumOfDACchannels]; }