Ejemplo n.º 1
0
/**
 *
 * @param pump
 * @returns {deferred.promise|*}
 */
function startPump( pump ){
    var deferred = Q.defer();
    var timer;

    b.digitalWrite( pump, ON );

    timer = setTimeout( function(){
        b.detachInterrupt( settings.inputs.tankSignal );
        deferred.reject( new Error( "Timeout on pumping cycle" ) );
    }, timeOuts.primeTimeOut );

    b.attachInterrupt( settings.inputs.flowSignal, inputHandler, b.FALLING, function(){
        b.detachInterrupt( settings.inputs.tankSignal );
        b.detachInterrupt( settings.inputs.flowSignal );
        deferred.reject( new Error( "Flow dropped below acceptable levels" ) );
    } );

    b.attachInterrupt( settings.inputs.tankSignal, inputHandler, b.RISING, function(){
        clearTimeout( timer );
        b.detachInterrupt( settings.inputs.flowSignal );
        b.detachInterrupt( settings.inputs.tankSignal );
        deferred.resolve();
    });

    return deferred.promise;
}
Ejemplo n.º 2
0
function init()
{
    console.log("init");
    
    //init the state
    isInit = false;
    
    //init timer
    timer = null;
    
    //light up the led 0
    b.pinMode(INITLED, b.OUTPUT);
    b.digitalWrite(INITLED, b.HIGH);
	
	
	//set start led
	b.pinMode(STARTLED, b.OUTPUT);
    b.digitalWrite(STARTLED, b.LOW);
	
	//init the send port and cut port
	b.pinMode(ULTRASONIC_OUTPUT, b.OUTPUT);
	b.digitalWrite(ULTRASONIC_OUTPUT, b.LOW);
	b.pinMode(CUT_OFF, b.OUTPUT);
	b.digitalWrite(CUT_OFF, b.HIGH);
	
	//init the receive ports and interrupt
	b.pinMode(GA, b.OUTPUT);
	b.pinMode(GB, b.OUTPUT);
	b.pinMode(GC, b.OUTPUT);
	b.pinMode(GD, b.OUTPUT);
	
	b.pinMode(INHIBIT1, b.OUTPUT);
	b.digitalWrite(INHIBIT1, b.HIGH);
	b.pinMode(INHIBIT2, b.OUTPUT);
	b.digitalWrite(INHIBIT2, b.HIGH);
	
    //set start button
    b.pinMode(START, b.INPUT);
	b.attachInterrupt(START, true, b.CHANGE, pushStart);
    //b.attachInterrupt(START, true, b.RISING, startWork);
	//b.attachInterrupt(START, true, b.FALLING, finishWork);
    
    //set up receiver
	b.attachInterrupt(SIG1, true, b.FALLING, recv1);
	b.attachInterrupt(SIG2, true, b.FALLING, recv2);
    
    //delay(2000);
    console.log("init done\n");
	//setTimeout(restore("hhhh"), 100);
    isInit = true;
    
}
Ejemplo n.º 3
0
function doAttach(x) {
    if(x.err) {
        console.log('x.err = ' + x.err);
        return;
    }
    b.attachInterrupt(button, true, b.CHANGE, printStatus);
}
Ejemplo n.º 4
0
    init:function(){
            var errorFlag = false;
            stop = false;

            // TODO: Pin needed for pressure switch
            b.attachInterrupt( settings.inputs.emergencyBtn, inputHandler, b.RISING, emergencyStop );

            _.forEach( settings.relays, function( pin ){
                if( b.pinMode( pin, b.OUTPUT ) === false ){
                    errorFlag = true;
                }
            });

            _.forEach( settings.inputs, function( pin ){
                if( b.pinMode( pin, b.INPUT ) === false ){
                    errorFlag = true;
                }
            });

            if( errorFlag === true ){
                logger.info( "pump pins initialized" );
            } else {
                logger.error( "pin assignment failed" );
                throw new Error( "Pin assignment failed" );
            }
        },
