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(); };
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); };
LCD.prototype.home = function(callback) { this._sendCommand(RETURNHOME); Cylon.Utils.sleep(2); if (typeof callback === "function") { callback(); } };
LCD.prototype.clear = function(callback) { this._sendCommand(CLEARDISPLAY); Cylon.Utils.sleep(2); if (typeof callback === "function") { callback(); } };
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)); };
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) ); };
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));
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); }); } };
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
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
* * @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(); };
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
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(); };
"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();
* * @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) {
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(); };
"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)); }
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
* @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(); };
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));
* 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;
"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) {
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); }
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) {
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); });
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);
/** * 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
* 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) //
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);
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) {