@ -1,10 +1,12 @@
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_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 ;
@ -13,22 +15,29 @@ var BOB_module = {};
BOB_upCameraReference ( function ( ) { } ) ;
function BOB_takePicture ( pCallback ) {
BOB_mod_exec ( "gphoto2 --capture-image-and-download --filename=/tmp/bobine.jpg --force-overwrite" , function ( pErr , pStdout , pStderr ) {
console . log ( "takjePixuter" , 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 {
//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 ) {
@ -41,21 +50,82 @@ BOB_module.takePicture = function(pBoothId, pPictId, pCallback) {
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 ( "/tmp/bobine.jpg" , 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')
@ -78,4 +148,4 @@ BOB_module.takePicture = function(pBoothId, pPictId, pCallback) {
module . exports = function ( pConfig ) {
BOB_cfg_config = pConfig ;
return BOB_module ;
}
}