public NeoPixelSession Open() { var data = new ws2811_t { freq = Frequency, dmanum = Dma, channel = new ws2811_channel_t[2] { new ws2811_channel_t { gpionum = GpioPin, count = _ledCount, invert = Invert ? 1 : 0, brightness = Brightness, }, new ws2811_channel_t { }, } }; return new NeoPixelSession(data); }
public WS281x(uint frequency, int dma, int channel1LedCount, int channel1GpioPin, int channel1Brightness, bool channel1Inverted, int channel2LedCount, int channel2GpioPin, int channel2Brightness, bool channel2Inverted) { if (!ValidChannel1Gpios.Contains(channel1GpioPin)) throw new ArgumentException(String.Format("Invalid GPIO Pin {0}, must be one of ({1})", channel1GpioPin, String.Join(", ", ValidChannel1Gpios)), nameof(channel1GpioPin)); if (!ValidChannel2Gpios.Contains(channel2GpioPin)) throw new ArgumentException(String.Format("Invalid GPIO Pin {0}, must be one of ({1})", channel2GpioPin, String.Join(", ", ValidChannel2Gpios)), nameof(channel2GpioPin)); _ws2811 = new ws2811_t { dmanum = 5, channel = new ws2811_channel_t[RPI_PWM_CHANNELS], freq = frequency }; _ws2811.channel[1].brightness = 255; _ws2811.dmanum = dma; _ws2811.freq = frequency; _ws2811.channel[0].count = channel1LedCount; _ws2811.channel[0].gpionum = channel1GpioPin; _ws2811.channel[0].brightness = channel1Brightness; _ws2811.channel[0].invert = channel1Inverted ? 1 : 0; _ws2811.channel[1].count = channel2LedCount; _ws2811.channel[1].gpionum = channel2GpioPin; _ws2811.channel[1].brightness = channel2Brightness; _ws2811.channel[1].invert = channel2Inverted ? 1 : 0; var res = ws2811_init(ref _ws2811); if (res != 0) { throw new ExternalException("Error initializing rpi_ws281x", res); } Channel1 = new Led[_ws2811.channel[0].count]; Channel2 = new Led[_ws2811.channel[1].count]; }
public static extern int ws2811_init(ref ws2811_t ws2811);
static extern int ws2811_wait(ref ws2811_t ws2811);
static extern int ws2811_render(ref ws2811_t ws2811);
static extern void ws2811_fini(ref ws2811_t ws2811);
static extern int ws2811_init(ref ws2811_t ws2811);
internal NeoPixelSession(ws2811_t data) { _data = data; // Have to be careful not to have a race condition here // Maybe create the wrapper which will do the cleandown on finallise // *before* the call to init? var ret = NativeMethods.ws2811_init(ref _data); if (ret != 0) throw new Exception(string.Format("ws2811_init failed - returned {0}", ret)); }