-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConfiguredCamera handling (untested)
- Loading branch information
Showing
18 changed files
with
394 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# Eazy BookScanner | ||
|
||
OpenSource Book Scanner application for digitizing books with two cameras. | ||
Usage for two digital cameras like described at <http://diybookscanner.org/>. | ||
|
||
![Screenshot GUI Eazy BookScanner](./screenshot-20201221.jpg) | ||
|
||
## References | ||
|
||
* Swing: https://zetcode.com/javaswing/ | ||
* Icons: https://www.javacodegeeks.com/2020/03/javafx-tip-32-need-icons-use-ikonli.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 40 additions & 10 deletions
50
...-bookscanner-swing/src/main/java/com/datazuul/eazy/bookscanner/devices/CameraFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...kscanner-swing/src/main/java/com/datazuul/eazy/bookscanner/devices/CamerasProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.datazuul.eazy.bookscanner.devices; | ||
|
||
import java.util.List; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
|
||
@ConfigurationProperties(prefix = "cameras") | ||
@ConfigurationPropertiesScan | ||
public class CamerasProperties { | ||
|
||
private List<Vendor> vendors; | ||
|
||
public List<Vendor> getVendors() { | ||
return vendors; | ||
} | ||
|
||
public void setVendors(List<Vendor> vendors) { | ||
this.vendors = vendors; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CamerasProperties{" + "vendors=" + vendors + '}'; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...okscanner-swing/src/main/java/com/datazuul/eazy/bookscanner/devices/ConfiguredCamera.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.datazuul.eazy.bookscanner.devices; | ||
|
||
import chdk.ptp.java.camera.FailSafeCamera; | ||
import chdk.ptp.java.exception.GenericCameraException; | ||
import chdk.ptp.java.exception.PTPTimeoutException; | ||
import chdk.ptp.java.model.FocusMode; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.usb.UsbDevice; | ||
|
||
public class ConfiguredCamera extends FailSafeCamera { | ||
|
||
private Logger log = Logger.getLogger(ConfiguredCamera.class.getName()); | ||
|
||
private final Product product; | ||
|
||
public ConfiguredCamera(UsbDevice device, Product product) { | ||
super(device); | ||
this.product = product; | ||
} | ||
|
||
@Override | ||
public void setFocusMode(FocusMode mode) throws GenericCameraException, PTPTimeoutException { | ||
try { | ||
Thread.sleep(500); | ||
} catch (InterruptedException e) { | ||
log.log(Level.SEVERE, e.getLocalizedMessage(), e); | ||
throw new GenericCameraException(e.getLocalizedMessage()); | ||
} | ||
|
||
// currently only supporting autofocus mode | ||
if (FocusMode.AUTO.equals(mode)) { | ||
List<FocusModeChange> autofocus = product.getAutofocus(); | ||
int currentFocusMode = getFocusMode().getValue(); | ||
for (FocusModeChange focusModeChange : autofocus) { | ||
if (currentFocusMode == focusModeChange.getCurrentMode()) { | ||
List<String> commands = focusModeChange.getExecute(); | ||
if (commands != null) { | ||
for (String command : commands) { | ||
switch (command) { | ||
case "LEFT": | ||
this.executeLuaCommand("click('left');"); | ||
break; | ||
case "RIGHT": | ||
this.executeLuaCommand("click('right');"); | ||
break; | ||
case "SET": | ||
this.executeLuaCommand("click('set');"); | ||
break; | ||
default: | ||
break; | ||
} | ||
if (command.startsWith("sleep")) { | ||
long milliseconds = Long.valueOf(command.substring(5)); | ||
try { | ||
Thread.sleep(milliseconds); | ||
} catch (InterruptedException ex) { | ||
log.log(Level.SEVERE, ex.getLocalizedMessage(), ex); | ||
throw new GenericCameraException(ex.getLocalizedMessage()); | ||
} | ||
} | ||
} | ||
} | ||
// activate auto focus and focus | ||
try { | ||
this.executeLuaCommand("set_aflock(0);"); | ||
this.executeLuaCommand("press('shoot_half');"); | ||
Thread.sleep(800); | ||
this.executeLuaCommand("release('shoot_half');"); | ||
this.executeLuaCommand("set_aflock(1);"); | ||
Thread.sleep(1000); | ||
} catch (InterruptedException ex) { | ||
log.log(Level.SEVERE, ex.getLocalizedMessage(), ex); | ||
throw new GenericCameraException(ex.getLocalizedMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setZoom(int zoomPosition) throws PTPTimeoutException, GenericCameraException { | ||
Zoom zoom = product.getZoom(); | ||
if (zoom != null) { | ||
List<String> preExecute = zoom.getPreExecute(); | ||
for (String command : preExecute) { | ||
switch (command) { | ||
case "SET_AUTOFOCUS": | ||
setFocusMode(FocusMode.AUTO); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
super.setZoom(zoomPosition); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ookscanner-swing/src/main/java/com/datazuul/eazy/bookscanner/devices/FocusModeChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.datazuul.eazy.bookscanner.devices; | ||
|
||
import java.util.List; | ||
|
||
public class FocusModeChange { | ||
|
||
private int currentMode; | ||
private List<String> execute; | ||
|
||
public int getCurrentMode() { | ||
return currentMode; | ||
} | ||
|
||
public List<String> getExecute() { | ||
return execute; | ||
} | ||
|
||
public void setCurrentMode(int currentMode) { | ||
this.currentMode = currentMode; | ||
} | ||
|
||
public void setExecute(List<String> execute) { | ||
this.execute = execute; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FocusModeChange{" + "currentMode=" + currentMode + ", execute=" + execute + '}'; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
eazy-bookscanner-swing/src/main/java/com/datazuul/eazy/bookscanner/devices/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.datazuul.eazy.bookscanner.devices; | ||
|
||
import java.util.List; | ||
|
||
public class Product { | ||
|
||
private List<FocusModeChange> autofocus; | ||
private Short id; | ||
private String name; | ||
private Zoom zoom; | ||
|
||
public List<FocusModeChange> getAutofocus() { | ||
return autofocus; | ||
} | ||
|
||
public Short getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Zoom getZoom() { | ||
return zoom; | ||
} | ||
|
||
public void setAutofocus(List<FocusModeChange> autofocus) { | ||
this.autofocus = autofocus; | ||
} | ||
|
||
public void setId(Short id) { | ||
this.id = id; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setZoom(Zoom zoom) { | ||
this.zoom = zoom; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Product{" + "autofocus=" + autofocus + ", id=" + id + ", name=" + name + ", zoom=" + zoom + '}'; | ||
} | ||
} |
Oops, something went wrong.