diff --git a/wrappers/csharp/Intel.RealSense/Types/Enums/Extension.cs b/wrappers/csharp/Intel.RealSense/Types/Enums/Extension.cs index 36015afa2a..1453edab6d 100644 --- a/wrappers/csharp/Intel.RealSense/Types/Enums/Extension.cs +++ b/wrappers/csharp/Intel.RealSense/Types/Enums/Extension.cs @@ -47,5 +47,11 @@ public enum Extension GlobalTimer = 36, Updatable = 37, UpdateDevice = 38, + L500DepthSensor = 39, + TM2Sensor = 40, + AutoCalibratedDevice = 41, + ColorSensor = 42, + MotionSensor = 43, + FisheyeSensor = 44 } } diff --git a/wrappers/nodejs/index.js b/wrappers/nodejs/index.js index 4c31090d57..28f40ed202 100644 --- a/wrappers/nodejs/index.js +++ b/wrappers/nodejs/index.js @@ -50,9 +50,19 @@ class Device { const array = []; sensors.forEach((s) => { - if (s.isDepthSensor()) { + if (s.is(RS2.RS2_EXTENSION_DEPTH_SENSOR)) { array.push(new DepthSensor(s)); - } else { + } + else if (s.is(RS2.RS2_EXTENSION_COLOR_SENSOR)) { + array.push(new ColorSensor(s)); + } + else if (s.is(RS2.RS2_EXTENSION_MOTION_SENSOR)) { + array.push(new MotionSensor(s)); + } + else if (s.is(RS2.RS2_EXTENSION_FISHEYE_SENSOR)) { + array.push(new FisheyeSensor(s)); + } + else { array.push(new Sensor(s)); } }); @@ -1088,6 +1098,45 @@ class DepthSensor extends Sensor { } } +/** + * Color sensor + */ +class ColorSensor extends Sensor { + /** + * Construct a device object, representing a RealSense camera + */ + constructor(sensor) { + super(sensor); + } +} + + +/** + * Motion sensor + */ +class MotionSensor extends Sensor { + /** + * Construct a device object, representing a RealSense camera + */ + constructor(sensor) { + super(sensor); + } +} + + +/** + * Fisheye sensor + */ +class FisheyeSensor extends Sensor { + /** + * Construct a device object, representing a RealSense camera + */ + constructor(sensor) { + super(sensor); + } +} + + const internal = { ctx: [], objs: [], @@ -6418,6 +6467,9 @@ module.exports = { Sensor: Sensor, DepthSensor: DepthSensor, ROISensor: ROISensor, + ColorSensor: ColorSensor, + MotionSensor: MotionSensor, + FisheyeSensor: FisheyeSensor, StreamProfile: StreamProfile, VideoStreamProfile: VideoStreamProfile, MotionStreamProfile: MotionStreamProfile, diff --git a/wrappers/nodejs/src/addon.cpp b/wrappers/nodejs/src/addon.cpp index e490d4b1cc..b0157981d7 100644 --- a/wrappers/nodejs/src/addon.cpp +++ b/wrappers/nodejs/src/addon.cpp @@ -2026,8 +2026,8 @@ class RSSensor : public Nan::ObjectWrap, Options { Nan::SetPrototypeMethod(tpl, "setRegionOfInterest", SetRegionOfInterest); Nan::SetPrototypeMethod(tpl, "getRegionOfInterest", GetRegionOfInterest); Nan::SetPrototypeMethod(tpl, "getDepthScale", GetDepthScale); - Nan::SetPrototypeMethod(tpl, "isDepthSensor", IsDepthSensor); Nan::SetPrototypeMethod(tpl, "isROISensor", IsROISensor); + Nan::SetPrototypeMethod(tpl, "is", Is); constructor_.Reset(tpl->GetFunction()); exports->Set(Nan::New("RSSensor").ToLocalChecked(), tpl->GetFunction()); } @@ -2343,16 +2343,18 @@ class RSSensor : public Nan::ObjectWrap, Options { info.GetReturnValue().Set(Nan::New(scale)); } - static NAN_METHOD(IsDepthSensor) { + static NAN_METHOD(Is) { info.GetReturnValue().Set(Nan::Undefined()); + int32_t stype = info[0]->IntegerValue(); + auto me = Nan::ObjectWrap::Unwrap(info.Holder()); if (!me) return; - bool is_depth = GetNativeResult(rs2_is_sensor_extendable_to, - &me->error_, me->sensor_, RS2_EXTENSION_DEPTH_SENSOR, &me->error_); + bool is_ok = GetNativeResult(rs2_is_sensor_extendable_to, + &me->error_, me->sensor_, static_cast(stype), &me->error_); if (me->error_) return; - info.GetReturnValue().Set(Nan::New(is_depth)); + info.GetReturnValue().Set(Nan::New(is_ok)); } static NAN_METHOD(IsROISensor) { @@ -4784,6 +4786,56 @@ void InitModule(v8::Local exports) { _FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_PAUSED); _FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_STOPPED); _FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_COUNT); + + + // rs2_extension + _FORCE_SET_ENUM(RS2_EXTENSION_UNKNOWN); + _FORCE_SET_ENUM(RS2_EXTENSION_DEBUG); + _FORCE_SET_ENUM(RS2_EXTENSION_INFO); + _FORCE_SET_ENUM(RS2_EXTENSION_MOTION); + _FORCE_SET_ENUM(RS2_EXTENSION_OPTIONS); + _FORCE_SET_ENUM(RS2_EXTENSION_VIDEO); + _FORCE_SET_ENUM(RS2_EXTENSION_ROI); + _FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_VIDEO_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_MOTION_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_COMPOSITE_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_POINTS); + _FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_ADVANCED_MODE); + _FORCE_SET_ENUM(RS2_EXTENSION_RECORD); + _FORCE_SET_ENUM(RS2_EXTENSION_VIDEO_PROFILE); + _FORCE_SET_ENUM(RS2_EXTENSION_PLAYBACK); + _FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_STEREO_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_DISPARITY_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_MOTION_PROFILE); + _FORCE_SET_ENUM(RS2_EXTENSION_POSE_FRAME); + _FORCE_SET_ENUM(RS2_EXTENSION_POSE_PROFILE); + _FORCE_SET_ENUM(RS2_EXTENSION_TM2); + _FORCE_SET_ENUM(RS2_EXTENSION_SOFTWARE_DEVICE); + _FORCE_SET_ENUM(RS2_EXTENSION_SOFTWARE_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_DECIMATION_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_THRESHOLD_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_DISPARITY_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_SPATIAL_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_TEMPORAL_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_HOLE_FILLING_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_ZERO_ORDER_FILTER); + _FORCE_SET_ENUM(RS2_EXTENSION_RECOMMENDED_FILTERS); + _FORCE_SET_ENUM(RS2_EXTENSION_POSE); + _FORCE_SET_ENUM(RS2_EXTENSION_POSE_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_WHEEL_ODOMETER); + _FORCE_SET_ENUM(RS2_EXTENSION_GLOBAL_TIMER); + _FORCE_SET_ENUM(RS2_EXTENSION_UPDATABLE); + _FORCE_SET_ENUM(RS2_EXTENSION_UPDATE_DEVICE); + _FORCE_SET_ENUM(RS2_EXTENSION_L500_DEPTH_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_TM2_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_AUTO_CALIBRATED_DEVICE); + _FORCE_SET_ENUM(RS2_EXTENSION_COLOR_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_MOTION_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_FISHEYE_SENSOR); + _FORCE_SET_ENUM(RS2_EXTENSION_COUNT); + } NODE_MODULE(node_librealsense, InitModule); diff --git a/wrappers/nodejs/test/test-sensor-extensions.js b/wrappers/nodejs/test/test-sensor-extensions.js new file mode 100644 index 0000000000..e5e4481a5a --- /dev/null +++ b/wrappers/nodejs/test/test-sensor-extensions.js @@ -0,0 +1,109 @@ +// Copyright (c) 2017 Intel Corporation. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license +// that can be found in the LICENSE file. + +'use strict'; +/* global describe, it, before, after */ +const assert = require('assert'); +let rs2; +let pipeline; +try { + rs2 = require('node-librealsense'); +} catch (e) { + rs2 = require('../index.js'); +} + +let device; +let frameset; +let dev_info; +let motion_product_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01", "0B3A", "0B3D"]; +const ctx = new rs2.Context(); +let devices = ctx.queryDevices().devices; +assert(devices.length > 0); // Device must be connected +device = devices[0] +dev_info = device.getCameraInfo(); + + +describe('Sensor extensions test', function() { + before(function() { + // const ctx = new rs2.Context(); + // let devices = ctx.queryDevices().devices; + // assert(devices.length > 0); // Device must be connected + // device = devices[0] + // dev_info = device.getCameraInfo(); + }); + + after(function() { + rs2.cleanup(); + }); + + it('Testing constructor - 0 argument', () => { + assert.throws(() => { + new rs2.Align(); + }); + }); + + it('Testing ColorSensor extention', () => { + var products_list = ["0AA5, 0B48, 0AD3, 0AD4, 0AD5, 0B01, 0B07, 0B3A, 0B3D"]; + let rtn = device.getCameraInfo(); + if (products_list.includes(rtn.productId)) + { + const sensors = device.querySensors(); + let is_found = false; + for (let i = 0; i < sensors.length; i++) { + if (sensors[i] instanceof rs2.ColorSensor) { + const sensor = sensors[i]; + const profile = sensor.getStreamProfiles()[0]; + assert(profile.streamType === rs2.stream.STREAM_COLOR && profile.format == rs2.format.FORMAT_RGB8); + is_found = true; + } + } + assert(is_found); + } + }); + + it('Testing FisheyeSensor extention', () => { + var products_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01"]; + let rtn = device.getCameraInfo(); + if (products_list.includes(rtn.productId)) + { + const sensors = device.querySensors(); + let is_found = false; + for (let i = 0; i < sensors.length; i++) { + if (sensors[i] instanceof rs2.FisheyeSensor) { + const sensor = sensors[i]; + const profile = sensor.getStreamProfiles()[0]; + assert(profile.streamType === rs2.stream.STREAM_COLOR && profile.format == rs2.format.FORMAT_RGB8); + is_found = true; + } + } + assert(is_found); + + } + }); + + if (motion_product_list.includes(dev_info.productId)) + { + it('Testing MotionSensor extention', () => { + var products_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01", "0B3A", "0B3D"]; + let rtn = device.getCameraInfo(); + if (products_list.includes(rtn.productId)) + { + const sensors = device.querySensors(); + let is_found = false; + for (let i = 0; i < sensors.length; i++) { + if (sensors[i] instanceof rs2.MotionSensor) { + const sensor = sensors[i]; + const profile = sensor.getStreamProfiles()[0]; + assert([rs2.stream.STREAM_GYRO, rs2.stream.STREAM_ACCEL].includes(profile.streamType)) + assert([rs2.format.FORMAT_MOTION_RAW, rs2.format.FORMAT_MOTION_XYZ32F].includes(profile.format)); + is_found = true; + } + } + assert(is_found); + + } + }); + }; + +});