2016-01-12 17:49:13 +01:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
2016-02-17 14:14:04 +01:00
|
|
|
var arcom = new require('../ar-com');
|
|
|
|
var RCDB = new require('../models/rc_db');
|
|
|
|
var rc_db = new RCDB();
|
|
|
|
var arduino = new arcom.Arduino();
|
|
|
|
var rc = new arcom.RC(arduino);
|
2016-01-14 18:01:51 +01:00
|
|
|
|
2016-01-14 21:43:45 +01:00
|
|
|
arduino.setup();
|
2016-01-14 18:01:51 +01:00
|
|
|
|
2016-01-13 23:47:51 +01:00
|
|
|
/* GET home page. */
|
2016-01-12 17:49:13 +01:00
|
|
|
router.get('/', function(req, res, next) {
|
|
|
|
res.render('index', { title: 'Express' });
|
|
|
|
});
|
|
|
|
|
2016-01-13 09:34:47 +01:00
|
|
|
router.get('/toggleLight', function (req, res) {
|
2016-02-17 14:14:04 +01:00
|
|
|
/*var s = "0FFF0FFF000F";
|
2016-01-18 22:35:01 +01:00
|
|
|
var str = "";
|
|
|
|
for(i = 0; i < s.length; i+=2) { str += String.fromCharCode(parseInt(s.substr(i,2), 16)); }
|
2016-01-21 22:49:04 +01:00
|
|
|
arduino.write(new Buffer('Wl' + str,'ascii'));
|
2016-02-17 14:14:04 +01:00
|
|
|
res.send('switch light');*/
|
|
|
|
|
|
|
|
rc_db.fidn(1, function (error, results, fields) {
|
|
|
|
rc.send(results[0].on_value);
|
|
|
|
});
|
2016-01-12 20:22:26 +01:00
|
|
|
res.send('switch light');
|
|
|
|
});
|
|
|
|
|
2016-01-21 22:01:57 +01:00
|
|
|
router.get('/irTest', function (req, res) {
|
2016-01-28 19:00:17 +01:00
|
|
|
//arduino.write(new Buffer('X0' + String.fromCharCode(4) + String.fromCharCode(12) + String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(2689 / 256) + String.fromCharCode(2689 % 256),'ascii'));
|
2016-01-28 18:57:15 +01:00
|
|
|
arduino.write(new Buffer('Uo000000'), 'ascii');
|
|
|
|
arduino.write(new Buffer('Up000000'), 'ascii');
|
2016-01-21 22:01:57 +01:00
|
|
|
res.send('switch light');
|
|
|
|
});
|
|
|
|
|
2016-01-12 17:49:13 +01:00
|
|
|
module.exports = router;
|