diff --git a/kitchenradio/app.js b/kitchenradio/app.js index 1b7e75d..e783233 100644 --- a/kitchenradio/app.js +++ b/kitchenradio/app.js @@ -56,6 +56,9 @@ radioInstance.play(); routes.init(app); app.set('Routes', routes); app.use('/action/play/:id/', routes.play); +app.use('/action/stop/', routes.stop); +app.use('/action/volume/up/', routes.volumeUp); +app.use('/action/volume/down/', routes.volumeDown); app.use('/', routes.index); // catch 404 and forward to error handler diff --git a/kitchenradio/app/radio.js b/kitchenradio/app/radio.js index 647cb93..af97312 100644 --- a/kitchenradio/app/radio.js +++ b/kitchenradio/app/radio.js @@ -20,6 +20,8 @@ var Log = null var Helper = null; var Conf = null; +var volume = '40'; + exports.init = function(Express, Configuration) { App = Express; @@ -33,6 +35,10 @@ exports.init = function(Express, Configuration) { Log.log('Radio: Found channel ' + channel.title); }); + // set default volume level + Helper.shspawn('amixer scontrols'); + Helper.shspawn('amixer sset \'PCM\' '+volume+'%'); + return this; } @@ -78,4 +84,30 @@ exports.play = function(idx) { } else { Log.error('Radio: No channel defined!'); } +} + +exports.stop = function() { + Log.log('Radio: stop playing'); + Helper.shspawn(App.get('tools_root')+'action.sh stop'); +} + +exports.volumeUp = function() { + exports.volume(5) +} + +exports.volumeDown = function() { + exports.volume(-5) +} + +exports.volume = function(step) { + Log.log('Radio: volume ' + (step>0 ? 'up' : 'down')); + + if(step != 0) { + volume = volume + step; + + if(volume > 100) { volume = 100; } + if(volume < 0) { volume = 0; } + + Helper.shspawn('amixer sset \'PCM\' '+volume+'%'); + } } \ No newline at end of file diff --git a/kitchenradio/public/images/gl_formentera_kueste.jpg b/kitchenradio/public/images/gl_formentera_kueste.jpg new file mode 100644 index 0000000..563af3b Binary files /dev/null and b/kitchenradio/public/images/gl_formentera_kueste.jpg differ diff --git a/kitchenradio/public/images/gl_formentera_seil.jpg b/kitchenradio/public/images/gl_formentera_seil.jpg new file mode 100644 index 0000000..d2b1cb6 Binary files /dev/null and b/kitchenradio/public/images/gl_formentera_seil.jpg differ diff --git a/kitchenradio/public/javascripts/radio.js b/kitchenradio/public/javascripts/radio.js index b89c77d..f8d9918 100644 --- a/kitchenradio/public/javascripts/radio.js +++ b/kitchenradio/public/javascripts/radio.js @@ -9,13 +9,16 @@ var Radio = function() { var channels; var $navigation; + var $controlPanel; return { init: function(channels_) { channels = channels_; $navigation = $('#navigation'); + $controlPanel = $('#controls'); initTiles(); + initClickOfControls(); console.log('Radio initialized with ' + channels.length + ' channels'); } }; @@ -81,5 +84,33 @@ var Radio = function() { }); }); } + + /* private */ + function initClickOfControls() { + $controlPanel.find('a').click(function(e) { + e.preventDefault(); + + var stream = $(this).attr('href'); + console.log('Action: ' + stream); + + $.ajax({ + url: stream, + context: document.body, + statusCode: { + 200: function() { + console.log('ok'); + }, + 404: function() { + console.log('Resource not found'); + }, + 500: function() { + console.log('Something went wrong'); + } + } + }).done(function() { + + }); + }); + } }(); diff --git a/kitchenradio/public/stylesheets/style.css b/kitchenradio/public/stylesheets/style.css index c285ef0..70b48b5 100644 --- a/kitchenradio/public/stylesheets/style.css +++ b/kitchenradio/public/stylesheets/style.css @@ -129,8 +129,12 @@ body { height: 98.5%; } body { - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + font: 12px "Lucida Grande", Helvetica, Arial, sans-serif; background-color: rgba(0, 0, 0, 0.38); + background-image: url('/images/gl_formentera_seil.jpg'); + background-size: auto 100%; + background-repeat: no-repeat; + background-position: left top; } a { color: #00B7FF; @@ -147,8 +151,8 @@ a { align-content: center; } #navigation .tile { - background-color: rgba(255, 255, 255, 0.68); - margin: 10px; + background-color: rgba(255, 255, 255, 0.25); + margin: 2px; flex-grow: 1; flex-basis: auto; align-self: flex-start; @@ -157,7 +161,7 @@ a { #navigation .tile .content { height: inherit; text-align: center; - padding: 10px; + padding: 2px; } #navigation .tile .content .icon { display: block; @@ -169,9 +173,34 @@ a { margin-top: 20px; font-size: 2.2em; } -#information { - background-color: rgba(255, 255, 255, 0.68); - height: 30%; - margin: 10px; - margin-top: 20px; +#navigation .tile:hover { + background-color: rgba(255, 255, 255, 0.5); +} +#controls { + background-color: rgba(255, 255, 255, 0.25); + height: 30%; + margin: 2px; + margin-top: 4px; + display: flex; + flex-wrap: nowrap; + justify-content: center; + align-items: stretch; + align-content: center; +} +#controls .control { + display: block; + margin: 2px; + flex-grow: 1; + flex-basis: auto; + align-self: flex-start; + height: 100%; + text-align: center; + text-decoration: none; + font-size: 50px; +} +#controls .control:hover { + background-color: rgba(255, 255, 255, 0.5); +} +#controls .control.empty { + visibility: hidden; } diff --git a/kitchenradio/public/stylesheets/style.less b/kitchenradio/public/stylesheets/style.less index d8e10fc..a5e42cd 100644 --- a/kitchenradio/public/stylesheets/style.less +++ b/kitchenradio/public/stylesheets/style.less @@ -1,6 +1,7 @@ @backgroundcolor: rgba(0,0,0,0.38); -@backgroundcolor_element: rgba(255,255,255,0.68); -@margin_element: 10px; +@backgroundcolor_element: rgba(255,255,255,0.25); +@backgroundcolor_element_hover: rgba(255,255,255,0.50); +@margin_element: 2px; @@ -59,8 +60,12 @@ html, body { } body { - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + font: 12px "Lucida Grande", Helvetica, Arial, sans-serif; background-color: @backgroundcolor; + background-image: url('/images/gl_formentera_seil.jpg'); + background-size: auto 100%; + background-repeat: no-repeat; + background-position: left top; } a { @@ -104,12 +109,41 @@ a { font-size: 2.2em; } } + + &:hover { + background-color: @backgroundcolor_element_hover; + } } } -#information { +#controls { background-color: @backgroundcolor_element; height: 30%; margin: @margin_element; margin-top: (@margin_element * 2); + display: flex; + flex-wrap: nowrap; + justify-content: center; + align-items: stretch; + align-content: center; + + .control { + display: block; + margin: @margin_element; + flex-grow: 1; + flex-basis: auto; + align-self: flex-start; + height: 100%; + text-align: center; + text-decoration: none; + font-size: 50px; + + &:hover { + background-color: @backgroundcolor_element_hover; + } + + &.empty { + visibility: hidden; + } + } } \ No newline at end of file diff --git a/kitchenradio/routes/routes.js b/kitchenradio/routes/routes.js index 00e33db..5b2a1fe 100644 --- a/kitchenradio/routes/routes.js +++ b/kitchenradio/routes/routes.js @@ -33,4 +33,25 @@ exports.play = function(req, res, next) { } else { res.sendStatus(400); } +} + +exports.stop = function(req, res, next) { + Log.trace('Router: stop playing'); + + Radio.stop(); + res.sendStatus(200); +} + +exports.volumeUp = function(req, res, next) { + Log.trace('Router: volume up'); + + Radio.volumeUp(); + res.sendStatus(200); +} + +exports.volumeDown = function(req, res, next) { + Log.trace('Router: volume down'); + + Radio.volumeDown(); + res.sendStatus(200); } \ No newline at end of file diff --git a/kitchenradio/views/index.jade b/kitchenradio/views/index.jade index d0077c1..fbffbde 100644 --- a/kitchenradio/views/index.jade +++ b/kitchenradio/views/index.jade @@ -6,7 +6,14 @@ block content .content img.icon span.title - div#information + div#controls + a.control.volume_plus(href="/action/volume/down/") + i.fa.fa-volume-down + a.control.volume_minus(href="/action/volume/up/") + i.fa.fa-volume-up + a.control.empty + a.control.play_pause(href="/action/stop/") + i.fa.fa-stop script. diff --git a/kitchenradio/views/layout.jade b/kitchenradio/views/layout.jade index 5c322da..264f256 100644 --- a/kitchenradio/views/layout.jade +++ b/kitchenradio/views/layout.jade @@ -2,6 +2,7 @@ doctype html html head title= title + link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css') link(rel='stylesheet', href='/stylesheets/style.css') script(src="/javascripts/vendor/jquery.min.js") script(src="/javascripts/radio.js")