summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Driver.java25
-rw-r--r--src/drivers/DriverManager.java48
-rw-r--r--src/drivers/DriverTypeA.java2
-rw-r--r--src/drivers/Driver_1770_ff00.java (renamed from src/drivers/Device_1770_ff00.java)41
4 files changed, 97 insertions, 19 deletions
diff --git a/src/drivers/Driver.java b/src/drivers/Driver.java
new file mode 100644
index 0000000..d362d19
--- /dev/null
+++ b/src/drivers/Driver.java
@@ -0,0 +1,25 @@
+package org.manzerbredes.open_klm.drivers;
+
+
+/**
+ * Driver must implement this interface
+ *
+ * @author Manzerbredes
+ *
+ */
+public interface Driver{
+
+ /**
+ * Get the type of the driver
+ *
+ * @return class that represent the type of the driver (DriverTypeA.class for example)
+ */
+ public Class<?> getType();
+
+ /**
+ * Initialise the driver (do not initialise anything in the constructor).
+ *
+ * @return true if success (device is present and accessible) false else.
+ */
+ public boolean initDriver();
+} \ No newline at end of file
diff --git a/src/drivers/DriverManager.java b/src/drivers/DriverManager.java
new file mode 100644
index 0000000..9a3c37c
--- /dev/null
+++ b/src/drivers/DriverManager.java
@@ -0,0 +1,48 @@
+package org.manzerbredes.open_klm.drivers;
+
+
+/**
+ * Driver Manager
+ *
+ * @author Manzerbredes
+ *
+ */
+public class DriverManager{
+
+ /**
+ * List of avalaible drivers
+ */
+ private Class<?>[] drivers={
+ Driver_1770_ff00.class
+ };
+
+
+
+ /**
+ * Get a successfully loaded driver
+ *
+ * @return Driver the loaded driver.
+ */
+ public Driver getDevice(){
+ // Walk on driver list
+ for(int i=0;i<this.drivers.length;i++){
+ // Try to load each drivers
+ try {
+ Driver drv=(Driver) this.drivers[i].newInstance();
+ // If success return it
+ if(drv.initDriver())
+ return drv;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // If no driver avalaible
+ return null;
+ }
+
+
+
+
+
+
+} \ No newline at end of file
diff --git a/src/drivers/DriverTypeA.java b/src/drivers/DriverTypeA.java
index 37e8d4c..e7048df 100644
--- a/src/drivers/DriverTypeA.java
+++ b/src/drivers/DriverTypeA.java
@@ -1,7 +1,7 @@
package org.manzerbredes.open_klm.drivers;
/**
- * Basic driver with basic functionalities.
+ * Driver of type A (driver with is own functionalities).
*
* @author Manzerbredes
*
diff --git a/src/drivers/Device_1770_ff00.java b/src/drivers/Driver_1770_ff00.java
index 77ee461..9f849f9 100644
--- a/src/drivers/Device_1770_ff00.java
+++ b/src/drivers/Driver_1770_ff00.java
@@ -14,7 +14,7 @@ import com.codeminders.hidapi.*;
* @author Manzerbredes
*
*/
-public class Device_1770_ff00 implements DriverTypeA{
+public class Driver_1770_ff00 implements Driver, DriverTypeA{
@@ -32,17 +32,10 @@ public class Device_1770_ff00 implements DriverTypeA{
* Define Keyboard mode state
*/
private Mode mode=Mode.NORMAL;
-
-
-
-
-
- /**
- * Init driver and HIDAPI library
- *
- * @throws InstantiationException
- */
- public Device_1770_ff00() throws InstantiationException{
+
+
+ @Override
+ public boolean initDriver(){
// Init HIDAPI Library
com.codeminders.hidapi.ClassPathLibraryLoader.loadNativeHIDLibrary();
@@ -50,13 +43,13 @@ public class Device_1770_ff00 implements DriverTypeA{
try {
HIDManager man=HIDManager.getInstance();
this.device=man.openById(0x1770, 0xff00, null);
- if(this.device==null)
- throw new Exception();
+ if(this.device!=null)
+ return true;
}
catch(Exception e){
- throw new InstantiationException("Failed to instanciate driver. Device not found or permission denied (try as root)");
+ System.err.println(e.getMessage());
}
-
+ return false;
}
@@ -90,7 +83,9 @@ public class Device_1770_ff00 implements DriverTypeA{
-
+ /**
+ * Commit (apply current mode to update the color)
+ */
private void commit(){
try {
this.device.sendFeatureReport(this.getReport(1,2,65,this.mode.intValue(),0,0,0,236));
@@ -135,5 +130,15 @@ public class Device_1770_ff00 implements DriverTypeA{
this.mode=mode;
this.commit();
}
-
+
+
+ @Override
+ public Class<?> getType() {
+ return DriverTypeA.class;
+ }
+
+
+
+
+
} \ No newline at end of file