diff --git a/ino/mcopy_JKMM100/McopySerial.cpp b/ino/mcopy_JKMM100/McopySerial.cpp new file mode 100644 index 0000000..c849017 --- /dev/null +++ b/ino/mcopy_JKMM100/McopySerial.cpp @@ -0,0 +1,65 @@ +/// mcopy Serial Library + +#include "McopySerial.h" + +McopySerial::McopySerial (char identity) { + id = identity; +} + +void McopySerial::begin () { + Serial.begin(baud); + Serial.flush(); + Serial.setTimeout(serialDelay); +} + +char McopySerial::loop () { + if (Serial.available()) { + cmdChar = (char) Serial.read(); + _internal(); + } else { + cmdChar = 'z'; + } + return cmdChar; +} + +void McopySerial::_internal () { + if (cmdChar == DEBUG) { + debugOn = !debugOn; + } else if (cmdChar == CONNECT) { + _connect(); + } else if (cmdChar == MCOPY_IDENTIFIER) { + _identify(); + } +} + +void McopySerial::_connect () { + Serial.println(CONNECT); + log("connect()"); +} + +void McopySerial::_identify () { + Serial.println(id); + log("identify()"); +} + +void McopySerial::setBaud (int baudRate) { + baud = baudRate; +} + +void McopySerial::setIdentity (char identity) { + id = identity; +} + +void McopySerial::debug (bool state) { + debugOn = state; +} + +void McopySerial::confirm (char cmd) { + Serial.println(cmd); +} + +void McopySerial::log (String message) { + if (debugOn) { + Serial.println(message); + } +} \ No newline at end of file diff --git a/ino/mcopy_JKMM100/McopySerial.h b/ino/mcopy_JKMM100/McopySerial.h new file mode 100644 index 0000000..4e89a0a --- /dev/null +++ b/ino/mcopy_JKMM100/McopySerial.h @@ -0,0 +1,79 @@ +#ifndef MCOPY_SERIAL +#define MCOPY_SERIAL + +#include "Arduino.h" + +class McopySerial { + + private: + const int serialDelay = 5; + + volatile int baud = 57600; + volatile bool debugOn = false; + volatile char cmdChar = 'z'; + volatile char id; + + void _internal (); + void _connect (); + void _identify (); + + public: + + /* CMD FLAGS */ + static const char BLACK = 'b'; + static const char CAMERA = 'c'; + static const char CAMERA_BACKWARD = 'f'; + static const char CAMERA_CAPPER_IDENTIFIER = '8'; + static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + static const char CAMERA_FORWARD = 'e'; + static const char CAMERA_IDENTIFIER = 'k'; + static const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + static const char CAMERA_SECOND = '3'; + static const char CAMERA_SECOND_BACKWARD = '2'; + static const char CAMERA_SECOND_FORWARD = '1'; + static const char CAMERA_SECOND_IDENTIFIER = 'y'; + static const char CAMERA_TIMED = 'n'; + static const char CAMERAS = '4'; + static const char CAMERAS_IDENTIFIER = 'a'; + static const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + static const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + static const char CAPPER_IDENTIFIER = 'C'; + static const char CAPPER_OFF = 'B'; + static const char CAPPER_ON = 'A'; + static const char CONNECT = 'i'; + static const char DEBUG = 'd'; + static const char LIGHT = 'l'; + static const char LIGHT_IDENTIFIER = 'o'; + static const char MCOPY_IDENTIFIER = 'm'; + static const char PROJECTOR = 'p'; + static const char PROJECTOR_BACKWARD = 'h'; + static const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + static const char PROJECTOR_FORWARD = 'g'; + static const char PROJECTOR_IDENTIFIER = 'j'; + static const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + static const char PROJECTOR_SECOND = 'w'; + static const char PROJECTOR_SECOND_BACKWARD = 'v'; + static const char PROJECTOR_SECOND_FORWARD = 'u'; + static const char PROJECTOR_SECOND_IDENTIFIER = 't'; + static const char PROJECTORS = 'x'; + static const char PROJECTORS_IDENTIFIER = 'd'; + static const char TAKEUP_BACKWARD = 'E'; + static const char TAKEUP_FORWARD = 'D'; + /* END CMD FLAGS */ + + McopySerial(char identity); + + void begin(); + void setBaud(int baudRate); + void setIdentity(char identity); + char loop(); + void confirm(char cmd); + + void debug (bool state); + void log (String message); + +}; + +#endif diff --git a/ino/mcopy_JKMM100/mcopy_JKMM100.ino b/ino/mcopy_JKMM100/mcopy_JKMM100.ino new file mode 100644 index 0000000..05e1544 --- /dev/null +++ b/ino/mcopy_JKMM100/mcopy_JKMM100.ino @@ -0,0 +1,183 @@ +/* + * Sketch containing firmware for the JKMM100 + * A collaboration between MONO NO AWARE and mcopy. + * Compatible with JK105 hardware. + * + * Uses an Arduino Uno compatible board and a + * custom PCB. + * Rrelay module for proj : + + Wiring + + CAMERA + CAMERA_DIR + Wire directly to corresponding relay pins. + Arduino 2 3 5V GND + Relay 1 2 VCC GND + + Relays wired to JK Camera Controller 103/104 models + + PINS FOR CAM WIRE + + (# = Connector #) + Arduino # Wire In case Relay + ========================================= + PIN3 1 - Yellow = Grey = IN2 + 5V 2 - Red = Purple = VCC + PIN2 3 - Green = White = IN1 + GND 4 - Black = Black = GND + + PROJECTOR + PROJECTOR_DIR + + Wire to corresponding pins + Arduino 9 10 5V GND + Relay 1 2 VCC GND + + For controling JK Projectors 106 models + Solid state relays connect to: + 2uf run capacitory + 400 Ohm Resistor (50W) + + + PINS FOR PROJ WIRE + + # + 1 - + 2 - + 3 - + 4 - + + Relay 1 corresponds to FWD + Relay 2 corresponse to BWD + +*/ + +#include "McopySerial.h" + +volatile unsigned long now; + +//PROJECTOR CONSTANTS +const int PROJECTOR_MICROSWITCH = 8; + +const int PROJECTOR_FWD = 9; +const int PROJECTOR_BWD = 10; +const int PROJECTOR_ON = 11; + +const int PROJECTOR_MOMENT = 240; +const int PROJECTOR_FRAME = 600; +const int PROJECTOR_MICROSWITCH_CLOSED = 0; +const int PROJECTOR_MICROSWITCH_OPENED = 1; +const int PROJECTOR_HALF_TIME = 450; + +//PROJECTOR VARIABLES +boolean proj_dir = true; +boolean proj_running = false; +boolean proj_primed = false; +volatile int proj_micro_state = 0; +volatile long proj_time = 0; + +volatile char cmdChar = 'z'; + +McopySerial mc(McopySerial::PROJECTOR_IDENTIFIER); + +void setup () { + mc.begin(); + pins(); +} + +void loop () { + now = millis(); + + if (proj_running) { + proj_microswitch(); + } else { + cmdChar = mc.loop(); + cmd(cmdChar); + } +} + +void pins () { + pinMode(PROJECTOR_MICROSWITCH, INPUT_PULLUP); + pinMode(PROJECTOR_FWD, OUTPUT); + pinMode(PROJECTOR_BWD, OUTPUT); + pinMode(PROJECTOR_ON, OUTPUT); + + digitalWrite(PROJECTOR_FWD, LOW); + digitalWrite(PROJECTOR_BWD, LOW); + digitalWrite(PROJECTOR_ON, LOW); +} + +void cmd (char val) { + if (val == McopySerial::PROJECTOR_FORWARD) { + proj_direction(true); //explicit + } else if (val == McopySerial::PROJECTOR_BACKWARD) { + proj_direction(false); + } else if (val == McopySerial::PROJECTOR) { + proj_start(); + } +} + +void proj_start () { + proj_time = millis(); + + digitalWrite(PROJECTOR_ON, HIGH); + + if (proj_dir) { + digitalWrite(PROJECTOR_FWD, HIGH); + } else { + digitalWrite(PROJECTOR_BWD, HIGH); + } + + proj_running = true; +} + +void proj_stop () { + //stop both directions + delay(10); + digitalWrite(PROJECTOR_ON, LOW); + digitalWrite(PROJECTOR_FWD, LOW); + digitalWrite(PROJECTOR_BWD, LOW); + + //evaluate total time + + mc.confirm(McopySerial::PROJECTOR); + mc.log("projector()"); + proj_running = false; + + //Serial.println(millis() - proj_time); +} + +void proj_direction (boolean state) { + proj_dir = state; + if (state) { + mc.confirm(McopySerial::PROJECTOR_FORWARD); + mc.log("proj_direction -> true"); + } else { + mc.confirm(McopySerial::PROJECTOR_BACKWARD); + mc.log("proj_direction -> false"); + } +} + +//LOW=0=CLOSED +//HIGH=1=OPEN +void proj_microswitch () { + int val = digitalRead(PROJECTOR_MICROSWITCH); + if (!proj_primed // if not primed + && val != proj_micro_state // AND if state changes + && val == PROJECTOR_MICROSWITCH_OPENED // AND state changes to open + && now - proj_time > PROJECTOR_HALF_TIME) { + //prime + mc.log("proj_primed => true"); + proj_micro_state = val; + proj_primed = true; + } else if (proj_primed //if primed + && val != proj_micro_state //AND if state changes + && val == PROJECTOR_MICROSWITCH_CLOSED //AND state changes to open + && now - proj_time > PROJECTOR_HALF_TIME) { //AND total elapsed time is greater than half frame time + //stop + proj_primed = false; + proj_micro_state = val; //unneeded? + proj_stop(); + } else { + //delay(2); //some smothing value + } +} diff --git a/scripts/ino.sh b/scripts/ino.sh index 5e2567a..162e95b 100644 --- a/scripts/ino.sh +++ b/scripts/ino.sh @@ -16,4 +16,5 @@ if [ -f "$(which jq)" ]; then rm -f "${TMP_FILE}" fi -cp ino/lib/McopySerial/McopySerial.* ino/mcopy_cam_canon/ \ No newline at end of file +cp ino/lib/McopySerial/McopySerial.* ino/mcopy_cam_canon/ +cp ino/lib/McopySerial/McopySerial.* ino/mcopy_JKMM100/ \ No newline at end of file