Ejemplo n.º 5
0
function doAttach(x) {
    if(x.err) {
        console.log('x.err = ' + x.err);
        return;
    }
    // Call pingEnd when the pulse ends
    b.attachInterrupt(echo, true, b.FALLING, pingEnd);
}
MotionSensor.prototype.init = function(config) {
  config
    .type('motion-sensor')
    .name('Motion Sensor')
    .state('undetermined');

  b.pinMode(this.pin, b.INPUT);
  b.attachInterrupt(this.pin, true, b.CHANGE, this.onChange.bind(this));
};
Ejemplo n.º 7
0
exports.rainInterrupt = function (callback) {
   if (! piodb.pins) {
      return false;
   }
   if (! piodb.pins.rain) {
      return null;
   }
   io.attachInterrupt(piodb.pins.rain, true, piodb.pins.edge, callback);
}
Ejemplo n.º 8
0
function setupButtons () {
	bone.pinMode(DRAW_BUTTON, bone.INPUT, 7, 'pulldown');
	bone.pinMode(CLEAR_BUTTON, bone.INPUT, 7, 'pulldown');
	bone.pinMode(DRAW_LED, bone.OUTPUT);
	bone.attachInterrupt(DRAW_BUTTON, true, bone.FALLING, function (x) {
		if (!locked) {
			draw = !draw;
		}

		if (draw) {
			bone.digitalWrite(DRAW_LED, bone.HIGH);
		} else {
			bone.digitalWrite(DRAW_LED, bone.LOW);
		}
	});
	bone.attachInterrupt(CLEAR_BUTTON, true, bone.FALLING, function (x) {
		if (!locked) {
			clearMatrix();
		}
	});
}
Ejemplo n.º 9
0
 bonescript.digitalRead(node.pin, function (x) {
             // Initialise the currentState and lastActveTime variables based on the value read
             node.currentState = Number(x.value);
             if (node.currentState === node.activeState) {
                 node.lastActiveTime = Date.now();
                 // switch to process.hrtime()
             }
             // Attempt to attach a change-of-state interrupt handler to the pin. If we succeed,
             // set the input event and interval handlers, then send an initial message with the
             // pin state on the first output
             if (bonescript.attachInterrupt(node.pin, true, bonescript.CHANGE, interruptCallback)) {
                 node.interruptAttached = true;
                 node.on("input", inputCallback);
                 node.intervalId = setInterval(timerCallback, node.updateInterval);
             } else {
                 node.error("Failed to attach interrupt");
             }
             setTimeout(function () { node.emit("input", {}); }, 50);
         });
Ejemplo n.º 10
0
 bonescript.digitalRead(node.pin, function (x) {
         // Initialise the currentState based on the value read
         node.currentState = Number(x.value);
         // Attempt to attach an interrupt handler to the pin. If we succeed,
         // set the input event and interval handlers
         var interruptType;
         if (node.countType === "pulse") {
             // interruptType = bonescript.FALLING; <- doesn't work in v0.2.4
             interruptType = bonescript.RISING;
         } else {
             interruptType = bonescript.CHANGE;
         }
         if (bonescript.attachInterrupt(node.pin, true, interruptType, interruptCallback)) {
             node.interruptAttached = true;
             node.on("input", inputCallback);
             node.intervalId = setInterval(timerCallback, node.updateInterval);
         } else {
             node.error("Failed to attach interrupt");
         }
     });
Ejemplo n.º 11
0
/**
 *
 * @param outlet
 * @returns {deferred.promise|*}
 */
function startOutlet( outlet ){
    var deferred = Q.defer();
    var timer;
    var signal = ( outlet === settings.relays.pump1Outlet ) ? settings.inputs.pump1Outlet : settings.inputs.pump2Outlet;

    b.digitalWrite( outlet, ON );

    timer = setTimeout( function(){
        b.digitalWrite( outlet, OFF );
        b.detachInterrupt( signal );
        deferred.reject( new Error( "Timeout on valve opening" ) );
    }, timeOuts.outletTimeOut );

    b.attachInterrupt( signal, inputHandler, b.RISING, function(){
        clearTimeout( timer );
        b.detachInterrupt( signal );
        deferred.resolve();
    });

    return deferred.promise;
}
Ejemplo n.º 12
0
/**
 *
 * @returns {deferred.promise|*}
 */
