[Application] Fixed path of getAppSharedURI
[platform/core/api/webapi-plugins.git] / src / sensor / sensor_api.js
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 var utils_ = xwalk.utils;
18 var privilege_ = utils_.privilege;
19 var validator_ = utils_.validator;
20 var converter_ = utils_.converter;
21 var T_ = utils_.type;
22 var types_ = validator_.Types;
23 var native_ = new utils_.NativeManager(extension);
24
25 // Enums
26 var SensorType = {
27     LIGHT: 'LIGHT',
28     MAGNETIC: 'MAGNETIC',
29     PRESSURE: 'PRESSURE',
30     PROXIMITY: 'PROXIMITY',
31     ULTRAVIOLET: 'ULTRAVIOLET',
32     HRM_RAW: 'HRM_RAW',
33     GRAVITY: 'GRAVITY',
34     GYROSCOPE: 'GYROSCOPE',
35     GYROSCOPE_ROTATION_VECTOR: 'GYROSCOPE_ROTATION_VECTOR',
36     LINEAR_ACCELERATION: 'LINEAR_ACCELERATION',
37     MAGNETIC_UNCALIBRATED: 'MAGNETIC_UNCALIBRATED',
38     GYROSCOPE_UNCALIBRATED: 'GYROSCOPE_UNCALIBRATED',
39     ACCELERATION: 'ACCELERATION'
40 };
41
42 var ProximityState = {
43     FAR: 'FAR',
44     NEAR: 'NEAR'
45 };
46
47 var MagneticSensorAccuracy = {
48     UNDEFINED: 'ACCURACY_UNDEFINED',
49     BAD: 'ACCURACY_BAD',
50     NORMAL: 'ACCURACY_NORMAL',
51     GOOD: 'ACCURACY_GOOD',
52     VERYGOOD: 'ACCURACY_VERYGOOD'
53 };
54
55 var SensorStates = {
56     NOT_STARTED: 0,
57     STARTING: 1,
58     STARTED: 2
59 };
60
61 // helper class for sensor listeners
62 var SensorListener = function(type, constructor) {
63     this.sensorType = type;
64     this.state = SensorStates.NOT_STARTED;
65     this.callback = undefined;
66     this.callbackInterval = undefined;
67     this.callbackBatchLatency = undefined;
68     this.constructor = constructor;
69 };
70
71 SensorListener.prototype.tryCall = function(object) {
72     if (this.callback) {
73         this.callback(new this.constructor(object));
74     }
75 };
76
77 SensorListener.prototype.start = function(successCallback, errorCallback) {
78     if (SensorStates.STARTED != this.state) {
79         // sensor not started
80         this.state = SensorStates.STARTING;
81         var thisObject = this;
82         native_.call('Sensor_start', { sensorType: thisObject.sensorType }, function(
83             result
84         ) {
85             if (native_.isFailure(result)) {
86                 thisObject.state = SensorStates.NOT_STARTED;
87                 if (!T_.isNullOrUndefined(errorCallback)) {
88                     errorCallback(native_.getErrorObject(result));
89                 }
90             } else {
91                 thisObject.state = SensorStates.STARTED;
92                 successCallback();
93             }
94         });
95     } else {
96         // sensor is already started - just call success callback
97         setTimeout(function() {
98             successCallback();
99         }, 0);
100     }
101 };
102
103 SensorListener.prototype.stop = function() {
104     if (SensorStates.NOT_STARTED != this.state) {
105         var result = native_.callSync('Sensor_stop', { sensorType: this.sensorType });
106         if (native_.isFailure(result)) {
107             throw native_.getErrorObject(result);
108         }
109         this.state = SensorStates.NOT_STARTED;
110     }
111 };
112
113 SensorListener.prototype.setListener = function(successCallback, interval, batchLatency) {
114     if (
115         !this.callback ||
116         this.callbackInterval != interval ||
117         this.callbackBatchLatency != batchLatency
118     ) {
119         //call platform only if there was no listener registered or parameters changed
120         var result = native_.callSync('Sensor_setChangeListener', {
121             sensorType: this.sensorType,
122             interval: interval,
123             batchLatency: batchLatency
124         });
125
126         if (native_.isFailure(result)) {
127             throw native_.getErrorObject(result);
128         }
129     }
130     this.callbackInterval = interval;
131     this.callbackBatchLatency = batchLatency;
132     this.callback = successCallback;
133 };
134
135 SensorListener.prototype.unsetListener = function() {
136     if (this.callback) {
137         //unregister in platform only if there is callback registered
138         this.callback = undefined;
139         var result = native_.callSync('Sensor_unsetChangeListener', {
140             sensorType: this.sensorType
141         });
142         if (native_.isFailure(result)) {
143             throw native_.getErrorObject(result);
144         }
145     }
146 };
147
148 SensorListener.prototype.getData = function(successCallback, errorCallback) {
149     var thisObj = this;
150     if (SensorStates.STARTED != this.state) {
151         setTimeout(function() {
152             if (!T_.isNullOrUndefined(errorCallback)) {
153                 errorCallback(
154                     new WebAPIException(
155                         WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
156                         'Service is not available.'
157                     )
158                 );
159             }
160         }, 0);
161     } else {
162         native_.call('Sensor_getData', { type: thisObj.sensorType }, function(result) {
163             if (native_.isFailure(result)) {
164                 if (!T_.isNullOrUndefined(errorCallback)) {
165                     errorCallback(native_.getErrorObject(result));
166                 }
167             } else {
168                 successCallback(new thisObj.constructor(result));
169             }
170         });
171     }
172 };
173
174 var _supportedSensors = [];
175 var _isChecked = false;
176 var _sensorListeners = {
177     LIGHT: {},
178     MAGNETIC: {},
179     PRESSURE: {},
180     PROXIMITY: {},
181     ULTRAVIOLET: {},
182     HRM_RAW: {},
183     GRAVITY: {},
184     GYROSCOPE: {},
185     GYROSCOPE_ROTATION_VECTOR: {},
186     LINEAR_ACCELERATION: {},
187     MAGNETIC_UNCALIBRATED: {},
188     GYROSCOPE_UNCALIBRATED: {},
189     ACCELERATION: {}
190 };
191
192 var errorWrapper = function(err) {
193     if (err.name === 'UnknownError') {
194         err = new WebAPIException(WebAPIException.ABORT_ERR, err.message);
195     }
196
197     native_.callIfPossible(this.errorCallback, err);
198 };
199
200 var _listener = function(object) {
201     if (object.sensorType.substring(0, 4) === 'LED_') {
202         object.sensorType = 'HRM_RAW';
203     }
204     _sensorListeners[object.sensorType].tryCall(object);
205 };
206
207 var SENSOR_CHANGED_LISTENER = 'SensorChangedListener';
208 native_.addListener(SENSOR_CHANGED_LISTENER, _listener);
209
210 function getAvailableSensors() {
211     var result = native_.callSync('SensorService_getAvailableSensors', {});
212     if (native_.isFailure(result)) {
213         throw native_.getErrorObject(result);
214     }
215     _supportedSensors = native_.getResultObject(result);
216     _isChecked = true;
217 }
218
219 function SensorService() {}
220
221 function getDefaultSensor() {
222     var args = validator_.validateArgs(arguments, [
223         {
224             name: 'type',
225             type: types_.ENUM,
226             values: T_.getValues(SensorType)
227         }
228     ]);
229
230     if (!_isChecked) {
231         getAvailableSensors();
232     }
233
234     var index = _supportedSensors.indexOf(args.type);
235     if (index === -1) {
236         throw new WebAPIException(WebAPIException.NOT_SUPPORTED_ERR, 'Not supported.');
237     } else if (_supportedSensors[index] === SensorType.LIGHT) {
238         return new LightSensor();
239     } else if (_supportedSensors[index] === SensorType.MAGNETIC) {
240         return new MagneticSensor();
241     } else if (_supportedSensors[index] === SensorType.PRESSURE) {
242         return new PressureSensor();
243     } else if (_supportedSensors[index] === SensorType.PROXIMITY) {
244         return new ProximitySensor();
245     } else if (_supportedSensors[index] === SensorType.ULTRAVIOLET) {
246         return new UltravioletSensor();
247     } else if (_supportedSensors[index] === SensorType.HRM_RAW) {
248         utils_.checkPrivilegeAccess(privilege_.HEALTHINFO);
249         return new HRMRawSensor();
250     } else if (_supportedSensors[index] === SensorType.GRAVITY) {
251         return new GravitySensor();
252     } else if (_supportedSensors[index] === SensorType.GYROSCOPE) {
253         return new GyroscopeSensor();
254     } else if (_supportedSensors[index] === SensorType.GYROSCOPE_ROTATION_VECTOR) {
255         return new GyroscopeRotationVectorSensor();
256     } else if (_supportedSensors[index] === SensorType.LINEAR_ACCELERATION) {
257         return new LinearAccelerationSensor();
258     } else if (_supportedSensors[index] === SensorType.MAGNETIC_UNCALIBRATED) {
259         return new MagneticUncalibratedSensor();
260     } else if (_supportedSensors[index] === SensorType.GYROSCOPE_UNCALIBRATED) {
261         return new GyroscopeUncalibratedSensor();
262     } else if (_supportedSensors[index] === SensorType.ACCELERATION) {
263         return new AccelerationSensor();
264     }
265 }
266
267 SensorService.prototype.getDefaultSensor = function() {
268     return getDefaultSensor.apply(this, arguments);
269 };
270
271 SensorService.prototype.getAvailableSensors = function() {
272     if (!_isChecked) {
273         getAvailableSensors();
274     }
275
276     return _supportedSensors.slice();
277 };
278
279 //////////////////////Sensor classes/////////////////////////////
280 //// Base Sensor class
281 var Sensor = function(type) {
282     Object.defineProperties(this, {
283         sensorType: { value: type, writable: false, enumerable: true }
284     });
285 };
286
287 Sensor.prototype.start = function() {
288     var args = validator_.validateArgs(arguments, [
289         {
290             name: 'successCallback',
291             type: types_.FUNCTION
292         },
293         {
294             name: 'errorCallback',
295             type: types_.FUNCTION,
296             optional: true,
297             nullable: true
298         }
299     ]);
300
301     _sensorListeners[this.sensorType].start(args.successCallback, args.errorCallback);
302 };
303
304 Sensor.prototype.stop = function() {
305     _sensorListeners[this.sensorType].stop();
306 };
307
308 Sensor.prototype.setChangeListener = function() {
309     var args = validator_.validateArgs(arguments, [
310         {
311             name: 'successCallback',
312             type: types_.FUNCTION
313         },
314         {
315             name: 'interval',
316             type: types_.LONG,
317             optional: true,
318             nullable: true
319         },
320         {
321             name: 'batchLatency',
322             type: types_.LONG,
323             optional: true,
324             nullable: false
325         }
326     ]);
327
328     var interval = args.interval || 100;
329     if (interval < 10 || interval > 1000) {
330         throw new WebAPIException(
331             WebAPIException.INVALID_VALUES_ERR,
332             'Interval should be in range [10, 1000] milliseconds.'
333         );
334     }
335
336     var batchLatency = args.batchLatency || 0;
337
338     _sensorListeners[this.sensorType].setListener(
339         args.successCallback,
340         interval,
341         batchLatency
342     );
343 };
344
345 Sensor.prototype.unsetChangeListener = function() {
346     _sensorListeners[this.sensorType].unsetListener();
347 };
348
349 Sensor.prototype.getSensorHardwareInfo = function() {
350     var args = validator_.validateArgs(arguments, [
351         {
352             name: 'successCallback',
353             type: types_.FUNCTION
354         },
355         {
356             name: 'errorCallback',
357             type: types_.FUNCTION,
358             optional: true,
359             nullable: true
360         }
361     ]);
362
363     var callback = function(result) {
364         if (native_.isFailure(result)) {
365             if (!T_.isNullOrUndefined(errorCallback)) {
366                 errorCallback(native_.getErrorObject(result));
367             }
368         } else {
369             args.successCallback(new SensorHardwareInfo(result));
370         }
371     };
372
373     var result = native_.call(
374         'Sensor_getSensorHardwareInfo',
375         { type: this.sensorType },
376         callback
377     );
378 };
379
380 //// LightSensor
381 var LightSensor = function(data) {
382     Sensor.call(this, SensorType.LIGHT);
383 };
384
385 LightSensor.prototype = new Sensor();
386
387 LightSensor.prototype.constructor = Sensor;
388
389 LightSensor.prototype.getLightSensorData = function() {
390     var args = validator_.validateArgs(arguments, [
391         {
392             name: 'successCallback',
393             type: types_.FUNCTION
394         },
395         {
396             name: 'errorCallback',
397             type: types_.FUNCTION,
398             optional: true,
399             nullable: true
400         }
401     ]);
402
403     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
404 };
405
406 //// MagneticSensor
407 var MagneticSensor = function(data) {
408     Sensor.call(this, SensorType.MAGNETIC);
409 };
410
411 MagneticSensor.prototype = new Sensor();
412
413 MagneticSensor.prototype.constructor = Sensor;
414
415 MagneticSensor.prototype.getMagneticSensorData = function() {
416     var args = validator_.validateArgs(arguments, [
417         {
418             name: 'successCallback',
419             type: types_.FUNCTION
420         },
421         {
422             name: 'errorCallback',
423             type: types_.FUNCTION,
424             optional: true,
425             nullable: true
426         }
427     ]);
428
429     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
430 };
431
432 //// PressureSensor
433 var PressureSensor = function(data) {
434     Sensor.call(this, SensorType.PRESSURE);
435 };
436
437 PressureSensor.prototype = new Sensor();
438
439 PressureSensor.prototype.constructor = Sensor;
440
441 PressureSensor.prototype.getPressureSensorData = function() {
442     var args = validator_.validateArgs(arguments, [
443         {
444             name: 'successCallback',
445             type: types_.FUNCTION
446         },
447         {
448             name: 'errorCallback',
449             type: types_.FUNCTION,
450             optional: true,
451             nullable: true
452         }
453     ]);
454
455     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
456 };
457
458 //// ProximitySensor
459 var ProximitySensor = function(data) {
460     Sensor.call(this, SensorType.PROXIMITY);
461 };
462
463 ProximitySensor.prototype = new Sensor();
464
465 ProximitySensor.prototype.constructor = Sensor;
466
467 ProximitySensor.prototype.getProximitySensorData = function() {
468     var args = validator_.validateArgs(arguments, [
469         {
470             name: 'successCallback',
471             type: types_.FUNCTION
472         },
473         {
474             name: 'errorCallback',
475             type: types_.FUNCTION,
476             optional: true,
477             nullable: true
478         }
479     ]);
480
481     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
482 };
483
484 //// UltravioletSensor
485 var UltravioletSensor = function(data) {
486     Sensor.call(this, SensorType.ULTRAVIOLET);
487 };
488
489 UltravioletSensor.prototype = new Sensor();
490
491 UltravioletSensor.prototype.constructor = Sensor;
492
493 UltravioletSensor.prototype.getUltravioletSensorData = function() {
494     var args = validator_.validateArgs(arguments, [
495         {
496             name: 'successCallback',
497             type: types_.FUNCTION
498         },
499         {
500             name: 'errorCallback',
501             type: types_.FUNCTION,
502             optional: true,
503             nullable: true
504         }
505     ]);
506
507     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
508 };
509
510 ////HRMRawSensor
511 var HRMRawSensor = function(data) {
512     Sensor.call(this, SensorType.HRM_RAW);
513 };
514
515 HRMRawSensor.prototype = new Sensor();
516
517 HRMRawSensor.prototype.constructor = Sensor;
518
519 function getHRMRawSensorData() {
520     var args = validator_.validateArgs(arguments, [
521         {
522             name: 'successCallback',
523             type: types_.FUNCTION
524         },
525         {
526             name: 'errorCallback',
527             type: types_.FUNCTION,
528             optional: true,
529             nullable: true
530         }
531     ]);
532
533     utils_.checkPrivilegeAccess(privilege_.HEALTHINFO);
534
535     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
536 }
537
538 HRMRawSensor.prototype.getHRMRawSensorData = function() {
539     getHRMRawSensorData.apply(this, arguments);
540 };
541
542 //// GravitySensor
543 var GravitySensor = function(data) {
544     Sensor.call(this, SensorType.GRAVITY);
545 };
546
547 GravitySensor.prototype = new Sensor();
548
549 GravitySensor.prototype.constructor = Sensor;
550
551 GravitySensor.prototype.getGravitySensorData = function() {
552     var args = validator_.validateArgs(arguments, [
553         {
554             name: 'successCallback',
555             type: types_.FUNCTION
556         },
557         {
558             name: 'errorCallback',
559             type: types_.FUNCTION,
560             optional: true,
561             nullable: true
562         }
563     ]);
564
565     _sensorListeners[this.sensorType].getData(
566         args.successCallback,
567         errorWrapper.bind(args)
568     );
569 };
570
571 //// GyroscopeSensor
572 var GyroscopeSensor = function(data) {
573     Sensor.call(this, SensorType.GYROSCOPE);
574 };
575
576 GyroscopeSensor.prototype = new Sensor();
577
578 GyroscopeSensor.prototype.constructor = Sensor;
579
580 GyroscopeSensor.prototype.getGyroscopeSensorData = function() {
581     var args = validator_.validateArgs(arguments, [
582         {
583             name: 'successCallback',
584             type: types_.FUNCTION
585         },
586         {
587             name: 'errorCallback',
588             type: types_.FUNCTION,
589             optional: true,
590             nullable: true
591         }
592     ]);
593
594     _sensorListeners[this.sensorType].getData(
595         args.successCallback,
596         errorWrapper.bind(args)
597     );
598 };
599
600 //// GyroscopeRotationVectorSensor
601 var GyroscopeRotationVectorSensor = function(data) {
602     Sensor.call(this, SensorType.GYROSCOPE_ROTATION_VECTOR);
603 };
604
605 GyroscopeRotationVectorSensor.prototype = new Sensor();
606
607 GyroscopeRotationVectorSensor.prototype.constructor = Sensor;
608 // prettier-ignore
609 GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData =
610 function() {
611     var args = validator_.validateArgs(arguments, [
612         {
613             name: 'successCallback',
614             type: types_.FUNCTION
615         },
616         {
617             name: 'errorCallback',
618             type: types_.FUNCTION,
619             optional: true,
620             nullable: true
621         }
622     ]);
623
624     _sensorListeners[this.sensorType].getData(
625         args.successCallback,
626         errorWrapper.bind(args)
627     );
628 };
629
630 //// LinearAccelerationSensor
631 var LinearAccelerationSensor = function(data) {
632     Sensor.call(this, SensorType.LINEAR_ACCELERATION);
633 };
634
635 LinearAccelerationSensor.prototype = new Sensor();
636
637 LinearAccelerationSensor.prototype.constructor = Sensor;
638
639 LinearAccelerationSensor.prototype.getLinearAccelerationSensorData = function() {
640     var args = validator_.validateArgs(arguments, [
641         {
642             name: 'successCallback',
643             type: types_.FUNCTION
644         },
645         {
646             name: 'errorCallback',
647             type: types_.FUNCTION,
648             optional: true,
649             nullable: true
650         }
651     ]);
652
653     _sensorListeners[this.sensorType].getData(
654         args.successCallback,
655         errorWrapper.bind(args)
656     );
657 };
658
659 //// MagneticUncalibratedSensor
660 var MagneticUncalibratedSensor = function(data) {
661     Sensor.call(this, SensorType.MAGNETIC_UNCALIBRATED);
662 };
663
664 MagneticUncalibratedSensor.prototype = new Sensor();
665
666 MagneticUncalibratedSensor.prototype.constructor = Sensor;
667
668 MagneticUncalibratedSensor.prototype.getMagneticUncalibratedSensorData = function() {
669     var args = validator_.validateArgs(arguments, [
670         {
671             name: 'successCallback',
672             type: types_.FUNCTION
673         },
674         {
675             name: 'errorCallback',
676             type: types_.FUNCTION,
677             optional: true,
678             nullable: true
679         }
680     ]);
681
682     _sensorListeners[this.sensorType].getData(
683         args.successCallback,
684         errorWrapper.bind(args)
685     );
686 };
687
688 //// GyroscopeUncalibratedSensor
689 var GyroscopeUncalibratedSensor = function(data) {
690     Sensor.call(this, SensorType.GYROSCOPE_UNCALIBRATED);
691 };
692
693 GyroscopeUncalibratedSensor.prototype = new Sensor();
694
695 GyroscopeUncalibratedSensor.prototype.constructor = Sensor;
696
697 GyroscopeUncalibratedSensor.prototype.getGyroscopeUncalibratedSensorData = function() {
698     var args = validator_.validateArgs(arguments, [
699         {
700             name: 'successCallback',
701             type: types_.FUNCTION
702         },
703         {
704             name: 'errorCallback',
705             type: types_.FUNCTION,
706             optional: true,
707             nullable: true
708         }
709     ]);
710
711     _sensorListeners[this.sensorType].getData(
712         args.successCallback,
713         errorWrapper.bind(args)
714     );
715 };
716
717 //// AccelerationSensor
718 var AccelerationSensor = function(data) {
719     Sensor.call(this, SensorType.ACCELERATION);
720 };
721
722 AccelerationSensor.prototype = new Sensor();
723
724 AccelerationSensor.prototype.constructor = Sensor;
725
726 AccelerationSensor.prototype.getAccelerationSensorData = function() {
727     var args = validator_.validateArgs(arguments, [
728         {
729             name: 'successCallback',
730             type: types_.FUNCTION
731         },
732         {
733             name: 'errorCallback',
734             type: types_.FUNCTION,
735             optional: true,
736             nullable: true
737         }
738     ]);
739
740     _sensorListeners[this.sensorType].getData(
741         args.successCallback,
742         errorWrapper.bind(args)
743     );
744 };
745
746 ////////////////////// Sensor Data classes/////////////////////////////
747 ////Base SensorData class
748 var SensorData = function() {};
749
750 //// SensorLightData
751 var SensorLightData = function(data) {
752     SensorData.call(this);
753     Object.defineProperties(this, {
754         lightLevel: { value: data.lightLevel, writable: false, enumerable: true }
755     });
756 };
757
758 SensorLightData.prototype = new SensorData();
759
760 SensorLightData.prototype.constructor = SensorData;
761
762 _sensorListeners[SensorType.LIGHT] = new SensorListener(
763     SensorType.LIGHT,
764     SensorLightData
765 );
766
767 //// SensorMagneticData
768 var SensorMagneticData = function(data) {
769     SensorData.call(this);
770     Object.defineProperties(this, {
771         x: { value: data.x, writable: false, enumerable: true },
772         y: { value: data.y, writable: false, enumerable: true },
773         z: { value: data.z, writable: false, enumerable: true },
774         accuracy: { value: data.accuracy, writable: false, enumerable: true }
775     });
776 };
777
778 SensorMagneticData.prototype = new SensorData();
779
780 SensorMagneticData.prototype.constructor = SensorData;
781
782 _sensorListeners[SensorType.MAGNETIC] = new SensorListener(
783     SensorType.MAGNETIC,
784     SensorMagneticData
785 );
786
787 //// SensorPressureData
788 var SensorPressureData = function(data) {
789     SensorData.call(this);
790     Object.defineProperties(this, {
791         pressure: { value: data.pressure, writable: false, enumerable: true }
792     });
793 };
794
795 SensorPressureData.prototype = new SensorData();
796
797 SensorPressureData.prototype.constructor = SensorData;
798
799 _sensorListeners[SensorType.PRESSURE] = new SensorListener(
800     SensorType.PRESSURE,
801     SensorPressureData
802 );
803
804 //// SensorProximityData
805 var SensorProximityData = function(data) {
806     SensorData.call(this);
807     Object.defineProperties(this, {
808         proximityState: { value: data.proximityState, writable: false, enumerable: true }
809     });
810 };
811
812 SensorProximityData.prototype = new SensorData();
813
814 SensorProximityData.prototype.constructor = SensorData;
815
816 _sensorListeners[SensorType.PROXIMITY] = new SensorListener(
817     SensorType.PROXIMITY,
818     SensorProximityData
819 );
820
821 //// SensorUltravioletData
822 var SensorUltravioletData = function(data) {
823     SensorData.call(this);
824     Object.defineProperties(this, {
825         ultravioletLevel: {
826             value: data.ultravioletLevel,
827             writable: false,
828             enumerable: true
829         }
830     });
831 };
832
833 SensorUltravioletData.prototype = new SensorData();
834
835 SensorUltravioletData.prototype.constructor = SensorData;
836
837 _sensorListeners[SensorType.ULTRAVIOLET] = new SensorListener(
838     SensorType.ULTRAVIOLET,
839     SensorUltravioletData
840 );
841
842 ////SensorHRMRawData
843 var SensorHRMRawData = function(data) {
844     SensorData.call(this);
845     Object.defineProperties(this, {
846         lightType: { value: data.lightType, writable: false, enumerable: true },
847         lightIntensity: { value: data.lightIntensity, writable: false, enumerable: true }
848     });
849 };
850
851 SensorHRMRawData.prototype = new SensorData();
852
853 SensorHRMRawData.prototype.constructor = SensorData;
854
855 _sensorListeners[SensorType.HRM_RAW] = new SensorListener(
856     SensorType.HRM_RAW,
857     SensorHRMRawData
858 );
859
860 //// SensorGravityData
861 var SensorGravityData = function(data) {
862     SensorData.call(this);
863     Object.defineProperties(this, {
864         x: { value: data.x, writable: false, enumerable: true },
865         y: { value: data.y, writable: false, enumerable: true },
866         z: { value: data.z, writable: false, enumerable: true }
867     });
868 };
869
870 SensorGravityData.prototype = new SensorData();
871
872 SensorGravityData.prototype.constructor = SensorData;
873
874 _sensorListeners[SensorType.GRAVITY] = new SensorListener(
875     SensorType.GRAVITY,
876     SensorGravityData
877 );
878
879 //// SensorGyroscopeData
880 var SensorGyroscopeData = function(data) {
881     SensorData.call(this);
882     Object.defineProperties(this, {
883         x: { value: data.x, writable: false, enumerable: true },
884         y: { value: data.y, writable: false, enumerable: true },
885         z: { value: data.z, writable: false, enumerable: true }
886     });
887 };
888
889 SensorGyroscopeData.prototype = new SensorData();
890
891 SensorGyroscopeData.prototype.constructor = SensorData;
892
893 _sensorListeners[SensorType.GYROSCOPE] = new SensorListener(
894     SensorType.GYROSCOPE,
895     SensorGyroscopeData
896 );
897
898 //// SensorGyroscopeRotationVectorData
899 var SensorGyroscopeRotationVectorData = function(data) {
900     SensorData.call(this);
901     Object.defineProperties(this, {
902         x: { value: data.x, writable: false, enumerable: true },
903         y: { value: data.y, writable: false, enumerable: true },
904         z: { value: data.z, writable: false, enumerable: true },
905         w: { value: data.w, writable: false, enumerable: true }
906     });
907 };
908
909 SensorGyroscopeRotationVectorData.prototype = new SensorData();
910
911 SensorGyroscopeRotationVectorData.prototype.constructor = SensorData;
912
913 _sensorListeners[SensorType.GYROSCOPE_ROTATION_VECTOR] = new SensorListener(
914     SensorType.GYROSCOPE_ROTATION_VECTOR,
915     SensorGyroscopeRotationVectorData
916 );
917
918 //// SensorLinearAccelerationData
919 var SensorLinearAccelerationData = function(data) {
920     SensorData.call(this);
921     Object.defineProperties(this, {
922         x: { value: data.x, writable: false, enumerable: true },
923         y: { value: data.y, writable: false, enumerable: true },
924         z: { value: data.z, writable: false, enumerable: true }
925     });
926 };
927
928 SensorLinearAccelerationData.prototype = new SensorData();
929
930 SensorLinearAccelerationData.prototype.constructor = SensorData;
931
932 _sensorListeners[SensorType.LINEAR_ACCELERATION] = new SensorListener(
933     SensorType.LINEAR_ACCELERATION,
934     SensorLinearAccelerationData
935 );
936
937 //// SensorMagneticUncalibratedData
938 var SensorMagneticUncalibratedData = function(data) {
939     SensorData.call(this);
940     Object.defineProperties(this, {
941         x: { value: data.x, writable: false, enumerable: true },
942         y: { value: data.y, writable: false, enumerable: true },
943         z: { value: data.z, writable: false, enumerable: true },
944         xAxisBias: { value: data.xAxisBias, writable: false, enumerable: true },
945         yAxisBias: { value: data.yAxisBias, writable: false, enumerable: true },
946         zAxisBias: { value: data.zAxisBias, writable: false, enumerable: true }
947     });
948 };
949
950 SensorMagneticUncalibratedData.prototype = new SensorData();
951
952 SensorMagneticUncalibratedData.prototype.constructor = SensorData;
953
954 _sensorListeners[SensorType.MAGNETIC_UNCALIBRATED] = new SensorListener(
955     SensorType.MAGNETIC_UNCALIBRATED,
956     SensorMagneticUncalibratedData
957 );
958
959 //// SensorGyroscopeUncalibratedData
960 var SensorGyroscopeUncalibratedData = function(data) {
961     SensorData.call(this);
962     Object.defineProperties(this, {
963         x: { value: data.x, writable: false, enumerable: true },
964         y: { value: data.y, writable: false, enumerable: true },
965         z: { value: data.z, writable: false, enumerable: true },
966         xAxisDrift: { value: data.xAxisDrift, writable: false, enumerable: true },
967         yAxisDrift: { value: data.yAxisDrift, writable: false, enumerable: true },
968         zAxisDrift: { value: data.zAxisDrift, writable: false, enumerable: true }
969     });
970 };
971
972 SensorGyroscopeUncalibratedData.prototype = new SensorData();
973
974 SensorGyroscopeUncalibratedData.prototype.constructor = SensorData;
975
976 _sensorListeners[SensorType.GYROSCOPE_UNCALIBRATED] = new SensorListener(
977     SensorType.GYROSCOPE_UNCALIBRATED,
978     SensorGyroscopeUncalibratedData
979 );
980
981 //// SensorAccelerationData
982 var SensorAccelerationData = function(data) {
983     SensorData.call(this);
984     Object.defineProperties(this, {
985         x: { value: data.x, writable: false, enumerable: true },
986         y: { value: data.y, writable: false, enumerable: true },
987         z: { value: data.z, writable: false, enumerable: true }
988     });
989 };
990
991 SensorAccelerationData.prototype = new SensorData();
992
993 SensorAccelerationData.prototype.constructor = SensorData;
994
995 _sensorListeners[SensorType.ACCELERATION] = new SensorListener(
996     SensorType.ACCELERATION,
997     SensorAccelerationData
998 );
999
1000 //////////////////////SensorHardwareInfo classes/////////////////////////////
1001 function SensorHardwareInfo(data) {
1002     Object.defineProperties(this, {
1003         name: { value: data.name, writable: false, enumerable: true },
1004         type: { value: data.type, writable: false, enumerable: true },
1005         vendor: { value: data.vendor, writable: false, enumerable: true },
1006         minValue: { value: data.minValue, writable: false, enumerable: true },
1007         maxValue: { value: data.maxValue, writable: false, enumerable: true },
1008         resolution: { value: data.resolution, writable: false, enumerable: true },
1009         minInterval: { value: data.minInterval, writable: false, enumerable: true },
1010         maxBatchCount: { value: data.batchCount, writable: false, enumerable: true }
1011     });
1012 }
1013 // Exports
1014 exports = new SensorService();