in the code below, I slightly modified the examples from the example, this sets the first LED to white, then attempts to turn the device off, then I set the color to green.
the device, turns on white, then green, no exceptions thrown.
public static void Main (string[] args)
{
BlinkStick device = BlinkStick.FindFirst ();
if (device != null) {
if (device.OpenDevice ()) {
device.SetMode (2);
device.SetColor(0,0,"#ffffff");
device.TurnOff();
device.SetColor(0,0,"#00ff00");
} else {
Console.WriteLine ("Could not open the device");
}
} else {
Console.WriteLine ("BlinkStick not found");
}
}
I believe the issue is in the SDK, this will from my understanding, and testing only turn off the first LED, and it doesn’t actually turn off the device, it just sets the color to black. After reviewing many of the functions in the API, it doesn’t look like the majority of them have been adapted for use with Multiple LEDs, is that accurate?
public void TurnOff()
{
SetColor(0, 0, 0);
}
should be something like
public void TurnOff() {
int numberOfLeds = 0;
numberOfLeds = device.GetLedCount(); //this at times has thrown exeception for being unable to retrive count.
if (numberOfLeds > 0)
{
for (byte i = 0; i < numberOfLeds; i++)
{
device.SetColor(0, i, 0);
Thread.Sleep(20); //would rather avoid thread sleep, implement OnReceiveColor per index
}
}
}
Ah, now I understand:
You cannot TurnOff a complete device like flex because the SDK does not know how many LEDs you have connected. The amout of LEDs attached to a flex could be variable.
Please find the post here how to solve this: Set_Colors
Set all your LEDs to off with the very fast Set_Colors function.
I suggest then that the API be updated to something like this.
public void TurnOff()
{
int numberOfLeds = 0;
numberOfLeds = device.GetLedCount();
byte[] data = new byte[numberOfLeds * 3]; //each LED has 3 bytes of data (GRB), default for new byte array is 0 all zeros is black, or off
SetColors(0,data);
}
This should get a count of the LEDs, and produce 3 bytes per, of 0, setting all to black.
I don’t have the device in front of me at the moment, so anyone able to double check this?
@bruce thanks for the suggestion. Will have it implemented in the next release. It’s a bit more complicated as all devices have to be supported, but I have this implemented in the client application so it should be no problem to port it to the library.