Skip to content

Commit

Permalink
Merge pull request #5 from gordonturner/develop
Browse files Browse the repository at this point in the history
Preparing for release 3.0
  • Loading branch information
gordonturner authored Apr 1, 2017
2 parents 0c9e5cd + d5d9be2 commit a3e1b43
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 12 deletions.
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var app = express();

// BEGIN

//var lirc = require('./routes/lirc');
//app.use('/lirc', lirc);
var lirc = require('./routes/lirc');
app.use('/lirc', lirc);

// END lirc

Expand All @@ -28,6 +28,14 @@ app.use('/cec', cec);
// END cec


// BEGIN macro

var macro = require('./routes/macro');
app.use('/macro', macro);

// END macro


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
Expand Down
208 changes: 208 additions & 0 deletions docs/2017-03-25-Aux Macro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
2017-03-25-Aux Macro
====================

Command Line
------------

- For the following:
- On Raspberry Pi connected to Samsung TV
- Kodi/osmc with cec disabled
- lirc installed
- cec-client install (from Github source)

- Created `aux.sh` script:

```
vi aux.sh
```
```
#!/bin/bash
echo "tx 2F:82:20:00" | cec-client RPI -s -d 4
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_CYCLEWINDOWS" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
irsend -d /run/lirc/lircd-lirc0 SEND_ONCE "Samsung" "KEY_UP" && sleep 0.5
```


App Calls
---------

- Call cec and set to Kodi:

```
www.cecUsb.sendCommand( 0x1F, 0x82, 0x20, 0x00 );
```

- Must wait until complete, might have to use callback?

- Then run:

```
/* TODO: Consider refactoring this very procedural process */
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_CYCLEWINDOWS', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
lircNode.irsend.send_once('JVC-RM-AJ777', 'KEY_UP', function() {
sleep.sleep(1);
});
```


Adding Sleep Step
-----------------

- This was harder then it should have been

- Using:

https://www.npmjs.com/package/sleep

- should be a simple add to the `package.json`:

```
"sleep":"5.1.0"
```

- Install dependencies:

```
npm install
```

- And code:

```
var sleep = require('sleep');

[...]

sleep.msleep(500);
```

- Got error:

```
stupid-remote:macro called aux +2ms
stupid-remote:macro Sent KEY_CYCLEWINDOWS +91ms
/home/osmc/stupid-remote/routes/macro.js:47
sleep.msleep(500);
^

TypeError: sleep.msleep is not a function
at /home/osmc/stupid-remote/routes/macro.js:47:11
at ChildProcess.exithandler (child_process.js:204:7)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:827:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
```


npm install
-----------

- Error on RPI:

```
npm install
```


```
> sleep@5.1.0 install /home/osmc/stupid-remote/node_modules/sleep
> node-gyp rebuild

module.js:327
throw err;
^

Error: Cannot find module 'nan'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at [eval]:1:1
at Object.exports.runInThisContext (vm.js:54:17)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:409:26)
at node.js:579:27
at nextTickCallbackWith0Args (node.js:420:9)
gyp: Call to 'node -e "require('nan')"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.4.27-9-osmc
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/osmc/stupid-remote/node_modules/sleep
gyp ERR! node -v v4.4.5
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm ERR! Linux 4.4.27-9-osmc
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.4.5
npm ERR! npm v2.15.5
npm ERR! code ELIFECYCLE

npm ERR! sleep@5.1.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sleep@5.1.0 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the sleep package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs sleep
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls sleep
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/osmc/stupid-remote/npm-debug.log
```

- Deleted `node_modules` and re-ran `npm install`, fixed issue


Send KEY_AUX
------------

```
router.get('/aux', function (req, res, next) {
debug('called aux');

lircNode.irsend.send_once('Samsung', 'KEY_AUX', function() {
debug("Sent KEY_AUX");

res.writeHead(200, {"Content-Type": "application/json"});
var html = '{"status":"ok"}';
res.end(html);
});

});
```

- No response
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bootstrap": "3.3.5",
"node-cec": "^0.1.2",
"lirc_node": "0.0.4",
"swagger-jsdoc": "1.3.0"
"swagger-jsdoc": "1.3.0",
"sleep":"5.1.0"
}
}
28 changes: 22 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,21 @@
</div>

<div id="task3" class="task">
<div class="button-lead"><a id="auxButton" class="btn btn-circle btn-warning" href="#" role="button">AUX</a></div>
<div class="button-body"><span class="btn description">Switch to AUX</span></div>
</div>

<div id="task4" class="task">
<div class="button-lead"><a id="ps4Button" class="btn btn-circle btn-warning" href="#" role="button">PS 4</a></div>
<div class="button-body"><span class="btn description">Switch to PS 4</span></div>
</div>
<div id="task4" class="task">

<div id="task5" class="task">
<div class="button-lead"><a id="tvOnButton" class="btn btn-circle btn-success" href="#" role="button">TV On</a></div>
<div class="button-body"><span class="btn description">Turn TV on</span></div>
</div>

<div id="task5" class="task">
<div id="task6" class="task">
<div class="button-lead"><a id="tvOffButton" class="btn btn-circle btn-danger" href="#" role="button">TV Off</a></div>
<div class="button-body"><span class="btn description">Turn TV off</span></div>
</div>
Expand Down Expand Up @@ -160,12 +165,23 @@



//
$("#auxButton").click( function( event ) {

$.get( "./macro/aux", function( data ) {
console.log(data);
});

} );



//
$("#ps4Button").click( function( event ) {

$.get( "./cec/ps4", function( data ) {
console.log(data);
});
$.get( "./cec/ps4", function( data ) {
console.log(data);
});

} );

Expand Down
6 changes: 3 additions & 3 deletions routes/lirc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var express = require('express');
var router = express.Router();
var www = require('../bin/www');

var debug = require('debug')('stupid-remote:lirc');

var lircNode = require('lirc_node');
lircNode.init();

var debug = require('debug')('stupid-remote:lirc');

/**
* handle GET /tvOn request
*
Expand Down Expand Up @@ -46,7 +46,7 @@ router.get('/switchToggle', function (req, res, next) {
* /lirc/nes:
* get:
* tags:
* - Switch Control
* - Switch Active Device Control
* description: Change input to NES
* produces:
* - application/json
Expand Down
Loading

0 comments on commit a3e1b43

Please sign in to comment.