clean up frontend to arduino communication

This commit is contained in:
Shannon Sterz 2016-01-13 09:34:47 +01:00
parent 90240c7c39
commit 8b7b8c9a52
3 changed files with 14 additions and 12 deletions

View file

@ -1,9 +1,10 @@
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int mode = 0;
int incomingByte = 0;
boolean on = false;
RCSwitch mySwitch = RCSwitch();
int mode = 0;
void setup()
{
@ -15,10 +16,11 @@ void loop()
{
if(Serial.available()) {
incomingByte = Serial.read();
switch(mode)
{
switch (var) {
case 126:
if(on) {
controlRCOutlets("0FFF0FFF0000");
Serial.println("Light is off.");
@ -28,12 +30,13 @@ void loop()
Serial.println("Light is on.");
on = true;
}
break;
}
}
}
void controlRCOutlets(const char* sCodeWord) {
mySwitch.sendTriState(sCodeWord);
delay(1000);
}
}

View file

@ -25,10 +25,10 @@ app.factory('arduino', ['$http', function($http, auth){
}]);
app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){
$scope.test = 'Hello World!';
$scope.toggleLight = function(){
arduino.toggleLight();
};

View file

@ -10,10 +10,9 @@ router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
app.get('/toggleLight', function (req, res) {
router.get('/toggleLight', function (req, res) {
serialPort.write(new Buffer('~','ascii'));
res.send('switch light');
serialport.write(new Buffer(0x7E));
});
module.exports = router;