{"size": 1430, "ext": "js", "max_stars_repo_path": "dev/node_modules/cylon-gpio/lib/continuous-servo.js", "max_stars_repo_name": "born2net/mediaArduino", "max_stars_repo_stars_event_min_datetime": "2015-01-03T23:47:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-03T09:51:28.000Z", "max_issues_repo_path": "dev/node_modules/cylon-gpio/lib/continuous-servo.js", "max_issues_repo_name": "rabah-bou/mediaArduino", "max_issues_repo_issues_event_min_datetime": "2019-12-09T10:42:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-09T10:42:09.000Z", "max_forks_repo_path": "dev/node_modules/cylon-gpio/lib/continuous-servo.js", "max_forks_repo_name": "rabah-bou/mediaArduino", "max_forks_repo_forks_event_min_datetime": "2015-01-22T02:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-23T14:16:44.000Z"}
{"max_stars_count": 53, "max_issues_count": 1, "max_forks_count": 35, "avg_line_length": 25.0877192982, "max_line_length": 80, "alphanum_fraction": 0.7167832168}
/*
 * Continuous Servo driver
 * http://cylonjs.com
 *
 * Copyright (c) 2013-2014 The Hybrid Group
 * Licensed under the Apache 2.0 license.
*/

"use strict";

var Cylon = require('cylon');

var ContinuousServo = module.exports = function ContinuousServo() {
  ContinuousServo.__super__.constructor.apply(this, arguments);
  this.pin = this.device.pin;
  this.angleValue = 0;

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

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

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

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

// Public: Stops the driver
//
// Returns null.
ContinuousServo.prototype.stop = function() {
  return this.connection.servoWrite(this.pin, 90);
};

// Public: Turns the servo to go clockwise, if the driver is continuous.
//
// Returns true | nil.
ContinuousServo.prototype.clockwise = function() {
  Cylon.Logger.debug("Servo on pin " + this.pin + " turning clockwise");
  return this.connection.servoWrite(this.pin, 180);
};

// Public: Turns the servo to go counter clockwise, if the driver is continuous.
//
// Returns true | nil.
ContinuousServo.prototype.counterClockwise = function() {
  Cylon.Logger.debug("Servo on pin " + this.pin + " turning counter clockwise");
  return this.connection.servoWrite(this.pin, 89);
};
