Added ability to reset absolute zero
This commit is contained in:
parent
348037a2ab
commit
732c3626b5
@ -1257,7 +1257,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</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>
|
||||
|
||||
|
||||
@ -2922,7 +3084,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</dd>
|
||||
|
@ -1257,7 +1257,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</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>
|
||||
|
||||
|
||||
@ -2922,7 +3084,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</dd>
|
||||
|
166
docs/PUPHub.html
166
docs/PUPHub.html
@ -1257,7 +1257,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</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>
|
||||
|
||||
|
||||
@ -2922,7 +3084,7 @@
|
||||
<ul class="dummy">
|
||||
<li>
|
||||
<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>
|
||||
</ul>
|
||||
</dd>
|
||||
|
@ -298,13 +298,13 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
}
|
||||
else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method BoostMoveHub#brakeMotor
|
||||
|
@ -293,13 +293,13 @@ class ControlPlusHub extends lpf2hub_1.LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
}
|
||||
else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method ControlPlusHub#brakeMotor
|
||||
|
@ -534,7 +534,7 @@ class LPF2Hub extends hub_1.Hub {
|
||||
* @param {number} y
|
||||
* @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;
|
||||
}
|
||||
case Consts.DeviceType.BOOST_TACHO_MOTOR: {
|
||||
|
@ -292,13 +292,13 @@ class PUPHub extends lpf2hub_1.LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
}
|
||||
else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method PUPHub#brakeMotor
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0",
|
||||
"description": "A Javascript module to interface with LEGO Powered Up components.",
|
||||
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
|
||||
"main": "dist/node/index-node.js",
|
||||
|
@ -227,12 +227,12 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
} else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method BoostMoveHub#brakeMotor
|
||||
|
@ -225,12 +225,12 @@ export class ControlPlusHub extends LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
} else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method ControlPlusHub#brakeMotor
|
||||
|
@ -508,7 +508,7 @@ export class LPF2Hub extends Hub {
|
||||
* @param {number} y
|
||||
* @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;
|
||||
}
|
||||
case Consts.DeviceType.BOOST_TACHO_MOTOR: {
|
||||
|
@ -219,12 +219,12 @@ export class PUPHub extends LPF2Hub {
|
||||
let data = null;
|
||||
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.writeUInt32LE(pos, 4);
|
||||
data.writeUInt32LE(pos, 8);
|
||||
data.writeInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 8);
|
||||
} else {
|
||||
// @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.writeUInt32LE(pos, 4);
|
||||
data.writeInt32LE(pos, 4);
|
||||
}
|
||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
|
||||
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.
|
||||
* @method PUPHub#brakeMotor
|
||||
|
Loading…
x
Reference in New Issue
Block a user