diff options
Diffstat (limited to 'src/device/Driver.java')
| -rw-r--r-- | src/device/Driver.java | 158 |
1 files changed, 157 insertions, 1 deletions
diff --git a/src/device/Driver.java b/src/device/Driver.java index 25257a7..7a8bc7b 100644 --- a/src/device/Driver.java +++ b/src/device/Driver.java @@ -1,5 +1,9 @@ package org.manzerbredes.open_klm.device; +import java.io.IOException; + +import com.codeminders.hidapi.HIDDevice; +import com.codeminders.hidapi.HIDManager; /** * @@ -12,11 +16,163 @@ package org.manzerbredes.open_klm.device; public class Driver{ /** + * Defined Region Helper + * + * @author Manzerbredes + * + */ + public enum Region{ + LEFT(1), MIDDLE(2), RIGHT(3); + + private int current; + + Region(int current){ + this.current=current; + } + + public int intValue(){ + return this.current; + } + } + + /** + * Defined Color Helper + * + * @author Manzerbredes + * + */ + public enum Color{ + OFF(0),RED(1),ORANGE(2),YELLOW(3),GREEN(4),SKY(5), BLUE(6),PURPLE(7),WHITE(8); + + private int current; + + Color(int current){ + this.current=current; + } + + public int intValue(){ + return this.current; + } + } + + /** + * Defined Level Helper + * + * @author Manzerbredes + * + */ + public enum Intensity{ + HIGH(0), MEDIUM(1), LOW(2), LIGHT(3); + + private int current; + + Intensity(int current){ + this.current=current; + } + + public int intValue(){ + return this.current; + } + } + + /** + * Defined Mode Helper + * + * @author Manzerbredes + * + */ + public enum Mode{ + NORMAL(1), GAMING(2), BREATHE(3), DEMO(4), WAVE(5); + + private int current; + + Mode(int current){ + this.current=current; + } + + public int intValue(){ + return this.current; + } + } + + + + + + + + /** + * Device entry + */ + HIDDevice device; + + + /** * Init driver and HIDAPI library + * + * @throws InstantiationException */ - public Driver(){ + public Driver() throws InstantiationException{ // Init HIDAPI Library com.codeminders.hidapi.ClassPathLibraryLoader.loadNativeHIDLibrary(); + + try { + HIDManager man=HIDManager.getInstance(); + this.device=man.openById(0x1770, 0xff00, null); + } + catch(Exception e){ + throw new InstantiationException("Failed to instanciate driver."); + } + + } + + + /** + * Build a byte[] report + * + * @param a + * @param b + * @param c + * @param d + * @param e + * @param f + * @param g + * @param h + * @return + */ + private byte[] getReport(int a, int b, int c, int d, int e, int f, int g, int h){ + byte[] message = new byte[8]; + message[0] = (byte) a; + message[1] = (byte) b; + message[2] = (byte) c; + message[3] = (byte) d; + message[4] = (byte) e; + message[5] = (byte) f; + message[6] = (byte) g; + message[7] = (byte) h; + return message; + } + + + public void setColor(Color color, Intensity intensity){ + try { + this.device.sendFeatureReport(this.getReport(1,2,66,Region.LEFT.intValue(),color.intValue(),intensity.intValue(),0,236)); + this.device.sendFeatureReport(this.getReport(1,2,66,Region.MIDDLE.intValue(),color.intValue(),intensity.intValue(),0,236)); + this.device.sendFeatureReport(this.getReport(1,2,66,Region.RIGHT.intValue(),color.intValue(),intensity.intValue(),0,236)); + this.setMode(Mode.NORMAL); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setMode(Mode mode){ + try { + this.device.sendFeatureReport(this.getReport(1,2,65,mode.intValue(),0,0,0,236)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } }
\ No newline at end of file |
