duino bleep code not running - javascript

I am trying to run the following nodejs code, based on the duino module found here: https://github.com/ecto/duino
bleep.js:
var arduino = require("duino");
var board = new arduino.Board();
var led = new arduino.Led({
board: board,
pin: 13
});
var bleep = function() {
led.on();
setTimeout(function() {
led.off();
}, 100);
}
setInterval( bleep, 1000 );
EDIT
Based on zmo's suggestion, I am now running du.ino (found under duino/src/) on my arduino board and bleep.js on my laptop.
Whilst compiling bleep.js, I get the following error:
Error: Cannot open /dev/
I was trying to trace back to where the path is being set.
I have traced this error to duino/node_modules/serialport/serialport.js
May I know how the following line (found in serialport.js) works?
function SerialPort(path, options, openImmediately, callback) {
Before this function is called on line 49, the 'path' variable is [object Object].
But after, it becomes /dev/
where does the change take place?
Thank you.

uhuh... where to start.
It looks like you're trying to compile your js code as an arduino sketch .ino files using the arduino ide. That can't work, it should be C++ code.

Related

Why is my interval not working? (With firebase)

I stuck in a problem by coding on a javascript webapp with firebase:
function start() {
setInterval(getComps, 2000);
}
function getComps() {
permis=true;
for (var pc=policeNum; pc>0; pc--) {
policeRef.child(pc).once('value', function(snapshot) {
var oldData = snapshot.val();
//KI:
var compX=newX-oldData.X;
var compY=newY-oldData.Y;
updatePosition(compX, compY);
});
}
}
(The real code of the app is of course more complicated but this is enough to understand the problem I think) (The start() is called with a button in my index.html)
When I run my app I can see that updatePosition() is only called once in the beginning but not later again in my wanted interval. Do someone know what´s wrong here and can give me a example or explanation of a better code.
Thank you for every answer, I hope you can understand what I mean. (all variables are of course defined)

How can I trigger an error from inside gulp-esdoc?

I am using gulp-esdoc to generate my documentation (and it already works).
Today I added a git pre-commit hook, it launches multiples gulp tasks and prevent any commit if one of the tasks returns an error.
I works for most of my tasks, but for gulp-esdoc, I don't know how to return such an error to prevent the commit.
I configured my esdoc this way :
gulp.task('documentation', function() {
gulp.src("./client/")
.pipe(esdoc({
destination: "./docs",
"title": "SOMETHING",
index: "./README.md",
"plugins": [{
"name": "./README/docplugins/on-complete.js"
}]
}));
});
As you can see, I am using an esdoc plugin to do some code once the documentation has been generated, here is the code for the plugin :
var colors = require('colors'),
gutil = require('gulp-util');
exports.onComplete = function(ev) {
var output = require('../../docs/coverage.json');
var expectedCoverage = 100; // todo : get from option instead
var percentCovered = (output.actualCount / output.expectCount) * 100;
if (percentCovered < expectedCoverage) {
console.log('Code coverage is not sufficient (expected ' + expectedCoverage + '%, received only ' + percentCovered + '%) !!! Write some documentation or get out !'.red);
// return false; // todo
} else {
console.log('Code coverage is complete, well done :)'.green);
// return true;
}
};
The main goal here is to return an error if my code documentation is not 100% covered (the code logic is working, if a comment is missing in my JS code, I go into the line with the "todo".
Finally, here is my (simplified) git-hook (in my gulpfile) :
gulp.task('pre-commit', function () {
gulp.start('lint');
gulp.start('documentation');
});
The 'lint' part works, it prevent commit if I have an error in my code. But the 'documentation' code, using gulp-esdoc, doesn't return any error, so the commit is done :( I don't know what to do to return an error and prevent the git commit.
I need to do this because I want the junior developers joining my team to be forced to document their code :p
Thanks for helping !
One option is to throw a PluginError:
throw new gutil.PluginError('esdoc', 'Something broke');
This will cause your gulp process to exit with a non-zero exit code. It will however leave a rather ugly stack trace on STDERR (especially since gulp-esdoc rethrows errors from plugins).
Another option then is to explicitly exit the process with a specific exit code:
process.exit(1);
The process object in Node.js is a global object and can be accessed from anywhere without having to require() it.

AngularJS infinite-scroll issue

I'm trying to use infinite-scroll to lazy load images. I'm getting the following error when it's called though:
TypeError: undefined is not a function
at handler (http://onfilm.us/ng-infinite-scroll.js:31:34)
Here's a very watered down look of what I have thus far.
function tagsController($scope) {
$scope.handleClick = function(tags) {
// Parse Tags
$scope.finished_tags = parsed_data;
};
$scope.$emit( 'handleEmit', { tags = $scope.finished_tags; });
};
function imagesController($scope,$http) {
var rows_per = 5;
$scope.$on('handleBroadcast', function(event, args) {
// Sort the images here, put them in matrix
// Example: matrix[row_number] = { picture1, picture2, picture3 }
$scope.data = matrix;
$scope.loadMore();
};
$scope.loadMore() = function() {
var last = $scope.images.length;
for ( var i = 0; i < rows_per; i++ ) {
$scope.images[last + i] = new Array();
$scope.images[last + i] = $scope.data[last + i].slice( 0 );
}
}
}
The rough idea is that the page loads the first time (w/ no tags) and get images from a PHP script. All of them. They are stored, and loadMore() is called which will populate $scope.images with 5 rows of images. It does, and they are loaded.
The line in that script is accessing $window.height and $window.scrollup. I'm still pretty green w/ Javascript, so feel free to lambast me if I'm doing something horribly wrong.
This is the broken version I'm testing with:
http://onfilm.us/test.html
Here is a version before the lazy loading was implemented, if seeing how the tags work will help. I don't think that's the issue here though.
http://onfilm.us/image_index.html
EDIT: I do think this is a problem w/ the ng-infinite-scroll.js script. The error is on line 31 (of version 1.0.0). It's telling me:
TypeError: undefined is not a function
It doesn't like $window apparently.
My JS Kung Fu is not really equipped to say why. YOu can see a literal copy/paste job from the simple demo here (with the error) onfilm.us/scroll2.html
By refering your site, It appears at first instance that your HTML-markup is not appropriate. You should move infinite-scroll to the parent of ng-repeat directive so that it will not make overlapping calls for each row generated. Please visit http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html

Node.js - Ensuring a non-blocking call finishes

I'm using the pg postgres node module to interact with my database. The code works without an issue when I use pg's evented API. Below is an example of the code:
Migration.js
exports.up = function(logger){
var pg = require("pg")
, connectionString = //process.env.CONNECTIONSTRING
, client = new pg.Client(connectionString);
client.connect();
var cmd = "CREATE TABLE users( "
+ "id SERIAL NOT NULL, "
+ "firstName VARCHAR(50) NOT NULL, "
+ "lastName VARCHAR(50) NOT NULL, "
+ "CONSTRAINT pk_userid PRIMARY KEY (id) "
+ ")";
var query = client.query(cmd);
query.on("end", function(){
client.end();
logger.log("complete");
});
};
I'm using commander.js to write a command line utility around this migration script; however, the non-blocking call of the pg snippet is freeing up the command line interface script to finish before the database updates have been done. Below is an example commander snippet:
MyCliTool
var program = require('commander');
program
.version('1.0.2');
program
.command("up")
.description("Migrates up")
.action(function(){
require("../src/migration").up();
});
// Additional code removed for brevity
Is there a way that I can change the migration (or the commander.js app) script to ensure that the migration's up() function will finish prior to my cli script finishing? I have tried using callbacks but that appears to not be working.
UPDATE
Another example to illustrate this point. Below is a unit test (written with mocha) concerning the issue.
Up-test.js
describe("feature", function(){
it("should finish", function(){
var logger = {};
var finished = false;
logger.log = function(){finished = true;};
var migration = require("../src/migration.js");
migration.up(logger);
assert(finished, "function didn't finish"); // finished is false when this gets called.
});
});
Looks like your original script has a pain point around program.action(function () {});:
program
.command("up")
.description("Migrates up")
.action(function(){
require("../src/migration").up();
// nothing preventing this function from exiting immediately
});
I poked around a bit in commander.js docs and couldn't find anything regarding supplying a callback to your .action() program. If I were writing it, the code would look something like this:
program
.command("up")
.description("Migrates up")
.action(function (completedCallback) {
require("../src/migration").up(function () {
// migration is complete
completedCallback();
});
});
Your postgre-related script looks fine, though. A somewhat unrelated note might be to have require("../src/migration").up(); return an instance of require("events").EventEmitter and emit events you'd like to have visibility into, instead of using a logger variable. But that's just preference.
Try setting timers (http://nodejs.org/api/timers.html). We do this within our Azure CLI tool to have a spinner that runs when you are doing long running operations.
You can drill into the code here to see how we do it: https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/cli/cli.js. Search for the progress() function.

OLE ERROR 805303E in delphi?

hello
I am testing a function to load an html code in a geckobrowser (gecko component in Delphi).
Here the function
procédure TCustomGeckoBrowser.LoadHTML (htmlCode: string);
var
domwindow: nsIDOMWindow;
domdoc: nsIDOMDocument;
domhtmldoc: nsIDOMHTMLDocument;
nsstr: IInterfacedString;
begin
domwindow: = GetContentWindow;
domdoc: = GetContentDocument;
domhtmldoc: = domdoc que nsIDOMHTMLDocument;
nsstr: = nouvelleChaine;
nsstr.Assign (htmlCode);
domhtmldoc.Write (nsstr.AString);
end;
but the programme show an error of type "OLE ERROR 805303E8". I traced execution and found that the problem is in the line: domhtmldoc.Write (nsstr.AString)
the function "write" is declared in the interface of my component:
nsIDOMHTMLDocument = interface(nsIDOMDocument)
procedure Writeln(const text: nsAString); safecall;
.....
end;
Have you encountered such an error?
I used a temporary solution that needs to create a temporary file and then load do with the gecko. but with this solution, I can not make a step backwards.
that's why I seek another solution that allows me to make change on the webpage.
thancks for your help

Categories