UNPKG

timeline-state-resolver

Version:
438 lines • 14.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FocusPositionQuery = exports.FocusPositionControl = exports.OneTouchFocusControl = exports.AutoFocusOnOffQuery = exports.AutoFocusOnOffControl = exports.FocusSpeedControl = exports.ZoomPositionQuery = exports.ZoomPositionControl = exports.ZoomSpeedQuery = exports.ZoomSpeedControl = exports.PanTiltPositionQuery = exports.PanTiltPositionControl = exports.PanTiltSpeedControl = exports.PresetSpeedQuery = exports.PresetSpeedControl = exports.PresetNumberQuery = exports.PresetDeleteControl = exports.PresetPlaybackControl = exports.PresetRegisterControl = exports.PowerModeQuery = exports.PowerMode = exports.InvalidResponseError = void 0; const sprintf_js_1 = require("sprintf-js"); const _ = require("underscore"); const connection_1 = require("./connection"); class InvalidResponseError extends Error { constructor(response) { super(`Invalid response: ${response}`); this.response = response; } } exports.InvalidResponseError = InvalidResponseError; var PowerMode; (function (PowerMode) { PowerMode["POWER_MODE_ON"] = "p1"; PowerMode["POWER_MODE_STBY"] = "p0"; PowerMode["POWER_MODE_TURNING_ON"] = "p3"; })(PowerMode = exports.PowerMode || (exports.PowerMode = {})); class PowerModeQuery { serialize() { return '#O'; } deserializeResponse(response) { switch (response) { case 'p1': return PowerMode.POWER_MODE_ON; case 'p0': return PowerMode.POWER_MODE_STBY; case 'p3': return PowerMode.POWER_MODE_TURNING_ON; default: throw new InvalidResponseError(response); } } } exports.PowerModeQuery = PowerModeQuery; /** * Store camera preset */ class PresetRegisterControl { /** * @param presetNumber The preset to be stored. 0-99 */ constructor(presetNumber) { this.presetNumber = presetNumber; validatePresetNumber(presetNumber); } serialize() { return (0, sprintf_js_1.sprintf)('#M%02i', this.presetNumber); } deserializeResponse(response) { if (response.startsWith('s')) { return parseInt(response.slice(1), 10); } throw new InvalidResponseError(response); } } exports.PresetRegisterControl = PresetRegisterControl; /** * Recall camera preset */ class PresetPlaybackControl { /** * @param presetNumber The preset to be recalled. 0-99 */ constructor(presetNumber) { this.presetNumber = presetNumber; validatePresetNumber(presetNumber); } serialize() { return (0, sprintf_js_1.sprintf)('#R%02i', this.presetNumber); } deserializeResponse(response) { if (response.startsWith('s')) { return parseInt(response.slice(1), 10); } throw new InvalidResponseError(response); } } exports.PresetPlaybackControl = PresetPlaybackControl; /** * Reset camera preset */ class PresetDeleteControl { /** * @param presetNumber The preset to be reset. 0-99 */ constructor(presetNumber) { this.presetNumber = presetNumber; validatePresetNumber(presetNumber); } serialize() { return (0, sprintf_js_1.sprintf)('#C%02i', this.presetNumber); } deserializeResponse(response) { if (response.startsWith('s')) { return parseInt(response.slice(1), 10); } throw new InvalidResponseError(response); } } exports.PresetDeleteControl = PresetDeleteControl; function validatePresetNumber(preset) { if (!_.isFinite(preset)) throw new Error('Camera preset is not a finite number'); if (preset < 0 || preset > 99) throw new Error('Illegal preset number'); } /** * Get the last preset recalled in the camera */ class PresetNumberQuery { serialize() { return '#S'; } deserializeResponse(response) { if (response.startsWith('s')) { return parseInt(response.slice(1), 10); } throw new InvalidResponseError(response); } } exports.PresetNumberQuery = PresetNumberQuery; /** * Set camera preset recall speed, within speed table */ class PresetSpeedControl { /** * @param speed Speed to be set for the camera preset recall. 250-999 or 0. 0 is maximum speed */ constructor(speed) { this.speed = speed; if (!_.isFinite(speed)) throw new Error('Camera speed preset is not a finite number'); if ((speed < 250 || speed > 999) && speed !== 0) throw new Error('Camera speed must be between 250 and 999 or needs to be 0'); } serialize() { return (0, sprintf_js_1.sprintf)('#UPVS%03i', this.speed); } deserializeResponse(response) { if (response.startsWith('uPVS')) { return parseInt(response.slice(4), 10); } throw new InvalidResponseError(response); } } exports.PresetSpeedControl = PresetSpeedControl; /** * Get camera preset recall speed, within speed table */ class PresetSpeedQuery { serialize() { return '#UPVS'; } deserializeResponse(response) { if (response.startsWith('uPVS')) { return parseInt(response.slice(4), 10); } throw new InvalidResponseError(response); } } exports.PresetSpeedQuery = PresetSpeedQuery; /** * Set camera pan and tilt speed (essentially, current virtual joystick position) */ class PanTiltSpeedControl { /** * @param panSpeed Acceptable values are 1-99. 50 is pan stop, 49 is slowest LEFT, 51 is slowest RIGHT, 1 is fastest LEFT, 99 is fastest RIGHT * @param tiltSpeed Acceptable values are 1-99. 50 is tilt stop, 49 is slowest DOWN, 51 is slowest UP, 1 is fastest DOWN, 99 is fastest UP */ constructor(panSpeed, tiltSpeed) { this.panSpeed = panSpeed; this.tiltSpeed = tiltSpeed; if (!_.isFinite(panSpeed)) throw new Error('Camera pan speed is not a finite number'); if (panSpeed < 1 || panSpeed > 99) throw new Error('Camera pan speed must be between 1 and 99'); if (!_.isFinite(tiltSpeed)) throw new Error('Camera tilt speed is not a finite number'); if (tiltSpeed < 1 || tiltSpeed > 99) throw new Error('Camera tilt speed must be between 1 and 99'); } serialize() { return (0, sprintf_js_1.sprintf)('#PTS%02i%02i', this.panSpeed, this.tiltSpeed); } deserializeResponse(response) { if (response.startsWith('pTS')) { return { panSpeed: parseInt(response.slice(3, 5), 10), tiltSpeed: parseInt(response.slice(5), 10) }; } throw new InvalidResponseError(response); } } exports.PanTiltSpeedControl = PanTiltSpeedControl; /** * Set absolute camera pan and tilt position */ class PanTiltPositionControl { /** * @param panPosition * @param tiltPosition */ constructor(panPosition, tiltPosition) { this.panPosition = panPosition; this.tiltPosition = tiltPosition; if (!_.isFinite(panPosition)) throw new Error('Camera pan position is not a finite number'); if (panPosition < 0 || panPosition > 0xffff) throw new Error('Camera pan position must be between 0 and 65535'); if (!_.isFinite(tiltPosition)) throw new Error('Camera tilt speed is not a finite number'); if (tiltPosition < 0 || tiltPosition > 0xffff) throw new Error('Camera tilt speed must be between 0 and 65535'); } serialize() { return (0, sprintf_js_1.sprintf)('#APC%04x%04x', this.panPosition, this.tiltPosition); } deserializeResponse(response) { if (response.startsWith('aPC')) { return { panPosition: parseInt(response.slice(3, 7), 16), tiltPosition: parseInt(response.slice(7), 16) }; } throw new InvalidResponseError(response); } } exports.PanTiltPositionControl = PanTiltPositionControl; /** * Get absolute camera pan and tilt position */ class PanTiltPositionQuery { serialize() { return '#APC'; } deserializeResponse(response) { if (response.startsWith('aPC')) { return { panPosition: parseInt(response.slice(3, 7), 16), tiltPosition: parseInt(response.slice(7), 16) }; } throw new InvalidResponseError(response); } } exports.PanTiltPositionQuery = PanTiltPositionQuery; /** * Set camera lens zoom speed (essentially, current virtual zoom rocker position) */ class ZoomSpeedControl { /** * @param speed Speed to be set for the camera zoom. Acceptable values are 1-99. 50 is zoom stop, 49 is slowest WIDE, 51 is slowest TELE, 1 is fastest WIDE, 99 is fastest TELE */ constructor(speed) { this.speed = speed; if (!_.isFinite(speed)) throw new Error('Camera zoom speed is not a finite number'); if (speed < 1 || speed > 99) throw new Error('Camera zoom speed must be between 1 and 99'); } serialize() { return (0, sprintf_js_1.sprintf)('#Z%02i', this.speed); } deserializeResponse(response) { if (response.startsWith('zS')) { return parseInt(response.slice(2), 10); } throw new InvalidResponseError(response); } } exports.ZoomSpeedControl = ZoomSpeedControl; /** * Get camera lens zoom speed (essentially, current virtual zoom rocker position) */ class ZoomSpeedQuery { serialize() { return '#Z'; } deserializeResponse(response) { if (response.startsWith('zS')) { return parseInt(response.slice(2), 10); } throw new InvalidResponseError(response); } } exports.ZoomSpeedQuery = ZoomSpeedQuery; /** * Set camera lens zoom (an absolute number) */ class ZoomPositionControl { /** * @param position Absolute zoom position to be set. Range: 0x555 (WIDE) - 0xfff (TELE) */ constructor(position) { this.position = position; if (!_.isFinite(position)) throw new Error('Camera zoom position is not a finite number'); if (position < 0x555 || position > 0xfff) throw new Error('Camera zoom position must be between 1365 and 4095'); } serialize() { return (0, sprintf_js_1.sprintf)('#AXZ%03X', this.position); } deserializeResponse(response) { if (response.startsWith('axz')) { return parseInt(response.slice(3), 16); } throw new InvalidResponseError(response); } } exports.ZoomPositionControl = ZoomPositionControl; /** * Get camera lens zoom (an absolute number) */ class ZoomPositionQuery { serialize() { return '#GZ'; } deserializeResponse(response) { if (response.startsWith('gz')) { return parseInt(response.slice(2), 16); } throw new InvalidResponseError(response); } } exports.ZoomPositionQuery = ZoomPositionQuery; /** * Set camera focus speed */ class FocusSpeedControl { /** * @param speed Speed to be set for the camera focus. Acceptable values are 1-99. 50 is focus stop, 49 is slowest NEAR, 51 is slowest FAR, 1 is fastest NEAR, 99 is fastest FAR */ constructor(speed) { this.speed = speed; if (!_.isFinite(speed)) throw new Error('Camera focus speed is not a finite number'); if (speed < 1 || speed > 99) throw new Error('Camera focus speed must be between 1 and 99'); } serialize() { return (0, sprintf_js_1.sprintf)('#F%02i', this.speed); } deserializeResponse(response) { if (response.startsWith('fS')) { return parseInt(response.slice(2), 10); } throw new InvalidResponseError(response); } } exports.FocusSpeedControl = FocusSpeedControl; /** * Set camera focus mode (AUTO/MANUAL) */ class AutoFocusOnOffControl { /** * @param mode Mode to be set for the camera focus */ constructor(mode) { this.mode = mode; } serialize() { return (0, sprintf_js_1.sprintf)('#D1%d', this.mode); } deserializeResponse(response) { if (response.startsWith('d1')) { return response.slice(2) === '1' ? connection_1.PanasonicFocusMode.AUTO : connection_1.PanasonicFocusMode.MANUAL; } throw new InvalidResponseError(response); } } exports.AutoFocusOnOffControl = AutoFocusOnOffControl; /** * Get camera focus mode (AUTO/MANUAL) */ class AutoFocusOnOffQuery { serialize() { return (0, sprintf_js_1.sprintf)('#D1'); } deserializeResponse(response) { if (response.startsWith('d1')) { return response.slice(2) === '1' ? connection_1.PanasonicFocusMode.AUTO : connection_1.PanasonicFocusMode.MANUAL; } throw new InvalidResponseError(response); } } exports.AutoFocusOnOffQuery = AutoFocusOnOffQuery; /** * Trigger one-touch focus */ class OneTouchFocusControl { serialize() { return 'OSE:69:1'; } deserializeResponse(response) { if (response === 'OSE:69:1') { return; } throw new InvalidResponseError(response); } } exports.OneTouchFocusControl = OneTouchFocusControl; /** * Set camera focus distance (an absolute number) */ class FocusPositionControl { /** * @param position Absolute focus position to be set. Range: 0x555 (NEAR) - 0xfff (FAR) */ constructor(position) { this.position = position; if (!_.isFinite(position)) throw new Error('Camera focus position is not a finite number'); if (position < 0x555 || position > 0xfff) throw new Error('Camera focus position must be between 1365 and 4095'); } serialize() { return (0, sprintf_js_1.sprintf)('#AXF%03x', this.position); } deserializeResponse(response) { if (response.startsWith('axf')) { return parseInt(response.slice(3), 16); } throw new InvalidResponseError(response); } } exports.FocusPositionControl = FocusPositionControl; /** * Get camera focus distance (an absolute number) */ class FocusPositionQuery { serialize() { return '#GF'; } deserializeResponse(response) { if (response.startsWith('gf')) { return parseInt(response.slice(2), 16); } throw new InvalidResponseError(response); } } exports.FocusPositionQuery = FocusPositionQuery; //# sourceMappingURL=commands.js.map