Settings, intval and mcopyJK firmware work.

This commit is contained in:
mmcwilliams 2018-01-17 12:23:23 -05:00
parent 9993631353
commit 695a289bdb
5 changed files with 84 additions and 82 deletions

View File

@ -1,9 +1,12 @@
'use strict' 'use strict'
const os = require('os') const os = require('os')
const path = require('os')
const sqlite3 = require('sqlite3') const sqlite3 = require('sqlite3')
const squel = require('squel') const squel = require('squel')
const PATH = path.join(os.homedir(), '.mcopy/mcopy.db')
const actionTable = `CREATE TABLE IF NOT EXISTS actions ( const actionTable = `CREATE TABLE IF NOT EXISTS actions (
time INTEGER PRIMARY KEY, time INTEGER PRIMARY KEY,
type TEXT, type TEXT,
@ -14,6 +17,13 @@ const actionTable = `CREATE TABLE IF NOT EXISTS actions (
sequence INTEGER sequence INTEGER
);` );`
var checkDir = function () {
const dir = path.join(os.homedir(), '.mcopy/')
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}
class DB { class DB {
constructor () { constructor () {

View File

@ -11,7 +11,7 @@ class Intval {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const baseUrl = devices[device]
const url = `${baseUrl}/frame` const url = `${baseUrl}/frame`
console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
if (err) { if (err) {
@ -24,7 +24,7 @@ class Intval {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const baseUrl = devices[device]
const url = `${baseUrl}/dir?dir=${dir}` const url = `${baseUrl}/dir?dir=${dir}`
console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
if (err) { if (err) {
@ -38,7 +38,7 @@ class Intval {
const timeStart = +new Date() const timeStart = +new Date()
const baseUrl = devices[device] const baseUrl = devices[device]
const url = `${baseUrl}/exposure?exposure=${exposure}` const url = `${baseUrl}/exposure?exposure=${exposure}`
console.log(url) //console.log(url)
req(url, (err, res, body) => { req(url, (err, res, body) => {
let ms = (+new Date()) - timeStart let ms = (+new Date()) - timeStart
if (err) { if (err) {

View File

@ -38,6 +38,10 @@ settings.get = function (key) {
return settings.state[key] return settings.state[key]
} }
settings.all = function () {
return settings.state
}
settings.restore = function () { settings.restore = function () {
let str let str
settings.checkDir() settings.checkDir()

View File

@ -291,7 +291,6 @@ cam.state = {
} }
cam.init = function () { cam.init = function () {
cam.listen() cam.listen()
cam.intval = new Intval('camera', '192.168.1.224')
} }
cam.set = function (dir, id) { cam.set = function (dir, id) {
let cmd let cmd
@ -304,14 +303,27 @@ cam.set = function (dir, id) {
arduino.send('camera', cmd, (ms) => { arduino.send('camera', cmd, (ms) => {
cam.end(cmd, id, ms) cam.end(cmd, id, ms)
}) })
/*
intval.setDir('camera', dir, (ms) => {
cam.end(cmd, id, ms)
})
*/
} }
cam.move = function (frame, id) { cam.move = function (frame, id) {
let cmd = mcopy.cfg.arduino.cmd.camera let cmd = mcopy.cfg.arduino.cmd.camera
/*arduino.send('camera', cmd, (ms) => { arduino.send('camera', cmd, (ms) => {
cam.end(cmd, id, ms) cam.end(cmd, id, ms)
})*/ })
cam.intval.move('camera', (ms) => { /*
intval.move('camera', (ms) => {
cam.end(cmd, id, ms)
})
*/
}
cam.exposure = function (exposure, id) {
intval.setDir('camera', exposure, (ms) => {
cam.end(cmd, id, ms) cam.end(cmd, id, ms)
}) })
} }

View File

@ -1,10 +1,11 @@
/* /*
Wiring Wiring
For "MONITOR" pins with INPUT_PULLUP resistors: For "MONITOR" pins with INPUT_PULLUP resistors:
GND-----\ | \-----PIN GND-----\ | \-----PIN
No additional resistors/caps needed. No additional resistors/caps needed.
--Note: not needed in prototype
CAMERA + CAMERA_DIR and PROJECTOR + PROJECTOR_DIR: CAMERA + CAMERA_DIR and PROJECTOR + PROJECTOR_DIR:
Wire directly to corresponding relay pins. Wire directly to corresponding relay pins.
@ -14,27 +15,23 @@
boolean debug_state = false; boolean debug_state = false;
unsigned long now; //to be compared to stored values every loop //unsigned long now; //to be compared to stored values every loop
//CAMERA CONSTANTS
const int CAMERA = 2; const int CAMERA = 2;
const int CAMERA_DIR = 3; const int CAMERA_DIR = 3;
const int CAMERA_MONITOR = 4; const int CAMERA_MOMENT = 200;
const int CAMERA_FRAME = 800;
unsigned long cam_momentary_end; //CAMERA VARIABLES
const long cam_moment = 300;
boolean cam_dir = true; boolean cam_dir = true;
boolean cam_running = false;
boolean cam_momentary = false;
//PROJECTOR CONSTANTS
const int PROJECTOR = 8; const int PROJECTOR = 8;
const int PROJECTOR_DIR = 9; const int PROJECTOR_DIR = 9;
const int PROJECTOR_MONITOR = 10; const int PROJECTOR_MOMENT = 200;
const int PROJECTOR_FRAME = 800;
unsigned long proj_momentary_end; //PROJECTOR VARIABLES
const long proj_moment = 300;
boolean proj_dir = true; boolean proj_dir = true;
boolean proj_running = false;
boolean proj_momentary = false;
//PROJECTOR COMMANDS //PROJECTOR COMMANDS
const char cmd_projector = 'p'; const char cmd_projector = 'p';
@ -59,13 +56,13 @@ const int serialDelay = 5;
void setup () { void setup () {
Serial.begin(57600); Serial.begin(57600);
Serial.flush(); Serial.flush();
Serial.setTimeout(serialDelay); //Serial.setTimeout(serialDelay);
pins(); pins();
} }
void loop () { void loop () {
now = millis(); //now = millis();
if (Serial.available()) { if (Serial.available()) {
/* read the most recent byte */ /* read the most recent byte */
cmd_char = (char)Serial.read(); cmd_char = (char)Serial.read();
@ -75,13 +72,10 @@ void loop () {
cmd_char = 'z'; cmd_char = 'z';
} }
if (cam_running) { /*delay(2000);
monitorCam(); cam_start();
} delay(2000);
proj_start();*/
if (proj_running) {
monitorProj();
}
} }
void pins () { void pins () {
@ -92,10 +86,6 @@ void pins () {
pinMode(CAMERA_DIR, OUTPUT); pinMode(CAMERA_DIR, OUTPUT);
pinMode(PROJECTOR_DIR, OUTPUT); pinMode(PROJECTOR_DIR, OUTPUT);
//PULLUP
pinMode(CAMERA_MONITOR, INPUT_PULLUP);
pinMode(PROJECTOR_MONITOR, INPUT_PULLUP);
//SET LOW //SET LOW
digitalWrite(CAMERA, LOW); digitalWrite(CAMERA, LOW);
digitalWrite(CAMERA_DIR, LOW); digitalWrite(CAMERA_DIR, LOW);
@ -125,42 +115,6 @@ void cmd (char val) {
} }
} }
void monitorCam () {
int position = digitalRead(CAMERA_MONITOR);
if (cam_momentary && now >= cam_momentary_end) {
digitalWrite(CAMERA, LOW);
cam_momentary = false;
}
if (!cam_momentary) {
if (position == LOW) {
cam_stop();
}
}
}
void monitorProj () {
int position = digitalRead(PROJECTOR_MONITOR);
if (proj_momentary && now >= proj_momentary_end) {
digitalWrite(PROJECTOR, LOW);
proj_momentary = false;
}
if (!proj_momentary) {
//If internam microswitch is set to LOW?
if (position == LOW) {
proj_stop();
}
}
}
void setDir (int pin, boolean dir) {
if (dir) {
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
}
void debug () { void debug () {
debug_state = true; debug_state = true;
Serial.println(cmd_debug); Serial.println(cmd_debug);
@ -177,35 +131,56 @@ void identify () {
log("identify()"); log("identify()");
} }
void setDir (int pin, boolean dir) {
if (!dir) {
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
}
void proj_start () { void proj_start () {
if (proj_dir == false) {
setDir(PROJECTOR_DIR, false);
}
digitalWrite(PROJECTOR, HIGH); digitalWrite(PROJECTOR, HIGH);
proj_running = true; delay(PROJECTOR_MOMENT);
proj_momentary = true; digitalWrite(PROJECTOR, LOW);
proj_momentary_end = now + proj_moment; delay(PROJECTOR_FRAME);
if (proj_dir == false) {
setDir(PROJECTOR_DIR, true);
}
proj_stop();
} }
void cam_start () { void cam_start () {
if (cam_dir == false) {
setDir(CAMERA_DIR, false);
}
digitalWrite(CAMERA, HIGH); digitalWrite(CAMERA, HIGH);
cam_running = true; delay(CAMERA_MOMENT);
cam_momentary = true; digitalWrite(CAMERA, LOW);
cam_momentary_end = now + cam_moment; delay(CAMERA_FRAME);
if (cam_dir == false) {
setDir(CAMERA_DIR, true);
}
cam_stop();
} }
void proj_stop () { void proj_stop () {
proj_running = false;
Serial.println(cmd_projector); Serial.println(cmd_projector);
log("projector()"); log("projector()");
} }
void cam_stop () { void cam_stop () {
cam_running = false;
Serial.println(cmd_camera); Serial.println(cmd_camera);
log("camera()"); log("camera()");
} }
void proj_direction (boolean state) { void proj_direction (boolean state) {
proj_dir = state; proj_dir = state;
setDir(PROJECTOR_DIR, state); //UNO can only set 2 relays to high at a time
//setDir(PROJECTOR_DIR, state);
if (state) { if (state) {
Serial.println(cmd_proj_forward); Serial.println(cmd_proj_forward);
log("proj_direction -> true"); log("proj_direction -> true");
@ -217,7 +192,7 @@ void proj_direction (boolean state) {
void cam_direction (boolean state) { void cam_direction (boolean state) {
cam_dir = state; cam_dir = state;
setDir(CAMERA_DIR, state); //setDir(CAMERA_DIR, state);
if (state) { if (state) {
Serial.println(cmd_cam_forward); Serial.println(cmd_cam_forward);
log("cam_direction -> true"); log("cam_direction -> true");
@ -232,3 +207,4 @@ void log (String msg) {
Serial.println(msg); Serial.println(msg);
} }
} }