Created the basics of the mitchell and oxberry firmwares. Mitchell still needs button logic but oxberry will be controlled entirely digitally.

This commit is contained in:
Matt McWilliams 2024-07-07 22:17:48 -04:00
parent 29cd83eecf
commit f594472fd2
16 changed files with 215 additions and 41 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.8.122",
"version": "1.8.123",
"ext_port": 1111,
"profiles": {
"mcopy": {

2
app/package-lock.json generated
View File

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

View File

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

View File

@ -1,5 +1,5 @@
{
"version": "1.8.122",
"version": "1.8.123",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -129,7 +129,7 @@ uint32_t EndstopCameraShield::toOpen() {
return i;
}
uint32_t EndstopCameraShield::toClosed() {
uint32_t EndstopCameraShield::toClose() {
bool primed = false;
bool running = true;
uint32_t i = 0;

View File

@ -59,7 +59,7 @@ class EndstopCameraShield {
void loop();
uint32_t frame();
uint32_t toOpen();
uint32_t toClosed();
uint32_t toClose();
void setDirection(bool direction);
bool isOpened();
bool isClosed();

View File

@ -129,7 +129,7 @@ uint32_t EndstopCameraShield::toOpen() {
return i;
}
uint32_t EndstopCameraShield::toClosed() {
uint32_t EndstopCameraShield::toClose() {
bool primed = false;
bool running = true;
uint32_t i = 0;

View File

@ -59,7 +59,7 @@ class EndstopCameraShield {
void loop();
uint32_t frame();
uint32_t toOpen();
uint32_t toClosed();
uint32_t toClose();
void setDirection(bool direction);
bool isOpened();
bool isClosed();

View File

@ -0,0 +1,159 @@
#include "EndstopCameraShield.h"
#include "McopySerial.h"
const bool DEBUG = false;
//const uint8_t enableButtonPin = 9; //enable feature
const uint8_t directionSwitchPin = 10;
const uint8_t cameraButtonPin = 11;
const uint8_t openCloseSwitchPin = 12;
const uint8_t LEDPin = 13;
const uint32_t usPulse = 300;
const uint8_t microsteps = 2;
volatile char cmdChar = 'z';
volatile long now;
volatile long exposureAvg = -1; //pre-fill
volatile String exposureString;
volatile long exposureTarget = -1;
volatile bool direction = true;
volatile bool directionSwitch = true;
EndstopCameraShield cam(usPulse, microsteps);
McopySerial mc;
void setup () {
pinMode(directionSwitchPin, INPUT_PULLUP);
pinMode(openCloseSwitchPin, INPUT_PULLUP);
pinMode(cameraButtonPin, INPUT_PULLUP);
mc.begin(mc.CAMERA_IDENTIFIER);
mc.debug(DEBUG);
cam.setup();
if (cam.isOpened()) {
mc.log("Camera is OPENED");
} else if (cam.isClosed()) {
mc.log("Camera is CLOSED");
} else {
mc.log("Camera is in UNKNOWN state");
}
}
void loop () {
now = millis();
cmdChar = mc.loop();
cmd(cmdChar);
cam.loop();
}
void cmd (char val) {
if (val == mc.CAMERA_FORWARD) {
camera_direction(true);
} else if (val == mc.CAMERA_BACKWARD) {
camera_direction(false);
} else if (val == mc.CAMERA) {
camera();
} else if (val == mc.CAMERA_OPEN) {
camera_open();
} else if (val == mc.CAMERA_CLOSE) {
camera_close();
} else if (val == mc.CAMERA_EXPOSURE) {
exposure();
} else if (val == mc.STATE) {
state();
}
}
void exposure () {
exposureString = mc.getString();
parseExposureString();
exposureAvg = exposureTarget;
mc.confirm(mc.CAMERA_EXPOSURE);
}
void parseExposureString () {
exposureTarget = exposureString.toInt();
}
void camera_direction (boolean state) {
direction = state;
cam.setDirection(direction);
if (state) {
mc.confirm(mc.CAMERA_FORWARD);
mc.log("camera_direction(true)");
} else {
mc.confirm(mc.CAMERA_BACKWARD);
mc.log("camera_direction(false)");
}
}
void camera () {
long start = millis();
long half;
long pause;
long ms;
if (exposureTarget > -1) {
half = exposureAvg / 2; //assume a 180 shutter
pause = exposureTarget - half;
if (pause < exposureAvg) {
cam.frame();
} else {
cam.toOpen();
delay(pause);
cam.toClose();
}
} else{
cam.frame();
}
ms = millis() - start;
if (exposureTarget < 0) {
updateAvg(ms);
}
mc.log("camera()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA);
}
void camera_open () {
long start = millis();
long ms;
cam.toOpen();
ms = millis() - start;
mc.log("camera_open()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA_OPEN);
}
void camera_close () {
long start = millis();
long ms;
cam.toClose();
ms = millis() - start;
mc.log("camera_close()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA_CLOSE);
}
void state () {
String stateString = String(mc.STATE);
stateString += String(mc.CAMERA_EXPOSURE);
if (exposureTarget > -1) {
stateString += String(exposureTarget);
} else {
stateString += String(exposureAvg);
}
stateString += String(mc.STATE);
mc.sendString(stateString);
}
void updateAvg (long value) {
exposureAvg = round((exposureAvg + value) / 2);
}
/**
* Button logic
**/

View File

@ -1,10 +0,0 @@
#include "EndstopCameraShield.h"
#include "McopySerial.h"
void setup () {
}
void loop () {
}

View File

@ -129,7 +129,7 @@ uint32_t EndstopCameraShield::toOpen() {
return i;
}
uint32_t EndstopCameraShield::toClosed() {
uint32_t EndstopCameraShield::toClose() {
bool primed = false;
bool running = true;
uint32_t i = 0;

View File

@ -59,7 +59,7 @@ class EndstopCameraShield {
void loop();
uint32_t frame();
uint32_t toOpen();
uint32_t toClosed();
uint32_t toClose();
void setDirection(bool direction);
bool isOpened();
bool isClosed();

View File

@ -2,11 +2,6 @@
#include "McopySerial.h"
const bool DEBUG = false;
const uint8_t enableButtonPin = 9;
const uint8_t enableButtonPin = 10;
const uint8_t enableButtonPin = 11;
const uint8_t enableButtonPin = 12;
const uint8_t LEDPin = 13;
const uint32_t usPulse = 300;
@ -19,7 +14,6 @@ volatile String exposureString;
volatile long exposureTarget = -1;
volatile bool direction = true;
volatile bool directionSwitch = true;
EndstopCameraShield cam(usPulse, microsteps);
McopySerial mc;
@ -29,9 +23,13 @@ void setup () {
mc.debug(DEBUG);
cam.setup();
if (cam.isOpened()) {
mc.log("Camera is OPENED");
mc.log("Camera is OPENED, closing...");
cam.toClose();
} else if (cam.isClosed()) {
mc.log("Camera is CLOSED");
} else {
mc.log("Camera is in UNKNOWN state, closing...");
cam.toClose();
}
}
@ -49,6 +47,10 @@ void cmd (char val) {
camera_direction(false);
} else if (val == mc.CAMERA) {
camera();
} else if (val == mc.CAMERA_OPEN) {
camera_open();
} else if (val == mc.CAMERA_CLOSE) {
camera_close();
} else if (val == mc.CAMERA_EXPOSURE) {
exposure();
} else if (val == mc.STATE) {
@ -59,7 +61,7 @@ void cmd (char val) {
void exposure () {
exposureString = mc.getString();
parseExposureString();
cameraFrame = exposureTarget;
exposureAvg = exposureTarget;
mc.confirm(mc.CAMERA_EXPOSURE);
}
@ -80,7 +82,11 @@ void camera_direction (boolean state) {
}
void camera () {
long start, half, pause;
long start = millis();
long half;
long pause;
long ms;
if (exposureTarget > -1) {
half = exposureAvg / 2; //assume a 180 shutter
pause = exposureTarget - half;
@ -91,15 +97,38 @@ void camera () {
delay(pause);
cam.toClose();
}
} else{
millis();
cam.frame();
updateAvg(millis() - start);
}
ms = millis() - start;
if (exposureTarget < 0) {
updateAvg(ms);
}
mc.log("camera()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA);
}
void camera_open () {
long start = millis();
long ms;
cam.toOpen();
ms = millis() - start;
mc.log("camera_open()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA_OPEN);
}
void camera_close () {
long start = millis();
long ms;
cam.toClose();
ms = millis() - start;
mc.log("camera_close()");
mc.log(String(ms) + "ms");
mc.confirm(mc.CAMERA_CLOSE);
}
void state () {
String stateString = String(mc.STATE);
stateString += String(mc.CAMERA_EXPOSURE);
@ -114,8 +143,4 @@ void state () {
void updateAvg (long value) {
exposureAvg = round((exposureAvg + value) / 2);
}
/**
* Button logic
**/
}

4
package-lock.json generated
View File

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

View File

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

View File

@ -1,5 +1,5 @@
{
"version": "1.8.122",
"version": "1.8.123",
"ext_port": 1111,
"profiles": {
"mcopy": {