示例#1
0
LCD.prototype.start = function(callback) {
  Cylon.Utils.sleep(50);

  this._expanderWrite(this._backlightVal);
  Cylon.Utils.sleep(100);

  this._write4bits(0x03 << 4);
  Cylon.Utils.sleep(4);

  this._write4bits(0x03 << 4);
  Cylon.Utils.sleep(4);

  this._write4bits(0x03 << 4);
  this._write4bits(0x02 << 4);
  this._sendCommand(FUNCTIONSET | this._displayfunction);

  this.displayOn();
  this.clear();

  // Initialize to default text direction (for roman languages) & set the entry mode
  this._sendCommand(ENTRYMODESET | this._displaymode);
  this.home();

  every(0, function() {
    this._expanderWrite(this._backlightVal);
  }.bind(this));

  callback();
};
示例#2
0
LCD.prototype.start = function(callback) {
  Cylon.Utils.sleep(50);

  this._expanderWrite(this._backlightVal);
  Cylon.Utils.sleep(1000);

  this._write4bits(0x03 << 4);
  Cylon.Utils.sleep(4);

  this._write4bits(0x03 << 4);
  Cylon.Utils.sleep(4);

  this._write4bits(0x03 << 4);
  this._write4bits(0x02 << 4);
  this._sendCommand(FUNCTIONSET | this._displayfunction);

  this.displayOn();
  this.clear();

  // Initialize to default text direction (for roman languages) & set the entry mode
  this._sendCommand(ENTRYMODESET | this._displaymode);
  this.home();

  return LCD.__super__.start.apply(this, arguments);
};
示例#3
0
LCD.prototype.home = function(callback) {
  this._sendCommand(RETURNHOME);
  Cylon.Utils.sleep(2);
  if (typeof callback === "function") {
    callback();
  }
};
示例#4
0
LCD.prototype.clear = function(callback) {
  this._sendCommand(CLEARDISPLAY);
  Cylon.Utils.sleep(2);

  if (typeof callback === "function") {
    callback();
  }
};
示例#5
0
Tessel.prototype.analogRead = function(pin, callback) {
  var data, prev_data;

  data = null;
  prev_data = null;

  Cylon.Utils.every(0, function() {
    data = this._tesselPin(pin).read() * this._tesselPin(pin).resolution;

    if (data !== prev_data) {
      prev_data = data;
      callback(null, data);
    }
  }.bind(this));
};
示例#6
0
LIDARLite.prototype.distance = function(callback) {
  this.connection.i2cWrite(this.address, 
                           LIDARLite.RegisterMeasure, 
                           LIDARLite.MeasureValue);
  Cylon.Utils.sleep(20);

  this.connection.i2cRead(
    this.address,
    LIDARLite.RegisterHighLowB,
    2,
    function(err, data) {
      if ("function" === typeof(callback)) {
        callback(err, this.parseDistance(data));
      }
    }.bind(this)
  );
};
示例#7
0
    function(err, data) {
      var oldmode = data[0];
      var newmode = [(oldmode & 0x7F) | 0x10]; // sleep
      this.connection.i2cWrite(this.address, PCA9685.MODE1, newmode);

      this.connection.i2cWrite(
        this.address, PCA9685.PRESCALE, Math.floor(prescale)
      );

      this.connection.i2cWrite(this.address, PCA9685.MODE1, [oldmode]);

      Cylon.Utils.sleep(100);

      this.connection.i2cWrite(this.address, PCA9685.MODE1, [oldmode | 0x80]);

      if (typeof callback === "function") {
        callback(null, frequency);
      }
    }.bind(this));
示例#8
0
Tessel.prototype.digitalRead = function(pin, callback) {
  var data, prev_data;

  data = null;
  prev_data = null;

  if (pin !== "config") {
    Cylon.Utils.every(0, function() {
      data = this._tesselPin(pin).read();

      if (data !== prev_data) {
        prev_data = data;
        callback(data);
      }
    }.bind(this));
  } else {
    tessel.button.on("press", function() {
      callback(null, 1);
    });
    tessel.button.on("release", function() {
      callback(null, 0);
    });
  }
};
示例#9
0
var commands = [
  "digitalWrite", "digitalRead", "analogRead",
  "pwmWrite", "i2cRead", "i2cWrite"
];

var Tessel = module.exports = function Tessel() {
  Tessel.__super__.constructor.apply(this, arguments);

  this.i2cReady = false;
  this.i2cDevices = {};

  this.proxyMethods(commands, this.board, this);
};

