/*
 * 摄像头
 * */

var _comm = require('./comm');

/*
 * 拍照 sudo apt-get install fswebcam
 * */
exports.photograph = function(path,filename,callback) {
    try {
        if (!path) {
            path = "/";
        }
        if (!filename) {
            filename = _comm.dateFormat("yyyyMMddhhmmss") + ".jpg";
        }
        var file = path + filename;
        var cmd = "fswebcam --no-banner -r 640x480 " + file;
        _comm.runCommand(cmd, function (err, stdout, stderr) {
            if(!err){
                if(callback && typeof callback == 'function'){
                    callback(true);
                }
            }
            else{
                if(callback && typeof callback == 'function'){
                    callback(false);
                }
            }
        });
    }
    catch (e) {
        callback(false);
    }
}