Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Add activelow support for active low devices #75

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# heimcontrol.js

Documentation can be found here: http://ni-c.github.com/heimcontrol.js/

### Additions
Added a method to control Active low relays such as this one [here](http://www.amazon.com/Active-Channel-Relay-Module-Arduino/dp/B00E7PRHVO). Since these are active low, they need to be switched off inorder to turn them on. I simply made another method, (**Active low**) that reverses the switches used in the led method. In order for this to work, i also use another duino lib name Active low which can be downloaded [here](https://gist.github.com/schneiderr/71ea2fc8abebac03ebfa).
42 changes: 42 additions & 0 deletions plugins/arduino/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ define([ 'duino' ], function(duino) {
socket.on('arduino-led', function(data) {
that.led(data);
});
socket.on('arduino-activelow', function(data) {
that.activelow(data);
});
});
});

};
Expand Down Expand Up @@ -153,6 +157,44 @@ define([ 'duino' ], function(duino) {
}
});
};
/**
* Turn an Activelow light on
*
* @method Activelow
* @param {Object} data The websocket data from the client
* @param {String} data.id The ID of the database entry from the LED to use
* @param {String} data.value The value 1 every time to trigger .75 sec send.
*/
Arduino.prototype.activelow = function(data) {

var that = this;
this.pluginHelper.findItem(that.collection, data.id, function(err, item, collection) {
if ((!err) && (item)) {
// Inform clients over websockets
that.app.get('sockets').emit('arduino-activelow', data);

item.value = (parseInt(data.value));
that.values[item._id] = item.value;

// Create LED object
if (!that.pins[item.pin]) {
that.pins[item.pin] = new duino.Activelow({
board: that.board,
pin: parseInt(item.pin)
});
}

// Change LED status
if(item.value == "1"){
that.pins[item.pin].on();
}else {
that.pins[item.pin].off();
}
} else {
console.log(err);
}
});
};

/**
* Initialize the sensors attached to the Arduino
Expand Down
5 changes: 4 additions & 1 deletion plugins/arduino/public/css/arduino.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
}
.plugin-container.arduino.led:after {
content: "Arduino LED";
}
}
.plugin-container.arduino.activelow:after {
content: "Arduino ActiveLow";
}
7 changes: 7 additions & 0 deletions plugins/arduino/public/js/arduino.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ require([ "jquery", "/socket.io/socket.io.js" ], function() {
$('*[data-id="' + data.id + '"][data-value="' + data.value + '"]').addClass('active');
});

/**
* ActiveLow status switched
*/
socket.on('arduino-activelow', function(data) {
$('*[data-id="' + data.id + '"]').removeClass('active');
$('*[data-id="' + data.id + '"][data-value="' + data.value + '"]').addClass('active');
});
/**
* Arduino sensor data received
*/
Expand Down
11 changes: 11 additions & 0 deletions plugins/arduino/views/item.jade
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ each item in items
button.btn.btn-inverse.btn-large.socket(type="button", data-socket="arduino-led", data-value="0", data-id="#{item._id}", class=(item.value == 0 ? 'active' : ''))
i.icon-circle-blank
| Off
- if (item.method == 'activelow')
p.description
span.muted Active Low: 
strong #{item.description}
div.btn-group(data-activelow="buttons-radio")
button.btn.btn-large.socket(type="button", data-socket="arduino-activelow", data-value="1", data-id="#{item._id}", class=(item.value == 1 ? 'active' : ''))
i.fa.fa-power-off
| On
button.btn.btn-inverse.btn-large.socket(type="button", data-socket="arduino-activelow", data-value="0", data-id="#{item._id}", class=(item.value == 0 ? 'active' : ''))
i.fa.fa-circle-o-notch
| Off
2 changes: 2 additions & 0 deletions plugins/arduino/views/settings.jade
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ div.container
option(value="sensor",selected=(item.method == 'sensor')) sensor
option(value="irremote",selected=(item.method == 'irremote')) ir-remote
option(value="led",selected=(item.method == 'led')) led
option(value="activelow",selected=(item.method == 'activelow')) Active Low
div.switch-container
div.rcswitch(class=(item.method != 'rcswitch' ? 'hidden' : ''))
label(for="code") Tristate-Code:
Expand Down Expand Up @@ -89,6 +90,7 @@ div.plugin-container.arduino.settings#template(style="display: none;")
option(value="sensor") sensor
option(value="irremote") ir-remote
option(value="led") led
option(value="activelow") Active Low
div.switch-container
div.rcswitch.hidden
label(for="code") Tristate-Code:
Expand Down
4 changes: 3 additions & 1 deletion views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ doctype 5
html
head
title heimcontrol.js | #{title}
link(rel='stylesheet', href='#{theme}')
link(rel='stylesheet', href='#{theme}')
link(href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css", rel="stylesheet")
link(href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css", rel="stylesheet")
link(rel='stylesheet', href='/css/bootstrap-responsive.min.css')
link(rel='stylesheet', href='/css/font-awesome.min.css')
link(rel='stylesheet', href='/css/heimcontrol.css')
Expand Down