function startPrime(){

    var deferred = Q.defer();
    var timer;

    b.digitalWrite( settings.relays.prime1, ON );

    timer = setTimeout( function(){
        b.detachInterrupt( settings.inputs.primeSignal );
        b.digitalWrite( settings.relays.prime1, OFF );
        deferred.reject( new Error( "Timeout on prime" ) );
    }, timeOuts.primeTimeOut );

    b.attachInterrupt( settings.inputs.primeSignal, inputHandler, b.RISING, function(){
        clearTimeout( timer );
        b.detachInterrupt( settings.inputs.primeSignal );
        b.digitalWrite( settings.relays.prime1, OFF );
        deferred.resolve();
    });

    return deferred.promise;
}
Ejemplo n.º 13
0
function initDevices () {
	// Set up pins
	bone.pinMode(leftButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(rightButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(upButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(downButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(drawButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(clearButton, bone.INPUT, 7, 'pulldown');
	bone.pinMode(leftLED, bone.OUTPUT);
	bone.pinMode(rightLED, bone.OUTPUT);
	bone.pinMode(upLED, bone.OUTPUT);
	bone.pinMode(downLED, bone.OUTPUT);
	bone.pinMode(drawLED, bone.OUTPUT);

	// Set up asynchronous function calls
	bone.attachInterrupt(leftButton, true, bone.FALLING, function (x) {processButton('left');});
	bone.attachInterrupt(rightButton, true, bone.FALLING, function (x) {processButton('right');});
	bone.attachInterrupt(upButton, true, bone.FALLING, function (x) {processButton('up');});
	bone.attachInterrupt(downButton, true, bone.FALLING, function (x) {processButton('down');});
	bone.attachInterrupt(clearButton, true, bone.FALLING, function (x) {processButton('clear');});
	bone.attachInterrupt(drawButton, true, bone.FALLING, function (x) {processButton('draw');});

	async.series([
		function (callback) {
			matrix.writeBytes(0x21, [0x00]); // 8x8 Bi-Color LED Matrix Set-up
			callback(null);
		},
		function (callback) {
			matrix.writeBytes(0x81, [0x00]); // Display on and no blinking
			callback(null);
		},
		function (callback) {
			matrix.writeBytes(0xE7, [0x00]); // Configures the brightness
			callback(null);
		}
	], function (error) {
		if (error) {
			console.log(error);
		}
	});
}
Ejemplo n.º 14
0
function attQ(x){
	b.attachInterrupt(quitButton, true, b.RISING, quit);
}
Ejemplo n.º 15
0
function attT1(x){
	b.attachInterrupt(alert1, true, b.FALLING, tHandler);
}
Ejemplo n.º 16
0
    ydir = -1,
    colorL = [127, 0, 0],  // Color of ball (RGB)
    colorR = [0, 0, 127],  // Color of ball (RGB)
    color,
    bgnd = [0, 0, 0],     // Color of background
    grid = new Array(xlen*ylen),  // Playing field
    ms   = 20,   // Time (in ms) between moves
    pin  = 'P9_42',   // Pin with the reverse button
    zone = 25;     // Size of zone where reverse will occur
    
var x = 0,        // Current location
    y = 0;
    
b.pinMode(pin, b.INPUT);    // Set pin to be INPUT

b.attachInterrupt(pin, true, b.RISING, reverse);  // Call reverse() whenever button is pressed

function reverse() {
  console.log("x=%d", x)
  if(x<zone || x>xlen-zone-1) {   // If in the zone, reverse
    xdir = -xdir;
    if(xdir === 1) {
      color = colorL;
    } else {
      color = colorR;
    }
  }
}

// Initialize the grid of LEDs
for(var i=0; i<grid.length; i++) {
Ejemplo n.º 17
0
var b             = require('bonescript');
console.log("Loading child_process...");
var exec = require('child_process').exec;

var inputPin = 'P8_45';
var runMe = "./weatherStation.js";
if(process.argv.length >= 3) {
    runMe = process.argv[2];
}
if(process.argv.length === 4) {
    inputPin = process.argv[3];
}

b.pinMode(inputPin, b.INPUT);

b.attachInterrupt(inputPin, true, b.FALLING, interruptCallback);

function interruptCallback(x) {
    if(!x.attached) {
        console.log("Callback");
        exec(runMe, function(err, stdout, stderr) {
            if(err) {
                console.log("err: " + err);
            }
            if(stderr) {
                console.log("stderr: " + stderr);
            }
            if(stdout) {
                console.log("stdout: " + stdout);
            }
         });
wardLight('green');  // At begining ward light will turned on for 1sec indicating that it is working and device is up
setTimeout(wardLight('off'), 2000);
presenceIndication('green'); // At begining presence indicator will turned on for 1sec indicating that it is working and device is up
setTimeout(presenceIndication('off'),2000);

//after connection server sends an event named connection 
socket.on('connected', function (data) {
  console.log(data.status);
});



///*****************function loop************************ \\\ 
setInterval(hearRate, heartbitRate); //Checking the Heartbit
console.log('HeartBit started');
b.attachInterrupt(pendant_button, true, b.RISING, callNurse);//input of pendant is interrupt driven, RISING, FALLING, CHANGE, whenever from low pin goes to high it calls callNurse function.
console.log("Ready to take input");
b.attachInterrupt(presence_button, true, b.RISING, nursePresence);//input of nurse presence is interrupt driven, RISING, FALLING, CHANGE, whenever from low pin goes to high it calls nursePresence function.
b.attachInterrupt(cancel_button, true, b.RISING, cancelCall); // cancels emergency or bluecode call

 

/// ***************function Definition**********************\\\


//this is the main operation handling function
function executeState()
{
    
    switch (state.value)
        {
Ejemplo n.º 19
0
#!/usr/bin/env node
var b = require('bonescript');
var util = require('util');
var s = require("child_process");

var P1 = "P9_13";
var P2 = "P9_11";
var P1signal = 0;
var P2signal = 0;

s.exec("i2cset -y 1 0x48 0x3 0x19");
s.exec("i2cset -y 1 0x49 0x3 0x19");

b.pinMode(P1, b.INPUT);
b.pinMode(P2, b.INPUT);
b.attachInterrupt(P1, true, b.FALLING, P1Alert);
b.attachInterrupt(P2, true, b.FALLING, P2Alert);

function P1Alert()
{
    //util.print("1\n");
    if(P1signal)
    {
        var x = s.exec('i2cget -y 1 0x48 0', function(stdout, stderr) {
            //console.log(stderr);
            var f = stderr*9/5+32;
            util.print(util.format("TMP 1:   Celsius: %d   Farenheit: %d\n", stderr, f));
        });
    }
    P1signal = 1;
}
Ejemplo n.º 20
0
#!/usr/bin/env node

var b = require('bonescript');

//read GPIO
var alert = 'P9_21';
var alert2 = 'P9_22';

b.pinMode(alert, b.INPUT, 7, 'pullup');
b.pinMode(alert2, b.INPUT, 7, 'pullup');
state = b.digitalRead(alert);
state2 = b.digitalRead(alert2);
console.log('alert state =' + state);
console.log('alert state 2=' + state2);
//interrupt
b.attachInterrupt(alert, false, b.CHANGE, printStatus);
b.attachInterrupt(alert2, false, b.CHANGE, printStatus2);

function printStatus(x) {
	console.log('x.value = ' + x.value);
}

function printStatus2(x) {
	console.log('x.value2 = ' + x.value);
}
Ejemplo n.º 21
0
var bonescriptObject = require('bonescript');

// Connect a button to this pin (no need to add a pull-down resistor)
var inputPin = 'P8_8';
bonescriptObject.pinMode(inputPin, bonescriptObject.INPUT);
bonescriptObject.attachInterrupt(inputPin, true, bonescriptObject.FALLING, interruptCallback);



function interruptCallback(x) {
    // Add the code that you want to execute when the button is pressed
    // For instance, you can display something in the console
}
Ejemplo n.º 22
0
var b = require('bonescript');
var fs= require('fs');
var bulbPin = 'P8_10';
var fanPin = 'P8_12';
var fanUpPin = 'P8_14';
var fanDownPin = 'P8_16';

b.pinMode(bulbPin, b.INPUT);
b.pinMode(fanPin, b.INPUT);
b.pinMode(fanUpPin, b.INPUT);
b.pinMode(fanDownPin, b.INPUT);

b.attachInterrupt(bulbPin, true, b.RISING, bulb);
b.attachInterrupt(fanPin, true, b.RISING, fan);
b.attachInterrupt(fanUpPin, true, b.RISING, fanUp);
b.attachInterrupt(fanDownPin, true, b.RISING, fanDown);

function bulb(x) {
	console.log('bulb'); 
	var bulbState = fs.readFileSync("/var/www/FYP/views/txt/bulbState.txt", "utf8");
    fs.writeFileSync("/var/www/FYP/views/txt/bulbState.txt", 1-bulbState); 
}

function fan(x) {
	console.log('fan'); 
	var fanState = fs.readFileSync("/var/www/FYP/views/txt/fanSwitchState.txt", "utf8");
    fs.writeFileSync("/var/www/FYP/views/txt/fanSwitchState.txt", 1-fanState); 
}

function fanUp(x) {
	console.log('fan up'); 
Ejemplo n.º 23
0
var toggleState = b.LOW;
var toggleState2 = b.LOW;

console.log('Please connect ' + inputPin + ' to ' + outputPin +
    ' with a 1kohm resistor');
console.log('Please connect ' + inputPin2 + ' to ' + outputPin2 +
    ' with a 1kohm resistor');
b.pinMode(inputPin, b.INPUT);
b.pinMode(outputPin, b.OUTPUT);
b.pinMode(ledPin, b.OUTPUT);
b.pinMode(inputPin2, b.INPUT);
b.pinMode(outputPin2, b.OUTPUT);
b.pinMode(ledPin2, b.OUTPUT);
b.digitalWrite(outputPin, b.LOW);
b.digitalWrite(outputPin2, b.LOW);
b.attachInterrupt(inputPin, inputHandler, b.CHANGE);
b.attachInterrupt(inputPin2, inputHandler2, b.CHANGE);
toggle();
toggle2();

function inputHandler(x) {
    b.digitalWrite(ledPin, x.value);
}

function inputHandler2(x) {
    b.digitalWrite(ledPin2, x.value);
}

function toggle() {
    toggleState = (toggleState == b.LOW) ? b.HIGH : b.LOW;
    b.digitalWrite(outputPin, toggleState);
Ejemplo n.º 24
0
//Attach the interrupt
function attToggle(){
	b.attachInterrupt(leader, true, b.CHANGE, toggle);
}
Ejemplo n.º 25
0
        console.log(faq[i]);
        var gridToParse = faq[i].join('');
        red[i] = parseInt(gridToParse,2);
        console.log("red is "+red[i]);
        matrix.writeBytes(i*2, [green[i], red[i]]);
}

setInterval(readEncoder, period); 
setInterval(readEncoder1, period);


//b.attachInterrupt(button1, true, b.CHANGE, printStatus1);
//b.attachInterrupt(button2, true, b.CHANGE, printStatus2);
//b.attachInterrupt(button3, true, b.CHANGE, printStatus3);
//b.attachInterrupt(button4, true, b.CHANGE, printStatus4);
b.attachInterrupt(bClear,  true, b.CHANGE, printStatus5);



function printStatus1(x1)
{     
  if(x1.value ==1)
  {
    b.digitalWrite(LED1,b.HIGH);
    if(z>0)z=z-1;
  }  
  if(x1.value ==0)
  {
    b.digitalWrite(LED1,b.LOW);
    console.log("y is " +y);
    console.log("z is " +z);
Ejemplo n.º 26
0
#!/usr/bin/env node
var b = require('bonescript');
var leds =    ["P9_11", "P9_13", "P9_15", "P9_17"];
var buttons = ["P9_12", "P9_14", "P9_16", "P9_18"];
var map = {"P9_12": "P9_11", "P9_14": "P9_13", "P9_16": "P9_15", "P9_18": "P9_17", };

for(var i in leds) {
    b.pinMode(leds[i], b.OUTPUT);
}
for(var i in buttons) {
    b.pinMode(buttons[i], b.INPUT, 7, 'pulldown');
}

for(var i in leds) {
    b.digitalWrite(leds[i], 0);
}

for (var i in leds) {
    console.log("buttons[" + i + "] = " + buttons[i]);
    b.attachInterrupt(buttons[i], true, b.CHANGE, toggle);
}

console.log("Ready to go");

function toggle(x) {
        b.digitalWrite(map[x.pin.key], x.value);
        console.log(x.pin.key);
        console.log(map[x.pin.key]);
    }
Ejemplo n.º 27
0
const port = 9090, // Port to listen on
    http  = require('http'),
    request = require('request'),
    url   = require('url'),
    util  = require('util'),
    qs    = require('querystring'),
    b     = require('bonescript');
const key = 'EG33hBxy7L7W3DvKnNoCh';
const LED = 'P9_14';
const button = 'P9_12';
const event = 'LED';
    
b.pinMode(LED, b.OUTPUT);
b.pinMode(button, b.INPUT);

b.attachInterrupt(button, true, b.RISING, buttonPressed);

// This is called when the button is pressed.  It triggers a maker
// channel that sends a notification.

function buttonPressed(x) {
    if(!x.attached) {
        console.log("button pressed");
        var string = {value1: 'My', value2: 'Test 2', value3: 'BeagleBone'};
    
        var url = 'https://maker.ifttt.com/trigger/' + event + '/with/key/' + key + 
                '?' + qs.stringify(string);
    
        console.log(url);
        request(url, requestCallback);
Ejemplo n.º 28
0
for(i=0; i<number; i++){
    for(j=0;j<number;j++){
    faq[i][j]=0;
    }
}

for (i=0; i<number; i++){
        console.log(faq[i]);
        var gridToParse = faq[i].join('');
        red[i] = parseInt(gridToParse,2);
       console.log("red is "+red[i]);
        matrix.writeBytes(i*2, [green[i], red[i]]);
	console.log("empt print to i2c");
}

b.attachInterrupt(button1, true, b.CHANGE, printStatus1);
b.attachInterrupt(button2, true, b.CHANGE, printStatus2);
b.attachInterrupt(button3, true, b.CHANGE, printStatus3);
b.attachInterrupt(button4, true, b.CHANGE, printStatus4);
b.attachInterrupt(bClear,  true, b.CHANGE, printStatus5);

function printStatus1(x1)
{     
  if(x1.value ==1)
  {
    b.digitalWrite(LED1,b.HIGH);
    if(z>0)z=z-1;
  }  
  if(x1.value ==0)
  {
    b.digitalWrite(LED1,b.LOW);
Ejemplo n.º 29
0
	grid[i] = new Array(size);
}

//set button and LED pinmode
b.pinMode(LED_left, b.OUTPUT, 7);
b.pinMode(LED_up, b.OUTPUT, 7);
b.pinMode(LED_right, b.OUTPUT, 7);
b.pinMode(LED_down, b.OUTPUT, 7);

b.pinMode(button_left, b.INPUT, 7, 'pullup');
b.pinMode(button_up, b.INPUT, 7, 'pullup');
b.pinMode(button_right, b.INPUT, 7, 'pullup');
b.pinMode(button_down, b.INPUT, 7, 'pullup');
b.pinMode(button_reset, b.INPUT, 7, 'pullup');

b.attachInterrupt(button_left, false, b.CHANGE, moveLeft);
b.attachInterrupt(button_up, false, b.CHANGE, moveUp);
b.attachInterrupt(button_right, false, b.CHANGE, moveRight);
b.attachInterrupt(button_down, false, b.CHANGE, moveDown);
b.attachInterrupt(button_reset, false, b.CHANGE, clear);

//print empty grid
for (i=0; i<size; i++){
	for (j=0; j<size; j++) {
		grid[i][j] = ' ';
	}
}

for (i=0; i<size; i++){
	console.log(grid[i]);
}
Ejemplo n.º 30
0
function attR(x){
    b.attachInterrupt(rightButton, true, b.RISING, goRight);
}