Update mcopy_JKMM100_work to have McopySerial library

This commit is contained in:
Matt McWilliams 2023-11-25 20:05:52 -05:00
parent b14d24e650
commit 128a4d2ded
11 changed files with 175 additions and 10 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.74", "version": "1.8.75",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.74", "version": "1.8.75",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.74", "version": "1.8.75",
"description": "GUI for the mcopy small gauge film optical printer platform", "description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.74", "version": "1.8.75",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -0,0 +1,74 @@
/// mcopy Serial Library
#include "McopySerial.h"
McopySerial::McopySerial () {}
void McopySerial::begin (char identity) {
id = identity;
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) {
debug(!debugOn);
} else if (cmdChar == CONNECT) {
_connect();
} else if (cmdChar == MCOPY_IDENTIFIER) {
_identify();
}
}
void McopySerial::_connect () {
connected = true;
Serial.println(CONNECT);
log("connect()");
}
void McopySerial::_identify () {
identified = true;
Serial.println(id);
log("identify()");
}
void McopySerial::debug (bool state) {
debugOn = state;
log("debug()");
}
void McopySerial::confirm (char cmd) {
Serial.println(cmd);
}
void McopySerial::log (String message) {
if (debugOn) {
Serial.println(message);
}
}
String McopySerial::getString () {
while (Serial.available() == 0) {
//Wait for value string
}
return Serial.readString();
}
void McopySerial::sendString (String str) {
Serial.println(str);
}
void McopySerial::print (String message) {
Serial.println(message);
}

View File

@ -0,0 +1,89 @@
#ifndef MCOPY_SERIAL
#define MCOPY_SERIAL
#include <Arduino.h>
class McopySerial {
private:
const uint16_t serialDelay = 5;
const uint16_t baud = 57600;
volatile bool debugOn = false;
volatile char cmdChar = 'z';
volatile char id;
void _internal ();
void _connect ();
void _identify ();
public:
volatile bool connected = false;
volatile bool identified = false;
/* CMD FLAGS */
const char BLACK = 'b';
const char CAMERA = 'c';
const char CAMERA_BACKWARD = 'f';
const char CAMERA_CAPPER_IDENTIFIER = '8';
const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
const char CAMERA_EXPOSURE = 'G';
const char CAMERA_FORWARD = 'e';
const char CAMERA_IDENTIFIER = 'k';
const char CAMERA_PROJECTORS_IDENTIFIER = '5';
const char CAMERA_SECOND = '3';
const char CAMERA_SECOND_BACKWARD = '2';
const char CAMERA_SECOND_FORWARD = '1';
const char CAMERA_SECOND_IDENTIFIER = 'y';
const char CAMERA_TIMED = 'n';
const char CAMERAS = '4';
const char CAMERAS_IDENTIFIER = 'a';
const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
const char CAPPER_IDENTIFIER = 'C';
const char CAPPER_OFF = 'B';
const char CAPPER_ON = 'A';
const char CONNECT = 'i';
const char DEBUG = 'd';
const char ERROR = 'E';
const char HOME = 'I';
const char LIGHT = 'l';
const char LIGHT_IDENTIFIER = 'o';
const char MCOPY_IDENTIFIER = 'm';
const char OFFSET = 'O';
const char PROJECTOR = 'p';
const char PROJECTOR_BACKWARD = 'h';
const char PROJECTOR_CAMERA_IDENTIFIER = 's';
const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
const char PROJECTOR_FORWARD = 'g';
const char PROJECTOR_IDENTIFIER = 'j';
const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
const char PROJECTOR_SECOND = 'w';
const char PROJECTOR_SECOND_BACKWARD = 'v';
const char PROJECTOR_SECOND_FORWARD = 'u';
const char PROJECTOR_SECOND_IDENTIFIER = 't';
const char PROJECTORS = 'x';
const char PROJECTORS_IDENTIFIER = 'd';
const char STATE = 'H';
const char TAKEUP_BACKWARD = 'F';
const char TAKEUP_FORWARD = 'D';
/* END CMD FLAGS */
McopySerial();
void begin(char identity);
char loop();
void confirm(char cmd);
String getString();
void print(String message);
void sendString(String str);
void debug (bool state);
void log (String message);
};
#endif

View File

@ -51,6 +51,7 @@ const int PROJECTOR_FRAME = 600;
const int PROJECTOR_MICROSWITCH_CLOSED = 0; const int PROJECTOR_MICROSWITCH_CLOSED = 0;
const int PROJECTOR_MICROSWITCH_OPENED = 1; const int PROJECTOR_MICROSWITCH_OPENED = 1;
const int PROJECTOR_HALF_TIME = 450; const int PROJECTOR_HALF_TIME = 450;
const int PROJECTOR_STOP_DELAY = 15;
//PROJECTOR VARIABLES //PROJECTOR VARIABLES
boolean proj_dir = true; boolean proj_dir = true;
@ -135,11 +136,11 @@ void proj_stop () {
if (digitalRead(PROJECTOR_MICROSWITCH) == PROJECTOR_MICROSWITCH_CLOSED) { if (digitalRead(PROJECTOR_MICROSWITCH) == PROJECTOR_MICROSWITCH_CLOSED) {
if (proj_dir) { if (proj_dir) {
digitalWrite(PROJECTOR_BWD, HIGH); digitalWrite(PROJECTOR_BWD, HIGH);
delay(15); delay(PROJECTOR_STOP_DELAY);
digitalWrite(PROJECTOR_BWD, LOW); digitalWrite(PROJECTOR_BWD, LOW);
} else { } else {
digitalWrite(PROJECTOR_FWD, HIGH); digitalWrite(PROJECTOR_FWD, HIGH);
delay(15); delay(PROJECTOR_STOP_DELAY);
digitalWrite(PROJECTOR_FWD, LOW); digitalWrite(PROJECTOR_FWD, LOW);
} }
} }

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.74", "version": "1.8.75",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.8.74", "version": "1.8.75",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"arduino": "file:app/lib/arduino", "arduino": "file:app/lib/arduino",

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.74", "version": "1.8.75",
"description": "Small gauge film optical printer platform", "description": "Small gauge film optical printer platform",
"main": "build.js", "main": "build.js",
"directories": { "directories": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.74", "version": "1.8.75",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -21,6 +21,7 @@ SKETCHES=(
mcopy_cam_canon_ble_nano mcopy_cam_canon_ble_nano
mcopy_cam_relay mcopy_cam_relay
mcopy_JKMM100 mcopy_JKMM100
mcopy_JKMM100_work
components/mcopy_light components/mcopy_light
mcopy_projector_firmware mcopy_projector_firmware
) )