Added ability to reset absolute zero
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Nathan Kellenicki 2019-08-07 13:22:57 -07:00
parent 348037a2ab
commit 732c3626b5
13 changed files with 634 additions and 28 deletions

View File

@ -1257,7 +1257,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="boostmovehub.js.html">boostmovehub.js</a>, <a href="boostmovehub.js.html">boostmovehub.js</a>,
<a href="boostmovehub.js.html#sunlight-1-line-229">line 229</a> <a href="boostmovehub.js.html#sunlight-1-line-247">line 247</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2088,6 +2088,168 @@
</dd>
<hr>
<dt>
<h4 class="name" id="resetAbsolutePosition"><span class="type-signature"></span>resetAbsolutePosition(port)</h4>
</dt>
<dd>
<div class="description">
<p>Reset the current motor position as absolute position zero</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>port</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="boostmovehub.js.html">boostmovehub.js</a>,
<a href="boostmovehub.js.html#sunlight-1-line-229">line 229</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Resolved upon successful completion of command (ie. once the motor is finished).</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
</dd> </dd>
@ -2922,7 +3084,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="boostmovehub.js.html">boostmovehub.js</a>, <a href="boostmovehub.js.html">boostmovehub.js</a>,
<a href="boostmovehub.js.html#sunlight-1-line-238">line 238</a> <a href="boostmovehub.js.html#sunlight-1-line-256">line 256</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -1257,7 +1257,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="controlplushub.js.html">controlplushub.js</a>, <a href="controlplushub.js.html">controlplushub.js</a>,
<a href="controlplushub.js.html#sunlight-1-line-224">line 224</a> <a href="controlplushub.js.html#sunlight-1-line-242">line 242</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2088,6 +2088,168 @@
</dd>
<hr>
<dt>
<h4 class="name" id="resetAbsolutePosition"><span class="type-signature"></span>resetAbsolutePosition(port)</h4>
</dt>
<dd>
<div class="description">
<p>Reset the current motor position as absolute position zero</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>port</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="controlplushub.js.html">controlplushub.js</a>,
<a href="controlplushub.js.html#sunlight-1-line-224">line 224</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Resolved upon successful completion of command (ie. once the motor is finished).</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
</dd> </dd>
@ -2922,7 +3084,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="controlplushub.js.html">controlplushub.js</a>, <a href="controlplushub.js.html">controlplushub.js</a>,
<a href="controlplushub.js.html#sunlight-1-line-233">line 233</a> <a href="controlplushub.js.html#sunlight-1-line-251">line 251</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -1257,7 +1257,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="puphub.js.html">puphub.js</a>, <a href="puphub.js.html">puphub.js</a>,
<a href="puphub.js.html#sunlight-1-line-223">line 223</a> <a href="puphub.js.html#sunlight-1-line-241">line 241</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2088,6 +2088,168 @@
</dd>
<hr>
<dt>
<h4 class="name" id="resetAbsolutePosition"><span class="type-signature"></span>resetAbsolutePosition(port)</h4>
</dt>
<dd>
<div class="description">
<p>Reset the current motor position as absolute position zero</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>port</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="puphub.js.html">puphub.js</a>,
<a href="puphub.js.html#sunlight-1-line-223">line 223</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Resolved upon successful completion of command (ie. once the motor is finished).</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
</dd> </dd>
@ -2922,7 +3084,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="puphub.js.html">puphub.js</a>, <a href="puphub.js.html">puphub.js</a>,
<a href="puphub.js.html#sunlight-1-line-232">line 232</a> <a href="puphub.js.html#sunlight-1-line-250">line 250</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -298,13 +298,13 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} }
else { else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -312,6 +312,24 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
}; };
}); });
} }
/**
* Reset the current motor position as absolute position zero
* @method BoostMoveHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
resetAbsolutePosition(port) {
const portObj = this._portLookup(port);
if (!(portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method BoostMoveHub#brakeMotor * @method BoostMoveHub#brakeMotor

View File

@ -293,13 +293,13 @@ class ControlPlusHub extends lpf2hub_1.LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} }
else { else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -307,6 +307,24 @@ class ControlPlusHub extends lpf2hub_1.LPF2Hub {
}; };
}); });
} }
/**
* Reset the current motor position as absolute position zero
* @method ControlPlusHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
resetAbsolutePosition(port) {
const portObj = this._portLookup(port);
if (!(portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method ControlPlusHub#brakeMotor * @method ControlPlusHub#brakeMotor

View File

@ -534,7 +534,7 @@ class LPF2Hub extends hub_1.Hub {
* @param {number} y * @param {number} y
* @param {number} z (Only available when using a Control+ Hub) * @param {number} z (Only available when using a Control+ Hub)
*/ */
this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY, this._lastTiltY); this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY, this._lastTiltZ);
break; break;
} }
case Consts.DeviceType.BOOST_TACHO_MOTOR: { case Consts.DeviceType.BOOST_TACHO_MOTOR: {

View File

@ -292,13 +292,13 @@ class PUPHub extends lpf2hub_1.LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} }
else { else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -306,6 +306,24 @@ class PUPHub extends lpf2hub_1.LPF2Hub {
}; };
}); });
} }
/**
* Reset the current motor position as absolute position zero
* @method PUPHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
resetAbsolutePosition(port) {
const portObj = this._portLookup(port);
if (!(portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method PUPHub#brakeMotor * @method PUPHub#brakeMotor

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "3.3.0", "version": "3.4.0",
"description": "A Javascript module to interface with LEGO Powered Up components.", "description": "A Javascript module to interface with LEGO Powered Up components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/", "homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/node/index-node.js", "main": "dist/node/index-node.js",

View File

@ -227,12 +227,12 @@ export class BoostMoveHub extends LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} else { } else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -242,6 +242,28 @@ export class BoostMoveHub extends LPF2Hub {
} }
/**
* Reset the current motor position as absolute position zero
* @method BoostMoveHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
public resetAbsolutePosition (port: string) {
const portObj = this._portLookup(port);
if (!(
portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method BoostMoveHub#brakeMotor * @method BoostMoveHub#brakeMotor

View File

@ -225,12 +225,12 @@ export class ControlPlusHub extends LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} else { } else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -240,6 +240,28 @@ export class ControlPlusHub extends LPF2Hub {
} }
/**
* Reset the current motor position as absolute position zero
* @method ControlPlusHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
public resetAbsolutePosition (port: string) {
const portObj = this._portLookup(port);
if (!(
portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method ControlPlusHub#brakeMotor * @method ControlPlusHub#brakeMotor

View File

@ -508,7 +508,7 @@ export class LPF2Hub extends Hub {
* @param {number} y * @param {number} y
* @param {number} z (Only available when using a Control+ Hub) * @param {number} z (Only available when using a Control+ Hub)
*/ */
this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY, this._lastTiltY); this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY, this._lastTiltZ);
break; break;
} }
case Consts.DeviceType.BOOST_TACHO_MOTOR: { case Consts.DeviceType.BOOST_TACHO_MOTOR: {

View File

@ -219,12 +219,12 @@ export class PUPHub extends LPF2Hub {
let data = null; let data = null;
if (this._virtualPorts[portObj.id]) { if (this._virtualPorts[portObj.id]) {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
data.writeUInt32LE(pos, 8); data.writeInt32LE(pos, 8);
} else { } else {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
data.writeUInt32LE(pos, 4); data.writeInt32LE(pos, 4);
} }
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
@ -234,6 +234,28 @@ export class PUPHub extends LPF2Hub {
} }
/**
* Reset the current motor position as absolute position zero
* @method PUPHub#resetAbsolutePosition
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
public resetAbsolutePosition (port: string) {
const portObj = this._portLookup(port);
if (!(
portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
)) {
throw new Error("Absolute positioning is only available when using a Control+ Medium Motor, or Control+ Large Motor");
}
return new Promise((resolve) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/** /**
* Fully (hard) stop the motor on a given port. * Fully (hard) stop the motor on a given port.
* @method PUPHub#brakeMotor * @method PUPHub#brakeMotor