summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-29 18:05:00 +0200
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-29 18:05:00 +0200
commit09b9f7cad0d4013a228e2d7019cfd9067ef49bd7 (patch)
tree70f62b3681e79b4f3090b17d192b44526dd19ed2
parentfafcd1ba9f737b7803cc92f5b199df05235b1066 (diff)
Add waves mode
-rw-r--r--src/app/App.java9
-rw-r--r--src/client/MainWindow.java3
-rw-r--r--src/drivers/DriverTypeA.java16
-rw-r--r--src/drivers/Driver_1770_ff00.java76
4 files changed, 89 insertions, 15 deletions
diff --git a/src/app/App.java b/src/app/App.java
index 8de6d69..adec5cc 100644
--- a/src/app/App.java
+++ b/src/app/App.java
@@ -5,7 +5,6 @@ import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.manzerbredes.open_klm.client.MainWindow;
import org.manzerbredes.open_klm.drivers.*;
-import org.manzerbredes.open_klm.drivers.DriverTypeA;
import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
/**
@@ -52,6 +51,14 @@ public class App
parser.parseArgument(args);
app.parseArguments();
new MainWindow();
+ /* DriverTypeA device=new Driver_1770_ff00();
+ Driver a=(Driver) device;
+ a.initDriver();
+ device.setRegionColor(Region.LEFT, Color.RED, Intensity.HIGH);
+ device.setRegionColor(Region.MIDDLE, Color.ORANGE, Intensity.HIGH);
+ device.setRegionColor(Region.RIGHT, Color.PURPLE, Intensity.HIGH);
+
+ device.setMode(Mode.WAVE);*/
}
}
diff --git a/src/client/MainWindow.java b/src/client/MainWindow.java
index 1f24f64..f159621 100644
--- a/src/client/MainWindow.java
+++ b/src/client/MainWindow.java
@@ -12,8 +12,9 @@ import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
-import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
import org.manzerbredes.open_klm.drivers.*;
+import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
+
public class MainWindow extends JFrame {
diff --git a/src/drivers/DriverTypeA.java b/src/drivers/DriverTypeA.java
index a1166ee..4ad936e 100644
--- a/src/drivers/DriverTypeA.java
+++ b/src/drivers/DriverTypeA.java
@@ -92,7 +92,6 @@ public interface DriverTypeA{
}
-
/**
* Set color of the region
* @param region
@@ -109,6 +108,21 @@ public interface DriverTypeA{
public void setColor(Color color, Intensity intensity);
/**
+ * Set global secondary color (for waves)
+ * @param color
+ * @param intensity
+ */
+ public void setSecondaryColor(Color color, Intensity intensity);
+
+ /**
+ * Set secondary color (for waves) by region
+ * @param region
+ * @param color
+ * @param intensity
+ */
+ public void setSecondaryRegionColor(Region region, Color color, Intensity intensity);
+
+ /**
* Set keyboard mode
* @param mode
*/
diff --git a/src/drivers/Driver_1770_ff00.java b/src/drivers/Driver_1770_ff00.java
index 9b1d169..59c4dcb 100644
--- a/src/drivers/Driver_1770_ff00.java
+++ b/src/drivers/Driver_1770_ff00.java
@@ -8,7 +8,7 @@ import com.codeminders.hidapi.*;
/**
*
- * Driver to communicate with the keyboard device
+ * Driver to communicate with the keyboard device 1770 ff00
* using HIDAPI.
*
* @author Manzerbredes
@@ -22,9 +22,14 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
HIDDevice device;
/**
- * Define Keyboard color state
+ * Define Keyboard primary color state
*/
- private HashMap<Region, Pair<Color,Intensity>> keyboardColorsState=new HashMap<>();
+ private HashMap<Region, Pair<Color,Intensity>> primaryColorsState=new HashMap<>();
+
+ /**
+ * Define Keyboard secondary color state (for wave)
+ */
+ private HashMap<Region, Pair<Color,Intensity>> secondaryColorsState=new HashMap<>();
/**
* Define Keyboard mode state
@@ -41,8 +46,20 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
try {
HIDManager man=HIDManager.getInstance();
this.device=man.openById(0x1770, 0xff00, null);
- if(this.device!=null)
+ if(this.device!=null){
+ // Init primary color state
+ this.primaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
+ this.primaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
+ this.primaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
+ // Init secondary color state
+ this.secondaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
+ this.secondaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
+ this.secondaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
+ // Init mode
+ this.mode=Mode.NORMAL;
+ // Return true (init successfully done)
return true;
+ }
}
catch(Exception e){
System.err.println(e.getMessage());
@@ -52,7 +69,7 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
/**
- * Build a byte[] report
+ * Build a byte[] report for convenience.
*
* @param a
* @param b
@@ -77,7 +94,6 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
try {
this.device.sendFeatureReport(this.getReport(1,2,65,this.mode.intValue(),0,0,0,236));
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
@@ -88,9 +104,8 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
try {
this.device.sendFeatureReport(this.getReport(1,2,66,region.intValue(),color.intValue(),intensity.intValue(),0,236));
this.commit();
- this.keyboardColorsState.put(region, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.primaryColorsState.put(region, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
@@ -105,12 +120,11 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
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.commit();
- this.keyboardColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
- this.keyboardColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
- this.keyboardColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.primaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.primaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.primaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
@@ -120,6 +134,29 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
@Override
public void setMode(Mode mode) {
this.mode=mode;
+
+ // Apply wave mode
+ if(this.mode==Mode.WAVE){
+ for(int i=0;i<Region.values().length;i++){
+ int entry=i*3; // 3 entry for each region (left:1,2,3 -- middle:4,5,6 -- right:7,8,9)
+ try {
+ // Set primary color (with 2 of intensity for speed problem)
+ // TODO Check intensity (fixed for speed) :
+ this.device.sendFeatureReport(this.getReport(1,2,67,entry+1 ,this.primaryColorsState.get(Region.values()[i]).getValue0().intValue(),2,0,236));
+ // Set secondary color
+ this.device.sendFeatureReport(this.getReport(1,2,67,entry+2 ,this.secondaryColorsState.get(Region.values()[i]).getValue0().intValue(),this.secondaryColorsState.get(Region.values()[i]).getValue1().intValue(),0,236));
+ // Set period
+ // TODO Check period :
+ this.device.sendFeatureReport(this.getReport(1,2,67,entry+3 ,2,2,0,236));
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ // Apply mode
this.commit();
}
@@ -130,6 +167,21 @@ public class Driver_1770_ff00 implements Driver, DriverTypeA{
}
+ @Override
+ public void setSecondaryColor(Color color, Intensity intensity) {
+ this.secondaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.secondaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ this.secondaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ }
+
+
+ @Override
+ public void setSecondaryRegionColor(Region region, Color color, Intensity intensity) {
+ this.secondaryColorsState.put(region, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(color, intensity));
+ }
+
+
+