Use serialport data from TI Launchpad instead of keystrokes.

This commit is contained in:
Juho Teperi
2012-10-23 10:10:03 +03:00
parent 86c3fb0537
commit 76adadba57
4 changed files with 54 additions and 20 deletions

View File

@@ -16,13 +16,9 @@ a speed sensor.
## Speed sensor ## Speed sensor
Most basic speed sensor would be "Keyboard" that sends a keypress whenever Most basic speed sensor would be "Keyboard" that sends a keypress whenever the wheel has turned one revolution.
the wheel has turned one revolution. ~~This kind of sensor can be built from a old keyboard by soldering a reed switch to right conductors at keyboard circuit board. Some instructions here: http://www.instructables.com/id/Hacking-a-USB-Keyboard/.~~
This kind of sensor can be built from a old keyboard by soldering a reed switch Doesn't work. The reed switch wont be closed long enough for the keyboard controller or computer to register wheel revolutions.
to right conductors at keyboard circuit board. Some instructions here:
http://www.instructables.com/id/Hacking-a-USB-Keyboard/.
It is also possible to built equivalent device from Arduino Uno: It should be possible to build working device from Arduino Uno (http://mitchtech.net/arduino-usb-hid-keyboard/) or Arduino Due (http://www.i-programmer.info/news/91-hardware/4965-new-powerful-arduino-due-.html).
http://mitchtech.net/arduino-usb-hid-keyboard/. Device should read the reed switch status every 1ms and send keypress maybe every 500ms (send 'a' if there was one wheel revolution since last keypress, send 'b' if two etc).
Or more easily with the new Arduino Due:
http://www.i-programmer.info/news/91-hardware/4965-new-powerful-arduino-due-.html.

View File

@@ -11,10 +11,7 @@
".cache", ".cache",
".meteor" ".meteor"
], ],
"path": "/home/juho/Source/bicyclesim" "path": "."
},
{
"path": "/home/juho/Source/bicyclesim-bundle"
} }
] ]
} }

View File

@@ -98,7 +98,7 @@
<div class="fluid-row"> <div class="fluid-row">
<form> <form>
<legend>Asetukset</legend> <legend>Asetukset</legend>
<label>Liikekerroin. Vaikuttaa nopeuteen jolla reitillä liikutaan. Ei vaikuta nopeuslukemaan tai kuljettuun matkaan.</label> <label>Liikekerroin. Vaikuttaa kuljettuun matkaan mutta ei nopeuslukemaan.</label>
<input type="text" value="{{settings.multiplier}}" id="settings_multiplier"/> <input type="text" value="{{settings.multiplier}}" id="settings_multiplier"/>
<label>Renkaan koko, tuumia</label> <label>Renkaan koko, tuumia</label>
<input type="text" value="{{settings.diameter}}" id="settings_diameter"/> <input type="text" value="{{settings.diameter}}" id="settings_diameter"/>

View File

@@ -41,14 +41,14 @@ $(document).bind('keydown.space', function () {
} }
}); });
function speedo() { // function speedo() {
speed_buffer.push(revs * c()); // speed_buffer.push(revs * c());
revs = 0; // revs = 0;
Session.set('speed', speed_buffer.sum() / 5); // Session.set('speed', speed_buffer.sum() / 5);
} // }
setInterval(speedo, 500); // setInterval(speedo, 500);
// 5sec, 2 values / sec. // 5sec, 2 values / sec.
var speed_buffer = createRingBuffer(5 * 2); var speed_buffer = createRingBuffer(5 * 2);
@@ -72,8 +72,49 @@ Template.sim.helpers({
} }
}); });
// This version is connected to a bicycle using a TI Launchpad which sends data to
// computer using a serialport. Nodejs service reads that data using node-serialport
// and then sends it through websocket.
var sock = new SockJS("http://localhost:9999/speed");
function init_sim() { function init_sim() {
sock.onopen = function() {
debug('open');
};
sock.onmessage = function(e) {
if (Session.equals('page', 'sim') && window.point) {
debug('message', e.data);
var dist = parseInt(e.data, 10) * c();
speed_buffer.push(dist);
Session.set('speed', speed_buffer.sum() / 5);
Session.set('distance', Session.get('distance') + localStorage.multiplier * dist);
window.traveled += localStorage.multiplier * dist;
if (window.traveled >= window.point.distance) {
var next = Points.findOne({_id: window.point.next});
// Stay on current point if no next point exists
if (next) {
window.traveled -= next.distance;
maps.travel(next._id, {route: true});
window.point = next;
}
}
}
};
sock.onclose = function() {
debug('close');
};
Meteor.autosubscribe(function () { Meteor.autosubscribe(function () {
if (Session.equals('page', 'sim')) { if (Session.equals('page', 'sim')) {
var route = Routes.findOne({_id: Session.get('route')}); var route = Routes.findOne({_id: Session.get('route')});