This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving around the node server.. and...
- New capture script - Hook script now publishes to Redis - Node server almost is publishing to socket.io clients when Redis messages are send (pubsub)
- Loading branch information
1 parent
1acddef
commit 8631048
Showing
30 changed files
with
260 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
var express = require('express'), | ||
fs = require('fs'), | ||
spawn = require('child_process').spawn, | ||
|
||
app = module.exports = express.createServer(), | ||
io = require('socket.io').listen(app), | ||
db = require('redis').createClient(), | ||
photobooth, | ||
cfg; | ||
|
||
// Configuration | ||
|
||
app.configure(function(){ | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'ejs'); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })); | ||
app.use(app.router); | ||
app.use(express.static(__dirname + '/public')); | ||
}); | ||
|
||
app.configure('development', function(){ | ||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | ||
}); | ||
|
||
app.configure('production', function(){ | ||
app.use(express.errorHandler()); | ||
}); | ||
|
||
// database | ||
|
||
db.on('connected', function () { | ||
db.connected = true; | ||
}); | ||
|
||
db.on("message", function (channel, message) { | ||
console.log("Message: "+channel+" - "+message); | ||
}); | ||
db.subscribe("booth:capture"); | ||
|
||
|
||
// Routes | ||
|
||
app.get('/', function(req, res){ | ||
res.render('index', { | ||
title: 'PhotoBooth' | ||
}); | ||
}); | ||
|
||
function takePhotos(cb) { | ||
photobooth = spawn('./capture.php', [], { | ||
cwd: __dirname | ||
}); | ||
|
||
photobooth.stderr.on('data', function (data) { | ||
console.log("stderr: " + data.toString()) | ||
}) | ||
|
||
photobooth.on('exit', function (data) { | ||
photobooth = false; | ||
cb(); | ||
}); | ||
|
||
photobooth.stdout.on('data', function (data) { | ||
console.log("stdout: " + data.toString()); | ||
}); | ||
|
||
photobooth.stdin.end(); | ||
} | ||
|
||
app.get('/snap', function (req, res) { | ||
db.exists('photolock', function (err, response) { | ||
if (!response) { | ||
db.multi() | ||
.set('photolock', 1) | ||
.expire('photolock', 60) // only lock the process for 60 seconds | ||
.exec(); | ||
|
||
takePhotos(function () { | ||
db.del('photolock'); | ||
}); | ||
|
||
res.json({ type: "success" }); | ||
} else { | ||
res.json({ type: "failure", msg: "Already running" }); | ||
} | ||
}); | ||
}); | ||
|
||
app.get('/config', function (req, res) { | ||
var cfg = JSON.parse(fs.readFileSync(__dirname+"/config.json")); | ||
|
||
findPrinters(function(printers) { | ||
res.render('config', { | ||
title: 'PhotoBooth Config', | ||
cfg: cfg, | ||
printers: printers | ||
}); | ||
}); | ||
}); | ||
|
||
app.post('/config', function (req, res) { | ||
fs.writeFile(__dirname+"/config.json", JSON.stringify(req.body)); | ||
|
||
res.json({ msg: "Saved" }); | ||
}); | ||
|
||
io.sockets.on('connection', function (socket) { | ||
socket.emit('news', { hello: 'world' }); | ||
socket.on('my other event', function (data) { | ||
console.log(data); | ||
}); | ||
}); | ||
|
||
function findPrinters(cb) { | ||
var printers = spawn(__dirname+"/printers.php"); | ||
printers.on('exit', function (data) { | ||
printers = false; | ||
}); | ||
printers.stdout.on('data', function (data) { | ||
cb(JSON.parse(data.toString())); | ||
}); | ||
printers.stdin.end(); | ||
}; | ||
|
||
app.listen(3000); | ||
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require __DIR__.'/autoload.php'; | ||
|
||
use Symfony\Component\Process\Process; | ||
$redis = new Predis\Client(); | ||
|
||
$strip_id = sha1(microtime(true)); | ||
|
||
$env = $_ENV; | ||
$cmd = sprintf( | ||
'STRIP_ID=%s gphoto2 --capture-image-and-download --interval 1 --frames 3 --hook-script %s', | ||
$strip_id, escapeshellarg( __DIR__.'/hook.php') | ||
); | ||
$dir = __DIR__.'/tools/raw/' . $strip_id; | ||
mkdir($dir); | ||
|
||
$process = new Process($cmd, $dir); | ||
$process->run(function($type, $data) { | ||
echo $data; | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! | ||
* Bootstrap @VERSION | ||
* | ||
* Copyright 2011 Twitter, Inc | ||
* Licensed under the Apache License v2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Designed and built with all the love in the world @twitter by @mdo and @fat. | ||
* Date: @DATE | ||
*/ | ||
|
||
// CSS Reset | ||
@import "/public/stylesheets/reset.less"; | ||
|
||
// Core variables and mixins | ||
@import "/public/stylesheets/variables.less"; // Modify this for custom colors, font-sizes, etc | ||
@import "/public/stylesheets/mixins.less"; | ||
|
||
// Grid system and page structure | ||
@import "/public/stylesheets/scaffolding.less"; | ||
|
||
// Styled patterns and elements | ||
@import "/public/stylesheets/type.less"; | ||
@import "/public/stylesheets/forms.less"; | ||
@import "/public/stylesheets/tables.less"; | ||
@import "/public/stylesheets/patterns.less"; | ||
|
||
|
||
form { | ||
background: #fff; | ||
text-align: left; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
#!/bin/bash | ||
|
||
./console photos:capture | ||
./console photos:process -o strip.jpg tools/raw/ | ||
DIR=`dirname $0` | ||
|
||
# ./console photos:capture $DIR/tools/raw/ $DIR/hook.php | ||
|
||
./console photos:process -o $DIR/strip.jpg $DIR/tools/raw/ | ||
|
||
# lp -d "C3400__192_168_100_101____MiniMax-2" -o page-top=0 -o page-bottom=0 -o scaling=100 strip.jpg | ||
# lp -d "HP_Color_LaserJet_CM3530_MFP" strip.jpg |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.