diff --git a/.gitignore b/.gitignore index 1fcb152..ab4abd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ out +*.class diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6ba5786..e035d51 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,14 @@ - + + + + + + + + @@ -22,51 +29,28 @@ - - - - - - - - - - - - - - - - - - - - - - + + - - - - + + + + - - + + - - - - - - + + + @@ -74,8 +58,8 @@ - - + + @@ -86,8 +70,8 @@ - - + + @@ -95,6 +79,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -116,31 +162,31 @@ @@ -431,26 +477,26 @@ - - + + + + + + - + - - - - @@ -499,38 +545,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -552,8 +566,8 @@ - - + + @@ -592,14 +606,10 @@ - - - - - - - - + + + + @@ -610,10 +620,10 @@ - - - - + + + + @@ -633,8 +643,8 @@ - - + + @@ -654,8 +664,8 @@ - - + + @@ -674,14 +684,10 @@ - - - - - - - - + + + + @@ -715,14 +721,10 @@ - - - - - - - - + + + + @@ -733,14 +735,10 @@ - - - - - - - - + + + + @@ -751,14 +749,10 @@ - - - - - - - - + + + + @@ -769,14 +763,10 @@ - - - - - - - - + + + + @@ -787,14 +777,10 @@ - - - - - - - - + + + + @@ -805,14 +791,10 @@ - - - - - - - - + + + + @@ -839,40 +821,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -881,16 +829,6 @@ - - - - - - - - - - @@ -908,26 +846,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -961,10 +879,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -973,57 +964,62 @@ - - + + - - - - - - - - - - - - - + + - - - - + + + + - + - - + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 0201bde..b58ed76 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,43 @@ This is intended for use with euglena projector + microscope systems as develope Written in Java and using the Processing 3 library Jan Peykiewicz (anewusername at gmail) wrote this version in mid-2016, but doesn't *really* work on this project... + +I (Jan) haven't tested the below commands on windows, but they should be direct translations of the linux commands. + +## Compiling + +You'll need a recent JDK (eg. 1.8). + +On linux, +``` +cd src/ +javac -cp .:../lib/*:../lib/video/library/*:../lib/serial/library/*:../lib/opencv_processing/library/* EuglenaApplet.java +``` + +On windows, +``` +cd src\ +javac -cp .;..\lib\*;..\lib\video\library\*;..\lib\serial\library\*;..\lib\opencv_processing\library\* EuglenaApplet.java +``` + +## Running + +On linux, +``` +cd src/ +java -cp .:../lib/*:../lib/video/library/*:../lib/serial/library/*:../lib/opencv_processing/library/* EuglenaApplet +``` + +On windows, +``` +cd src\ +java -cp .;..\lib\*;..\lib\video\library\*;..\lib\serial\library\*;..\lib\opencv_processing\library\* EuglenaApplet +``` + +## Cleanup + +On linux, +```rm src/*.class``` + +On windows, +```del src\*.class``` diff --git a/src/Camera.java b/src/Camera.java index e955524..b656295 100644 --- a/src/Camera.java +++ b/src/Camera.java @@ -3,14 +3,28 @@ import processing.video.*; import static processing.core.PApplet.*; class Camera { + /* + Camera controller. + This class is mostly a wrapper around processing.video.Capture. + */ + + // Camera from which we want to update Capture cam; + + // The latest image we got from the camera PImage latestImage; - /* - Set up a camera. - */ Camera(PApplet applet, int cameraMode) { + /* + Initialize a camera. + + If you don't know what to set cameraMode to, just set it to 0 + and then look at the output; this function prints out a list + of [cameraMode "1920x1080 60fps"] lines which you can use + to choose the mode you want. + */ String[] cameras = Capture.list(); + if (cameras.length == 0) { println("There are no cameras available for capture."); applet.exit(); diff --git a/src/EuglenaApplet.java b/src/EuglenaApplet.java index b953d1c..99333f0 100644 --- a/src/EuglenaApplet.java +++ b/src/EuglenaApplet.java @@ -2,6 +2,10 @@ import controlP5.ControlEvent; import processing.core.*; public class EuglenaApplet extends PApplet { + /* + This is the main Processing applet. + */ + final int cameraMode = 9; final int whichArduino = 0; @@ -32,12 +36,17 @@ public class EuglenaApplet extends PApplet { @Override public void setup() { + /* + Applet initialization + */ clear(); smooth(); + // Initialize hardware camera = new Camera(this, cameraMode); ledControl = new LEDControl(this, whichArduino); + // Initialize software components menu = new Menu(this); // Start up projectorApplet window @@ -49,13 +58,17 @@ public class EuglenaApplet extends PApplet { @Override public void draw() { + /* + Draw loop + */ + + //Draw the menu menu.draw(this, ledControl); //Update webcam and draw the updated image to the screen camera.updateImage(); imageMode(PApplet.CORNER); image(camera.getImage(), 0, 0, width - menu.width, height); - } @@ -77,6 +90,9 @@ public class EuglenaApplet extends PApplet { @Override public void keyPressed() { + /* + Key-down handler + */ ledControl.keyPressed(key); if (key == CODED) { projectorApplet.calibrator.buttonPressed(keyCode); @@ -96,14 +112,23 @@ public class EuglenaApplet extends PApplet { @Override public void keyReleased() { + /* + Key-up handler + */ ledControl.keyReleased(key); } public void controlEvent(ControlEvent theEvent) { + /* + Pass menu events to the menu component + */ menu.controlEvent(theEvent); } void drawArrow(int cx, int cy, int len, float angle){ + /* + Utility function for drawing an arrow + */ pushMatrix(); translate(cx, cy); rotate(radians(angle)); @@ -114,6 +139,9 @@ public class EuglenaApplet extends PApplet { } void reset() { + /* + Reset the applet to a known state + */ if (projectorApplet.calibrator.active) { projectorApplet.calibrator.deactivate(); } else { diff --git a/src/LEDControl.java b/src/LEDControl.java index ab5f394..2999eb3 100644 --- a/src/LEDControl.java +++ b/src/LEDControl.java @@ -22,6 +22,10 @@ class LEDControl { print("Using arduino "); println(arduinos[whichArduino]); + /* + ARDUINO IS DISABLED + (since I don't always have one to test with...) + */ // this.arduino = new Arduino(applet, arduinos[whichArduino], comRate); // // for (Direction dir : Direction.values()) { diff --git a/src/Line.java b/src/Line.java index 106d0f2..ba8496a 100644 --- a/src/Line.java +++ b/src/Line.java @@ -45,7 +45,7 @@ class Line { p.noFill(); p.line(p.convertXCoord(x1), p.convertYCoord(y1), - p.convertXCoord(x2), p.convertYCoord(y2)); + p.convertXCoord(x2), p.convertYCoord(y2)); p.strokeWeight(old_strokeWeight); p.stroke(old_strokeColor); diff --git a/src/ProjectorApplet.java b/src/ProjectorApplet.java index da7e140..7781d72 100644 --- a/src/ProjectorApplet.java +++ b/src/ProjectorApplet.java @@ -2,16 +2,32 @@ import processing.core.PApplet; import java.util.ArrayList; class ProjectorApplet extends PApplet { + /* + Secondary applet for controlling what gets displayed on + the projector. + + This window runs as a separate thread, so in order to draw + things, you should create a ProjectorCommand and queue it + up with projectorApplet.commandQueue.add(myCommand). + */ + + // Which screen should we display on? final int projectorScreenNumber = 2; + // Center coordinates of the screen final static int centerX = 860; final static int centerY = 540; + // Background color int bgColor = color(0, 0, 0); + // Pointer to the main applet EuglenaApplet parent; + + // Calibration component Calibrator calibrator; + // Queue of commands to execute ArrayList commandQueue; ProjectorApplet(EuglenaApplet parent) { @@ -27,11 +43,21 @@ class ProjectorApplet extends PApplet { @Override public void setup() { clear(); -// smooth(); // Smooth might create artefacts when animating? +// smooth(); // Smooth might create artifacts when animating? } @Override public void draw() { + /* + Main draw loop for the projector window + */ + + /* + Exectue commands from the commandQueue. + If a command finished, mark it for removal. + If we get a ProjectorCommandException, don't execute + any further commands. + */ ArrayList entriesToRemove = new ArrayList<>(); try { for (int i = 0; i < commandQueue.size(); i++) { @@ -46,21 +72,27 @@ class ProjectorApplet extends PApplet { // Do nothing } - // Remove entries (have to do it in reverse order to preserve indices) + // Remove finished commands (have to do it in reverse order to preserve indices) for (int i = entriesToRemove.size() - 1; i >= 0; i--) { commandQueue.remove(i); } - + // Let the calibration module draw anything it needs calibrator.draw(parent); } public void reset() { + /* + Clear the commandQueue and the screen + */ commandQueue.clear(); this.clear(); } public void clear() { + /* + Clear the screen + */ fill(bgColor); noStroke(); rectMode(CORNER); @@ -79,6 +111,11 @@ class ProjectorApplet extends PApplet { return bgColor; } + /* + Functions for converting coordinates and distances from + main-window to projector-window coordinates + */ + public float convertXCoord(float x) { return (x / calibrator.magx + width * calibrator.offsetx); } diff --git a/src/Settings.java b/src/Settings.java index 54798ce..56b86e9 100644 --- a/src/Settings.java +++ b/src/Settings.java @@ -1,5 +1,5 @@ -/** - * +/* + * Currently unused? */ public class Settings {