sandeepmistry / node-chip-io

Johnny-Five IO Plugin for the Next Thing Co. C.H.I.P.
MIT License
96 stars 28 forks source link

Switch to synchronous I/O (for GPIO and I2C) #19

Closed sandeepmistry closed 8 years ago

sandeepmistry commented 8 years ago

Might help with #15 and #17 - needs testing.

Can be tested via: npm install sandeepmistry/node-chip-io#sync-io

cc/ @nkolban @rwaldron @ugate @sumarouno @ericterpstra

nalakawula commented 8 years ago

Hi @sandeepmistry , thanks you for mentioning me. I have tried your PR. npm install sandeepmistry/node-chip-io#sync-io

And then, try previous code #15 and try some code for my lcd 1602 with pcf8374T i2c backpack. Here the code I have tried:

lcd_hello_world.js:

"use strict";

var five = require('johnny-five');
var chipio = require('chip-io');

var board = new five.Board({
    io: new chipio()
});

board.on('ready', function() {
    let lcd = new five.LCD({
        controller: "PCF8574A", 
        address: 0x27, 
        bus: 2
    });
    lcd.cursor(0,0);
    lcd.print("Hello World");
    lcd.cursor(1,0);
    lcd.print("1234567890");
    console.log("Percobaan hello world!");
});

lcd_custom_char.js:

var five = require("johnny-five");
var chipio = require('chip-io');

var board = new five.Board({
  io: new chipio()
});

board.on("ready", function() {
  var l = new five.LCD({
        controller: "PCF8574T",
        address: 0x27,
        bus: 2,
        rows: 2,
        cols: 16
  });
    l.useChar("heart");
    l.cursor(0, 0).print("hello, I :heart: JS");
    l.cursor(1, 0).print("NodeJs is great");

});

lcd_runner.js:

var five = require("johnny-five");
var chipio = require('chip-io');

var board = new five.Board({
    io: new chipio()
});

board.on("ready", function() {
    var mylcd = new five.LCD({
        controller: "PCF8574T",
            address: 0x27,
            bus: 2,
            rows: 2,
            cols: 16
    });

    var frame = 1;
    var frames = [":runninga:", ":runningb:"];
    var row = 0;
    var col = 0;

    mylcd.useChar("runninga");
    mylcd.useChar("runningb");

    this.loop(300, function() {
        mylcd.clear().cursor(row, col).print( frames[frame ^= 1] );
        if (++col === mylcd.cols) {
            col = 0;
            if (++row === mylcd.rows) {
                row = 0;
            }
        }
    });
    console.log("percobaan running");

});

All above code work well after using sync-io. Run the code, stop the code, run again, stop again. And no more garbage text as discussed #15 . I can confirm, no more garbage text again in my lcd. Your work is great, thank you very much.

sandeepmistry commented 8 years ago

@sumarouno excellent thanks for trying out the changes!

I'll hold off merging for a week or so, so most testing can be done.

nalakawula commented 8 years ago

I will try more code as soon as possible. Fyi, this PR still not solve for #17

rwaldron commented 8 years ago
sandeepmistry commented 8 years ago

@rwaldron thanks for reviewing and providing your feedback. I think everything is up to spec now.

rwaldron commented 8 years ago

@sandeepmistry you're the best!