blink(1) mk2 is a very nice USB status light made by ThingM. This project, called blink4java aim to build a java library to control the blink.
We use the usb4java implementation of the JSR 080 for communication with USB devices. As usb4java rely on LibUsb, it should work on every platform (Linux, OSX, Windows).
Currently blink4java is only tested on Linux (ubuntu).
BlinkLocator
is used to locate the blink connected to your system.
A call to BlinkLocator.findBlinks()
will return a list of Blink
.
Blink represent a physical blink(1) device. Just call methods on it :)
Here is the code to find all blinks and ask them to fade to white.
// find all blinks
List<Blink> blinks = BlinkLocator.findBlinks(UsbHostManager.getUsbServices().getRootUsbHub());
RGBColor whiteColor = new RGBColor(255, 255, 255);
//Iterate over all blinks
for(Blink blink : blinks) {
//ask the current blink to fade to white in 3s
blink.fadeToColor(whiteColor, 3000);
}
Rmq : you should not create an instance of Blink by yourself, let BlinkLocator do it for you.
Here are the command already implemented on Blink
setColor(RGBColor color)
set the color of the ledsfadeToColor(RGBColor color, int fadeTime, BlinkLed led)
askled
to fade to the givencolor
infadeTime
millisecondsfadeToColor(RGBColor color, int fadeTime)
is a shortcut to `fadeToColor(color, fadeTime, BlinkLed.ALL_LEDS)RGBColor readCurrentColor(BlinkLed led)
return the current color of the specified led. Note : even with a fadeTime=0, fadeToColor is not instantaneous and readCurrentColor may return an intermediate value if executed just after fadeToColor.setPatternLine(PatternLine line)
set the PatternLinePatternLine readPatternLineAt(int position)
return the patternLine at positionplayPattern()
play the current pattern in loop foreverplayPattern(int startingPoint, int endingPoint, int repeat)
play the pattern from startingPoint position to endingPoint position for repeat timespausePattern()
stop playing pattern. (note: blink1 will stay with the last color displayed)savePattern()
save the pattern in the flash memory so the pattern will survive to a power off. (warning: previous pattern will be unrecoverable!)