2014-10-16 06:54:13 +08:00
|
|
|
"use strict";
|
|
|
|
|
2015-06-09 22:21:03 +08:00
|
|
|
var Utils = lib("io/utils.js");
|
2014-10-16 06:54:13 +08:00
|
|
|
|
|
|
|
describe("IOUtils", function() {
|
|
|
|
describe("#periodAndDuty", function() {
|
|
|
|
var fn = Utils.periodAndDuty;
|
|
|
|
|
|
|
|
it("calculates values for PWM", function() {
|
|
|
|
var value = fn(0.5, 2000, null, null);
|
2014-12-16 01:37:52 +08:00
|
|
|
expect(value).to.be.eql({ period: 500000, duty: 250000 });
|
2014-10-16 06:54:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("calculates values for servos", function() {
|
2014-12-15 07:21:28 +08:00
|
|
|
var value = fn(0.5, 50, { min: 500, max: 2400 }, "high");
|
2014-12-16 01:37:52 +08:00
|
|
|
expect(value).to.be.eql({ duty: 1450000, period: 20000000 });
|
2014-10-16 06:54:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("calculates values for different polarities", function() {
|
2014-12-15 07:21:28 +08:00
|
|
|
var value = fn(0.5, 50, { min: 500, max: 2400 }, "low");
|
2014-12-16 01:37:52 +08:00
|
|
|
expect(value).to.be.eql({ duty: 18550000, period: 20000000 });
|
2014-10-16 06:54:13 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|