<commit_before>/* Camera module
 *
 * https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/raspicam/RaspiCamDocs.odt
 *
 * these experiments will start to break request/response
 * patterns and help us to start to support streaming too
 * */

var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');

var PiCamera = require(__dirname+'/models/pi_camera.js');

var camera = new PiCamera();

module.exports = function(device) {
  return {
    'arm': {
      fn: camera.arm.bind(camera)
    },
    'disarm': {
      fn: camera.disarm.bind(camera)
    },
    'get still (320x240)': {
      fn: function(cb) {
        camera.getStill(function(err, stream) {
          var buf = "";
          var base64 = spawn('base64');
          stream.pipe(base64.stdin);
          base64.stdout.on('data', function(data) {
            buf += data.toString();
          });
          base64.on('close', function() {
            cb(null, {
              contentType: 'image/jpg (base64)',
              content: buf
            });
          });
        });
      }
    },
    'get rgb triplets (64x48)': {
      fn: function(cb) {
        exec('/opt/vc/bin/raspiyuv -w 64 -h 48 -o /tmp/still.rgb', function(err, stdout, stderr){
          if (err !== null) {
            cb({
              stderr: stderr,
              message: err.message,
              stack: err.stack
            }, null);
          } else {
            exec('node /opt/netpocketos/opt/device/features/camera/rgbMatrix.js /tmp/still.rgb 64 48', function(err2, stdout2, stderr2){<commit_msg>error handling for capture action<commit_after>/* Camera module
 *
 * https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/raspicam/RaspiCamDocs.odt
 *
 * these experiments will start to break request/response
 * patterns and help us to start to support streaming too
 * */

var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');

var PiCamera = require(__dirname+'/models/pi_camera.js');

var camera = new PiCamera();

module.exports = function(device) {
  return {
    'arm': {
      fn: camera.arm.bind(camera)
    },
    'disarm': {
      fn: camera.disarm.bind(camera)
    },
    'get still (320x240)': {
      fn: function(cb) {
        camera.getStill(function(err, stream) {
          if (err !== null) {
            cb(err);
          } else {
            var buf = "";
            var base64 = spawn('base64');
            stream.pipe(base64.stdin);
            base64.stdout.on('data', function(data) {
              buf += data.toString();
            });
            base64.on('close', function() {
              cb(null, {
                contentType: 'image/jpg (base64)',
                content: buf
              });
            });
          }
        });
      }
    },
    'get rgb triplets (64x48)': {
      fn: function(cb) {
        exec('/opt/vc/bin/raspiyuv -w 64 -h 48 -o /tmp/still.rgb', function(err, stdout, stderr){
          if (err !== null) {
            cb({
              stderr: stderr,
              message: err.message,
              stack: err.stack
            }, null);
          } else {
            exec('node /opt/netpocketos/opt/device/features/camera/rgbMatrix.js /tmp/still.rgb 64 48', function(err2, stdout2, stderr2){
{'fraction_non_alphanumeric': 0.1457345971563981, 'fraction_numerical': 0.019549763033175356, 'mean_word_length': 1.9545056867891513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1673891', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1027, 'n_words': 222}