-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-exhibition-runner.sh
executable file
·117 lines (84 loc) · 2.75 KB
/
script-exhibition-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
// Modules
// =======
var child_process = require( 'child_process' );
var os = require( 'os' );
var fs = require( 'fs' );
// Config
// ======
var IS_VIDEO_MASK = 128;
// Startup
// =======
getPideeValue( function ( value ) {
if ( getMaskIsSet( value, IS_VIDEO_MASK ) ) {
startVideoPlayer( value - IS_VIDEO_MASK );
} else {
startWebApp( value );
}
});
// Runners
// =======
// Startup Video
// -------------
function startVideoPlayer ( number ) {
getFilenameForNumber( 'videos', number, function ( filename ) {
console.log( 'Will play video', filename );
logProcess( 'omx', child_process.spawn( 'omxplayer', [ '-b', '--loop', '--no-osd', __dirname + '/videos/' + filename ] ) );
});
}
// Startup Webapp
// --------------
function startWebApp ( number ) {
// Start the webserver serving
logProcess( 'server', child_process.spawn( 'python', [ '-m', 'SimpleHTTPServer', '3000' ], { cwd: __dirname } ) );
// Start the browser
getFilenameForNumber( 'html', number, function ( filename ) {
console.log( 'Attempting to play:', filename );
logProcess( 'browser', child_process.spawn( __dirname + '/lib/script-run-browser.sh', [ 'http://0.0.0.0:3000/html/' + filename ] ) );
});
}
// Utils
// =====
function logProcess( name, process ) {
process.stdout.on( 'data', function ( data ) {
console.log( name, '(stdout)', data.toString() );
});
process.stdin.on( 'data', function ( data ) {
console.log( name, '(stderr)', data.toString() );
});
}
// Get Pidee Value
// ---------------
function getPideeValue ( callback ) {
var platform = os.platform();
if ( platform == 'darwin' ) {
var value = 17;
console.log( 'On OSX, faking value with', value );
setImmediate( function () {
callback( value );
});
return;
}
child_process.exec( __dirname + '/lib/print-dip', onPideeValue );
function onPideeValue ( error, stdout, stderror ) {
console.log( 'Print-dip:', stdout );
var value = parseInt( stdout, 10 );
console.log( 'Pidee value:', value );
callback( value );
}
}
function getMaskIsSet ( value, mask ) {
return (value & mask) !== 0;
}
function getFilenameForNumber ( path, number, callback ) {
console.log( 'Looking for', path, number );
var process = child_process.spawn( __dirname + '/lib/script-get-files.sh', [ path, number ], { cwd: __dirname } );
var files = '';
process.stdout.on( 'data', function ( data ) {
files += data.toString();
});
process.on( 'close', function () {
console.log( 'process finished with:', files );
callback( files.replace(/\n$/, '') );
});
}