Cylon.Utils.subclass(Tessel, Cylon.Adaptor);

/**
 * Connects to the Tessel
 *
 * @param {Function} callback to be triggered when connected
 * @return {void}
 */
Tessel.prototype.connect = function(callback) {
  callback();
};

/**
 * Disconnects from the Tessel
 *
 * @param {Function} callback to be triggered when disconnected
示例#10
0
  this.pwmScale = opts.pwmScale || { bottom: 0, top: 180 };
  this.pulseWidth = opts.pulseWidth || { min: 500, max: 2400 };

  if (this.pin == null) {
    throw new Error("No pin specified for Continuous Servo. Cannot proceed");
  }

  this.commands = {
    clockwise: this.clockwise,
    counter_clockwise: this.counterClockwise,
    stop: this.stop
  };
};

/** Subclasses the Cylon.Driver class */
Cylon.Utils.subclass(ContinuousServo, Cylon.Driver);

/**
 * Starts the Continuous Servo
 *
 * @param {Function} callback to be triggered when started
 * @return {null}
 */
ContinuousServo.prototype.start = function(callback) {
  callback();
};

/**
 * Stops the Continuous Servo
 *
 * @param {Function} callback to be triggered when stopped
示例#11
0
    *
    * @event digitalRead
    * @value val the value from the pin
    */
   "digitalRead",

   /**
    * Emitted when the Intel platform has written a value to a digital pin
    *
    * @event digitalWrite
    */
   "digitalWrite"
  ];
};

Cylon.Utils.subclass(Adaptor, Cylon.Adaptor);

Adaptor.prototype.commands = [
  "pins", "analogRead", "digitalRead", "digitalWrite", "pwmWrite",
  "servoWrite", "firmwareName", "i2cWrite", "i2cRead"
];

Adaptor.prototype.connect = function(callback) {
  this.connector = new GalileoIO();
  callback();
};

Adaptor.prototype.disconnect = function(callback) {
  callback();
};
示例#12
0
  this.lowerLimit = opts.lowerLimit || 0;
  this.analogVal = null;

  if (this.pin == null) {
    throw new Error("No pin specified for GATTSensor. Cannot proceed");
  }

  this.commands = {
    analog_read: this.analogRead
  };

  this.events = events;
};

/** Subclasses the Cylon.Driver class */
Cylon.Utils.subclass(GATTSensor, Cylon.Driver);

/**
 * Gets the current value from the GATTSensor
 *
 * @return {Number} the current `this.analogVal`
 * @publish
 */
GATTSensor.prototype.analogRead = function() {
  return this.analogVal;
};

/**
 * Starts the GATTSensor
 *
 * @param {Function} callback to be triggered when started
示例#13
0
    commands: require("./commands/Settings")
  },
  "speed-settings": {
    name: "SpeedSettings",
    commands: require("./commands/SpeedSettings")
  },
  "wifi-settings": {
    name: "WifiSettings",
    commands: require("./commands/WifiSettings")
  },
};

var bebopDevice = module.exports = function(opts) {
  bebopDevice.__super__.constructor.apply(this, arguments);

  this.driverName = opts.driver;
};

Cylon.Utils.subclass(bebopDevice, Cylon.Driver);

bebopDevice.prototype.start = function(callback) {
  this.setupCommands(bebopDevices[this.driverName].commands,
                     this.connection[bebopDevices[this.driverName].name]);

  callback();
};

bebopDevice.prototype.halt = function(callback) {
  callback();
};
示例#14
0
"use strict";

var Cylon = require("cylon");

var Central = module.exports = function Central(opts) {
  opts = opts || {};

  Central.__super__.constructor.apply(this, arguments);

  this.bleConnect = require("./noble");
  this.isConnected = false;
  this.uuid = opts.uuid ; // TODO: handle array of UUIDs
  this.connectedPeripherals = {};
};

Cylon.Utils.subclass(Central, Cylon.Adaptor);

/**
 * Connects to the BLE peripheral
 *
 * @param {Function} callback to be triggered when connected
 * @return {null}
 */
