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

Add Servo method in Arduino plugin #73

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2675ef3
Try and add Servo method
vpineda1996 Jun 8, 2014
a8f5eef
Changed port
vpineda1996 Jun 8, 2014
0acf113
Only sweep
vpineda1996 Jun 8, 2014
89ac700
Change sweep lapse
vpineda1996 Jun 8, 2014
3ad7ac8
example
vpineda1996 Jun 8, 2014
3921e73
Change LED for Servo
vpineda1996 Jun 8, 2014
24c6e32
Change led 4 servo
vpineda1996 Jun 9, 2014
da1f4f4
Change from 0 to 180 test
vpineda1996 Jun 10, 2014
07336d3
Change repository
vpineda1996 Jun 10, 2014
0814b13
jeje numbers
vpineda1996 Jun 10, 2014
3bb6352
attach Servo at the begging
vpineda1996 Jun 10, 2014
2cb6375
Testing with sweep
vpineda1996 Jun 10, 2014
6ae371d
modified amelia button css
vpineda1996 Jun 11, 2014
bb05f8f
Amelia changes
vpineda1996 Jun 11, 2014
6ef4b34
Amelia CSS
vpineda1996 Jun 11, 2014
0bd7e7e
Changed Amelia to all white letters
vpineda1996 Jun 11, 2014
ba1e419
Rotate Servo 180 degrees only
vpineda1996 Jun 11, 2014
8e48596
Change button label for servo; door open and close
vpineda1996 Jun 11, 2014
bf97e5f
Changes in color letters
vpineda1996 Jun 11, 2014
27957a7
Colors
vpineda1996 Jun 11, 2014
4b39499
Almost final colors
vpineda1996 Jun 11, 2014
556a9df
Final colors
vpineda1996 Jun 11, 2014
a2cb16e
God dammit colors
vpineda1996 Jun 11, 2014
e4cecb5
Guess 666 was the mistake
vpineda1996 Jun 11, 2014
f468eef
Colors
vpineda1996 Jun 11, 2014
619c053
Final fixes to button colors
vpineda1996 Jun 11, 2014
65974ec
When hover must be darker when active
vpineda1996 Jun 11, 2014
2f5d8e6
Inverse colors
vpineda1996 Jun 11, 2014
dce2cc4
LIGHTEEERRRR!!!!
vpineda1996 Jun 11, 2014
195cae9
Some noise from servo, might fix this
vpineda1996 Jun 11, 2014
362e436
Modify Servo's degrees from Settings
vpineda1996 Jun 11, 2014
24f730f
Coding for dummies
vpineda1996 Jun 11, 2014
5c691d1
Missed a }
vpineda1996 Jun 11, 2014
0d7ea92
Bulletproof
vpineda1996 Jun 11, 2014
96808a2
Added params annotation for servo
vpineda1996 Jun 11, 2014
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
2 changes: 1 addition & 1 deletion config/development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"port": 8080,
"port": 80,
"secret": "CHANGE_ME",
"mongo": {
"host" : "127.0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"ping": "= 0.1.7",
"wake_on_lan": "= 0.0.3",
"delivery": "= 0.0.3",
"duino": "https://github.com/ni-c/duino/tarball/master"
"duino": "https://github.com/vpineda1996/duino/tarball/master"
}
}
48 changes: 48 additions & 0 deletions plugins/arduino/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ define([ 'duino' ], function(duino) {
socket.on('arduino-led', function(data) {
that.led(data);
});
socket.on('arduino-servo', function(data) {
that.servo(data);
});
});

};
Expand Down Expand Up @@ -153,7 +156,52 @@ define([ 'duino' ], function(duino) {
}
});
};
/**
* Turn a servo on
*
* @method servo
* @param {Object} data The websocket data from the client
* @param {String} data.id The ID of the database entry from the servo to use
* @param {String} data.value The value to set (0 (off) or 1 (on))
* @param {String} item.maxdegrees The value to set the maximum position of servo (value between -360 and 360)
* @param {String} item.mindegrees The value to set the minimum position of servo (value between -360 and 360)
*/
Arduino.prototype.servo = 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-servo', data);

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

// Create Servo object
if (!that.pins[item.pin]) {
that.pins[item.pin] = new duino.Servo({
board: that.board,
pin: parseInt(item.pin)
});
that.pins[item.pin].attach();
}
//No user input the 179 and 1 shall be used
var maxd = item.maxdegrees || 179
var mind = item.mindegrees || 1
//Check and see if the maximum and minimum is set correctly else do nothing
if (360 <= parseInt(maxd) <= 360 && 360 >= parseInt(mind) >= -360) {
if(item.value == "1"){
that.pins[item.pin].write(parseInt(maxd));
}else {
//Button is off
that.pins[item.pin].write(parseInt(mind));
}
}
} else {
console.log(err);
}
});
};
/**
* Initialize the sensors attached to the Arduino
*
Expand Down
3 changes: 3 additions & 0 deletions 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.servo:after {
content: "Arduino Servo";
}
8 changes: 8 additions & 0 deletions plugins/arduino/public/js/arduino.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ require([ "jquery", "/socket.io/socket.io.js" ], function() {
$('*[data-id="' + data.id + '"]').removeClass('active');
$('*[data-id="' + data.id + '"][data-value="' + data.value + '"]').addClass('active');
});

/**
* Servo status switched
*/
socket.on('arduino-servo', 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 == 'servo')
p.description
span.muted Servo:&nbsp;
strong #{item.description}
div.btn-group(data-led="buttons-radio")
button.btn.btn-large.socket(type="button", data-socket="arduino-servo", data-value="1", data-id="#{item._id}", class=(item.value == 1 ? 'active' : ''))
i.icon-circle
| Open
button.btn.btn-inverse.btn-large.socket(type="button", data-socket="arduino-servo", data-value="0", data-id="#{item._id}", class=(item.value == 0 ? 'active' : ''))
i.icon-circle
| Close
8 changes: 8 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="servo",selected=(item.method == 'servo')) servo
div.switch-container
div.rcswitch(class=(item.method != 'rcswitch' ? 'hidden' : ''))
label(for="code") Tristate-Code:
Expand All @@ -37,6 +38,12 @@ div.container
input(type="text", name="data[#{i}][formula]", placeholder="x*100-3.14", data-required="1", value=(item.formula ? item.formula : ''))
label(for="unit") Unit (optional):
input(type="text", name="data[#{i}][unit]", placeholder="°F", data-required="0", value=(item.unit ? item.unit : ''))

div.servo(class=(item.method != 'servo' ? 'hidden' : ''))
label(for="maxdegrees") Maximum Degrees (Number)
input(type="text", name="data[#{i}][maxdegrees]", placeholder="180", data-required="1", value=(item.maxdegrees ? item.maxdegrees : ''))
label(for="mindegrees") Minimum Degrees (Number)
input(type="text", name="data[#{i}][mindegrees]", placeholder="0", data-required="1", value=(item.mindegrees ? item.mindegrees : ''))

div.irremote(class=(item.method != 'irremote' ? 'hidden' : ''))
label(for="irtype") IR Type:
Expand Down Expand Up @@ -85,6 +92,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="servo") servo
div.switch-container
div.rcswitch.hidden
label(for="code") Tristate-Code:
Expand Down
2 changes: 1 addition & 1 deletion public/css/themes/amelia.css

Large diffs are not rendered by default.