You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
4.3 KiB
154 lines
4.3 KiB
var BOB_mod_gm = require('gm').subClass({ imageMagick: true });
|
|
// var BOB_mod_gphoto2 = require('gphoto2');
|
|
// var BOB_var_gphoto = new BOB_mod_gphoto2.GPhoto2();
|
|
var BOB_mod_fs = require('fs');
|
|
var BOB_mod_path = require('path');
|
|
var BOB_mod_mkdirp = require('mkdirp');
|
|
|
|
var BOB_mod_exec = require('child_process').exec;
|
|
|
|
var BOB_cfg_config = null;
|
|
|
|
var BOB_var_camera = null;
|
|
|
|
var BOB_module = {};
|
|
|
|
var BOB_tmpPict = "/home/odroid/bobine-tmp.jpg"
|
|
|
|
BOB_upCameraReference(function() {});
|
|
|
|
function BOB_takePicture(pCallback) {
|
|
BOB_mod_exec("gphoto2 --capture-image-and-download --filename="+BOB_tmpPict+" --force-overwrite", function(pErr, pStdout, pStderr) {
|
|
console.log("takePicture", pErr || pStdout || pStderr)
|
|
console.log(pErr, pStdout, pStderr)
|
|
return pCallback(pErr)
|
|
})
|
|
}
|
|
|
|
function BOB_upCameraReference(pCallback) {
|
|
// List cameras / assign list item to variable to use below options
|
|
//if( BOB_var_camera === null ) {
|
|
// BOB_var_gphoto.list(function (list) {
|
|
// if (list.length === 0) {
|
|
// return pCallback();
|
|
// } else {
|
|
// console.log(list)
|
|
// BOB_var_camera = list[0];
|
|
// console.log(BOB_var_camera.model);
|
|
// return pCallback();
|
|
// }
|
|
// })
|
|
//} else {
|
|
return pCallback();
|
|
//}
|
|
}
|
|
|
|
BOB_module.getConfig = function(pCallback) {
|
|
BOB_var_camera.getConfig(pCallback);
|
|
}
|
|
|
|
BOB_module.takePicture = function(pBoothId, pPictId, pCallback) {
|
|
var destPath = BOB_mod_path.join(BOB_cfg_config.paths.original, pBoothId);
|
|
var pbltPath = BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId);
|
|
var pictOrig = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]);
|
|
var pictPblt = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]);
|
|
|
|
BOB_mod_mkdirp.sync(BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId));
|
|
|
|
console.log("new")
|
|
|
|
BOB_takePicture(function (pErr) {
|
|
// If error occurs
|
|
if( pErr ) {
|
|
return pCallback(pErr)
|
|
// Else write file on ddisk
|
|
} else {
|
|
BOB_mod_mkdirp(destPath, function() {
|
|
copyFile(BOB_tmpPict, pictOrig, function(pErr) {
|
|
return pCallback(pErr, pictOrig)
|
|
});
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function copyFile(source, target, cb) {
|
|
var cbCalled = false;
|
|
|
|
var rd = BOB_mod_fs.createReadStream(source);
|
|
rd.on("error", function(err) {
|
|
done(err);
|
|
});
|
|
var wr = BOB_mod_fs.createWriteStream(target);
|
|
wr.on("error", function(err) {
|
|
done(err);
|
|
});
|
|
wr.on("close", function(ex) {
|
|
done();
|
|
});
|
|
rd.pipe(wr);
|
|
|
|
function done(err) {
|
|
if (!cbCalled) {
|
|
cb(err);
|
|
cbCalled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
BOB_module.takePictureNpm = function(pBoothId, pPictId, pCallback) {
|
|
var destPath = BOB_mod_path.join(BOB_cfg_config.paths.original, pBoothId);
|
|
var pbltPath = BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId);
|
|
var pictOrig = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]);
|
|
var pictPblt = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]);
|
|
|
|
console.log("1");
|
|
BOB_mod_mkdirp.sync(BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId));
|
|
console.log("2");
|
|
|
|
BOB_upCameraReference(function() {
|
|
console.log("3");
|
|
|
|
if( BOB_var_camera === null ) {
|
|
return pCallback("No camera found");
|
|
} else {
|
|
console.log("4");
|
|
|
|
BOB_var_camera.takePicture({download: true}, function (pErr, pData) {
|
|
// If error occurs
|
|
if( pErr ) {
|
|
return pCallback(pErr)
|
|
// Else write file on ddisk
|
|
} else {
|
|
console.log("5");
|
|
|
|
BOB_mod_mkdirp(destPath, function() {
|
|
console.log("6");
|
|
|
|
BOB_mod_fs.writeFile(pictOrig, pData, function(pErr) {
|
|
console.log("7");
|
|
|
|
// BOB_mod_gm(pictOrig)
|
|
// .autoOrient()
|
|
// .gravity('Center')
|
|
// // .resize(BOB_cfg_config.cropSize.width, BOB_cfg_config.cropSize.height, "^")
|
|
// // .crop(BOB_cfg_config.cropSize.width, BOB_cfg_config.cropSize.height)
|
|
// // .modulate(100, 0)
|
|
// // .contrast(+2)
|
|
// .write(pictOrig, function(pErr) {
|
|
// return pCallback(pErr, pictPblt)
|
|
// })
|
|
return pCallback(pErr, pictOrig)
|
|
});
|
|
})
|
|
}
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = function(pConfig) {
|
|
BOB_cfg_config = pConfig;
|
|
return BOB_module;
|
|
}
|