Central.prototype.connect = function(callback) {
  this.bleConnect.on("discover", function(peripheral) {
    if (peripheral.uuid === this.uuid) {
      var p = { peripheral: peripheral, connected: false };
      this.connectedPeripherals[peripheral.uuid] = p;

      this.bleConnect.stopScanning();
示例#15
0
 *
 * @constructor bmp180
 */
var Bmp180 = module.exports = function Bmp180() {
  Bmp180.__super__.constructor.apply(this, arguments);

  this.address = this.address || 0x77;

  this.commands = {
    get_pressure: this.getPressure,
    get_temperature: this.getTemperature,
    get_altitude: this.getAltitude
  };
};

Cylon.Utils.subclass(Bmp180, I2CDriver);

Bmp180.REGISTER_CALIBRATION = 0xAA;
Bmp180.REGISTER_CONTROL = 0xF4;
Bmp180.REGISTER_TEMPDATA = 0xF6;
Bmp180.REGISTER_PRESSUREDATA = 0xF6;
Bmp180.REGISTER_READTEMPCMD = 0x2E;
Bmp180.REGISTER_READPRESSURECMD = 0x34;

Bmp180.MODE_LOWRES = 0;
Bmp180.MODE_MEDIUMRES = 1;
Bmp180.MODE_HIGHRES = 2;
Bmp180.MODE_UHIGHRES = 3;

function waitTime(mode) {
  switch (mode) {
示例#16
0
var Utils = require("./utils");

var Thermostat = module.exports = function Thermostat(opts) {
  Thermostat.__super__.constructor.apply(this, arguments);

  this.deviceId = opts.deviceId;
  this.deviceKey = "devices/thermostats/" + this.deviceId;
  this.type = "Thermostat";

  this.commands = {
    read: this.read,
    write: this.write
  };
};

Cylon.Utils.subclass(Thermostat, Cylon.Driver);

Thermostat.prototype.start = function(callback) {
  this.connection.on("value", function(snapshoot) {
    this.thermostat = snapshoot.val().devices.thermostats[this.deviceId];
    Utils.setupCommands(Commands, this.thermostat, this);
    this.emit("status", this.thermostat);
  }.bind(this));

  callback();
};

Thermostat.prototype.halt = function(callback) {
  callback();
};
示例#17
0
"use strict";

var Cylon = require("cylon");

var fs = require("fs");

var Pin = require("./pin");

var PwmPin = module.exports = function PwmPin(opts) {
  this.pinNum = opts.pin;
  this.period = opts.period;
  this.connected = false;
  this.errCount = 0;
};

Cylon.Utils.subclass(PwmPin, Pin);

PwmPin.prototype.connect = function() {
  var am33xx;

  this.on("error", function(err) {
    err.count = ++this.errCount;

    if ((err.count < 10) && (err.code === "ENOENT") && (err.errno === 34)) {
      this.pwmWrite(this.duty);
    } else {
      this.emit("err", this.duty);
      this.removeAllListeners("error", function() {
        this.emit("err", this.duty);
      }.bind(this));
    }
示例#18
0
文件: motor.js 项目: Gumpty/Guylon
  if (this.pin == null) {
    throw new Error("No pin specified for Motor. Cannot proceed");
  }

  this.commands = {
    turn_on: this.turnOn,
    turn_off: this.turnOff,
    toggle: this.toggle,
    speed: this.speed,
    current_speed: this.currentSpeed
  };
};

/** Subclasses the Cylon.Driver class */
Cylon.Utils.subclass(Motor, Cylon.Driver);

/**
 * Starts the Motor
 *
 * @param {Function} callback to be triggered when started
 * @return {void}
 */
Motor.prototype.start = function(callback) {
  callback();
};

/**
 * Stops the Motor
 *
 * @param {Function} callback to be triggered when halted
示例#19
0
     * @event hand
     * @value data
     */
    "hand",

    /**
     * Emitted per frame when the Leap Motion sees a gesture
     *
     * @event gesture
     * @value data
     */
    "gesture"
  ];
};

Cylon.Utils.subclass(Driver, Cylon.Driver);

/**
 * Starts the driver
 *
 * @param {Function} callback to be triggered when started
 * @return {void}
 */
Driver.prototype.start = function(callback) {
  this.defineDriverEvent("frame");
  this.defineDriverEvent("hand");
  this.defineDriverEvent("gesture");

  callback();
};
示例#20
0
  this.model = opts.model || "lv";

  if (this.pin == null) {
    throw new Error("No pin specified for Maxbotix. Cannot proceed");
  }

  this.commands = {
    range: this.range,
    rangeCm: this.rangeCm
  };

  this.events = events;
};

/** Subclasses the Cylon.Driver class */
Cylon.Utils.subclass(Maxbotix, Cylon.Driver);

/**
 * Starts the Maxbotix
 *
 * @param {Function} callback to be triggered when started
 * @return {null}
 */
Maxbotix.prototype.start = function(callback) {
  Cylon.Logger.debug("Maxbotix on pin " + this.pin + " started");

  this.connection.analogRead(this.pin, function(err, readVal) {
    this.analogValue = readVal;
    this.emit("range", this.range());
    this.emit("rangeCm", this.rangeCm());
  }.bind(this));
示例#21
0
 * HMC5883L Driver
 *
 * @constructor hmc5883L
 */

var HMC5883L = module.exports = function HMC5883L() {
  HMC5883L.__super__.constructor.apply(this, arguments);
  this.address = this.address || 0x1E;

  this.commands = {
    getMag: this.getMag
    };
};


Cylon.Utils.subclass(HMC5883L, I2CDriver);

HMC5883L.ADDRESS = 0x1E;

HMC5883L.CONFIG_REG_A = 0x00;
HMC5883L.CONFIG_REG_B = 0x01;
HMC5883L.MODE_REG = 0x02;

HMC5883L.REG_OUT_X_MSB = 0x03;
HMC5883L.REG_OUT_X_LSB = 0x04;
HMC5883L.REG_OUT_Z_MSB = 0x05;
HMC5883L.REG_OUT_Z_LSB = 0x06;
HMC5883L.REG_OUT_Y_MSB = 0x07;
HMC5883L.REG_OUT_Y_LSB = 0x08;

示例#22
0
"use strict";

var fs = require("fs"),
    EventEmitter = require("events").EventEmitter;

var Cylon = require("cylon");

var CAPEMGR_DIR = "/sys/devices";

var Pin = module.exports = function Pin() {
};

Cylon.Utils.subclass(Pin, EventEmitter);

Pin.prototype._findFile = function(dirName, regex) {
  var files = fs.readdirSync(dirName);

  for (var i = 0; i < files.length; i++) {
    if (regex.test(files[i])) {
      return files[i];
    }
  }

  return null;
};

Pin.prototype._capemgrDir = function() {
  if (this.capemgrDir == null) {
    var capemgr = this._findFile(CAPEMGR_DIR, /^bone_capemgr\.\d+$/);

    if (capemgr != null) {
示例#23
0
    
    this.digitalVal = null;
    
    if (this.pin == null) {
        throw new Error("No pin specified for Digital Sensor. Cannot proceed");
    }
    
    this.commands = {
    digital_read: this.digitalRead
    };
    
    this.events = events;
};

/** Subclasses the Cylon.Driver class */
Cylon.Utils.subclass(DigitalSensor, Cylon.Driver);

/**
 * Gets the current value from the Analog Sensor
 *
 * @param {Function} [callback] invoked with `err, value` as args
 * @return {Number} the current sensor value
 * @publish
 */
DigitalSensor.prototype.digitalRead = function (callback) {
    var val = this.digitalVal;
    
    if (typeof callback === "function") {
        callback(null, val);
    }
    
示例#24
0
var GenericAccess = "1800",
    DeviceName = "2a00",
    Appearance = "2a01";

var BLEGenericAccess = module.exports = function BLEGenericAccess(opts) {
  BLEGenericAccess.__super__.constructor.apply(this, arguments);

  this.serviceId = opts.serviceId || GenericAccess;

  this.commands = {
    getDeviceName: this.getDeviceName,
    getAppearance: this.getAppearance
  };
};

Cylon.Utils.subclass(BLEGenericAccess, Driver);

/**
 * Gets the name of the BLE device
 *
 * @param {Function} callback to be triggered when data is read
 * @return {null}
 * @publish
 */
BLEGenericAccess.prototype.getDeviceName = function(callback) {
  this._getServiceCharacteristic(DeviceName, function(err, data) {
    if (err) {
      return callback(err);
    }

    if (data !== null) {
示例#25
0
var Driver = require("./driver");

var BatteryService = "180f",
    BatteryLevel = "2a19";

var BLEBatteryService = module.exports = function BLEBatteryService(opts) {
  BLEBatteryService.__super__.constructor.apply(this, arguments);

  this.serviceId = opts.serviceId || BatteryService;

  this.commands = {
    getBatteryLevel: this.getBatteryLevel
  };
};

Cylon.Utils.subclass(BLEBatteryService, Driver);

/**
 * Gets the current battery level of the BLE device
 *
 * @param {Function} callback to be triggered when battery data is read
 * @return {null}
 * @publish
 */
BLEBatteryService.prototype.getBatteryLevel = function(callback) {
  this._getServiceCharacteristic(BatteryLevel, function(err, data) {
    if (data !== null) {
      data = data.readUInt8(0);
    }
    callback(err, data);
  });
示例#26
0
    core: this.core,
    digitalRead: this.digitalRead,
    digitalWrite: this.digitalWrite,
    analogRead: this.analogRead,
    analogWrite: this.analogWrite,
    pwmWrite: this.pwmWrite,
    servoWrite: this.servoWrite,
    callFunction: this.callFunction,
    command: this.command,
    getVariable: this.getVariable,
    variable: this.variable,
    onEvent: this.onEvent
  };
};

Cylon.Utils.subclass(Spark, Cylon.Driver);

Spark.prototype.start = function(callback) {
  callback();
};

Spark.prototype.halt = function(callback) {
  callback();
};

Spark.prototype.core = function() {
  return this.connection.coreAttrs();
};

Spark.prototype.digitalRead = function(pin, callback) {
  this.connection.digitalRead(pin, callback);
示例#27
0
/**
 * A MPU6050 Driver
 *
 * @constructor mpu6050
 */
var Mpu6050 = module.exports = function Mpu6050() {
  Mpu6050.__super__.constructor.apply(this, arguments);
  this.address = 0x68; // DataSheet
  this.commands = {
    get_angular_velocity: this.getAngularVelocity,
    get_acceleration: this.getAcceleration,
    get_motion_and_temp: this.getMotionAndTemp
  };
};

Cylon.Utils.subclass(Mpu6050, Cylon.Driver);

/**
 * Starts the driver
 *
 * @param {Function} callback triggered when the driver is started
 * @return {null}
 */
Mpu6050.prototype.start = function(callback) {
  // setClockSource
  this.connection.i2cWrite(this.address, MPU6050_RA_PWR_MGMT_1);
  this.connection.i2cWrite(this.address, MPU6050_PWR1_CLKSEL_BIT);
  this.connection.i2cWrite(this.address, MPU6050_PWR1_CLKSEL_LENGTH);
  this.connection.i2cWrite(this.address, MPU6050_CLOCK_PLL_XGYRO);

  // setFullScaleGyroRange
示例#28
0
 * Copyright (c) 2013 The Hybrid Group
 * Licensed under the Apache 2.0 license.
*/

"use strict";

var Cylon = require('cylon');

var Commands = require('./commands');

var Flight = module.exports = function Flight() {
  Flight.__super__.constructor.apply(this, arguments);
  this.setupCommands(Commands);
};

Cylon.Utils.subclass(Flight, Cylon.Driver);

Flight.prototype.start = function(callback) {
  callback();
};

Flight.prototype.halt = function(callback) {
  callback();
};

Flight.prototype.hover = function() {
  return this.connection.stop();
};

// Public: Moves the drone forward by a specified interval (0-1)
//
示例#29
0
  this.pwmScale = opts.extraParams.pwmScale || { bottom: 0, top: 255 };


  this.commands = {
    is_on: this.isOn,

    turn_on: this.turnOn,
    turn_off: this.turnOff,
    toggle: this.toggle,

    brightness: this.brightness,
    current_brightness: this.currentBrightness
  };
};

Cylon.Utils.subclass(Led, Cylon.Driver);

Led.prototype.start = function(callback) {
  callback();
};

Led.prototype.halt = function(callback) {
  callback();
};

// Public: Turns LED on.
//
// Returns null.
Led.prototype.turnOn = function() {
  this.isHigh = true;
  this.connection.digitalWrite(this.pin, 1);
示例#30
0
  this.analogVal = 0;
  this.distanceCm = 0;
  this.distanceIn = 0;

  if (this.pin == null) {
    throw new Error("No pin specified for IR Range Sensor. Cannot proceed")
  }

  this.commands = {
    analog_read: this.analogRead,
    range_cm: this.rangeCm,
    range: this.range
  };
};

Cylon.Utils.subclass(IrRangeSensor, Cylon.Driver);

// Public: Starts the driver
//
// Returns null.
IrRangeSensor.prototype.start = function(callback) {
  this.connection.analogRead(this.pin, function(err, readVal) {
    this._calcDistances(readVal);
    this.emit('range', this.distanceIn);
    this.emit('rangeCm', this.distanceCm);
  }.bind(this));

  callback();
};

IrRangeSensor.prototype.halt = function(callback) {