luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NyxSensorConnector.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2011-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 #ifndef __NYX_SENSOR_CONNECTOR_H__
22 #define __NYX_SENSOR_CONNECTOR_H__
23 
24 #include <limits.h>
25 #include <QObject>
26 #include <QSocketNotifier>
27 #include <QEvent>
28 #include <vector>
29 #include <string>
30 
31 #include <nyx/nyx_client.h>
32 
33 #include "CustomEvents.h"
34 
38 #define INVALID_ANGLE (INT_MIN)
39 
40 // Forward declaration
41 struct json_object;
43 
47 class NYXConnectorBase : public QObject
48 {
49  Q_OBJECT
50 public:
51  typedef enum
52  {
71  }Sensor;
72 
73 
80  typedef enum
81  {
82  SensorReportRateUnknown = NYX_REPORT_RATE_UNKNOWN,
83  SensorReportRateDefault = NYX_REPORT_RATE_DEFAULT,
84  SensorReportRateLow = NYX_REPORT_RATE_LOW,
85  SensorReportRateMedium = NYX_REPORT_RATE_MEDIUM,
86  SensorReportRateHigh = NYX_REPORT_RATE_HIGH,
87  SensorReportRateHighest = NYX_REPORT_RATE_HIGHEST,
88  SensorReportRateCount = NYX_REPORT_RATE_COUNT
90 
94  virtual ~NYXConnectorBase ();
95 
101  static std::vector<NYXConnectorBase::Sensor> getSupportedSensors();
102 
111  static std::string getSupportedSensors(bool bJson);
112 
124  static NYXConnectorBase* getSensor (Sensor aSensorType,
125  NYXConnectorObserver *aObserver = 0,
126  bool bCanPostEvent = true);
127 
133  virtual bool on();
134 
140  virtual bool off();
141 
149  virtual bool setRate(SensorReportRate aRate);
150 
158  virtual void setOrientationAngle(int aAngle)
159  {
160  if (INVALID_ANGLE != aAngle)
161  {
162  m_OrientationAngle = aAngle;
163  }
164  }
165 
171  virtual std::string toJSONString();
172 
180  virtual json_object* toJSONObject() = 0;
181 
189  virtual QEvent* getQSensorData() = 0;
190 
196  virtual inline nyx_device_handle_t getHandle()
197  {
198  return m_Handle;
199  }
200 
206  inline Sensor type()
207  {
208  return m_SensorType;
209  }
210 
216  virtual void scheduleDeletion();
217 
218 protected:
228  NYXConnectorBase (Sensor aSensorType, nyx_device_type_t aDevType, nyx_device_id_t aDevID, NYXConnectorObserver *aObserver, bool bCanPostEvent);
229 
234  virtual nyx_error_t openSensor ();
235 
240  virtual void connectSensorSignalToSlot();
241 
248  void callObserver(bool aShouldEmit = true);
249 
253  inline bool canPostEvent()
254  {
255  return m_CanPostEvent;
256  }
257 
258 private:
262  static NYXConnectorBase::Sensor MapFromNYX(nyx_device_type_t aNYXDevType);
263 
264 Q_SIGNALS:
268  virtual void sensorDataAvailable();
269 
270 protected Q_SLOTS:
276  virtual void readSensorData(int aSocket) = 0;
277 
278 protected:
279  // Functions
280 
285  virtual void postProcessSensorData() {}
286 
287  // Data
289  QSocketNotifier* m_NYXSensorNotifier;
290  nyx_device_handle_t m_Handle;
291  nyx_device_type_t m_NYXDeviceType;
292  nyx_device_id_t m_NYXDeviceId;
298 };
299 
304 {
305 public:
312  virtual void NYXDataAvailable (NYXConnectorBase::Sensor aSensorType) = 0;
313 };
314 
319 {
320  Q_OBJECT
321 public:
328  NYXAccelerationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
329 
333  inline float X() const { return m_AccelerationData.x; }
334 
338  inline float Y() const { return m_AccelerationData.y; }
339 
343  inline float Z() const { return m_AccelerationData.z; }
344 
361  virtual json_object* toJSONObject();
362 
370  virtual QEvent* getQSensorData();
371 
372 protected Q_SLOTS:
378  virtual void readSensorData(int aSocket);
379 
380 protected:
385  virtual void postProcessSensorData();
386 
387 private:
388  // Data
389  nyx_sensor_acceleration_event_item_t m_AccelerationData;
390 };
391 
396 {
397  Q_OBJECT
398 public:
405  NYXAlsSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
406 
410  inline int getLightIntensity() { return m_LightIntensity; }
411 
427  virtual json_object* toJSONObject();
428 
436  virtual QEvent* getQSensorData();
437 
438 protected Q_SLOTS:
444  virtual void readSensorData(int aSocket);
445 
446 private:
447  int m_LightIntensity;
448 };
449 
454 {
455  Q_OBJECT
456 public:
463  NYXAngularVelocitySensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
464 
468  inline float X() const { return m_AngularVelocity.x; }
469 
473  inline float Y() const { return m_AngularVelocity.y; }
474 
478  inline float Z() const { return m_AngularVelocity.z; }
479 
497  virtual json_object* toJSONObject();
498 
506  virtual QEvent* getQSensorData();
507 
508 protected Q_SLOTS:
514  virtual void readSensorData(int aSocket);
515 
516 private:
517  nyx_sensor_angular_velocity_event_item_t m_AngularVelocity;
518 };
519 
524 {
525  Q_OBJECT
526 public:
533  NYXBearingSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
534 
538  inline float bearingMagnitude() const { return m_Bearing.magnetic; }
539 
543  inline float trueBearing() const { return m_Bearing.true_bearing; }
544 
548  inline float confidence() const { return m_Bearing.confidence; }
549 
566  virtual json_object* toJSONObject();
567 
576  bool setLocation(double aLatitude, double aLongitude);
577 
585  virtual QEvent* getQSensorData();
586 
587 protected Q_SLOTS:
593  virtual void readSensorData(int aSocket);
594 
595 private:
596  nyx_sensor_bearing_event_item_t m_Bearing;
597 };
598 
603 {
604  Q_OBJECT
605 public:
612  NYXGravitySensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
613 
617  inline float X() const { return m_Gravity.x; }
618 
622  inline float Y() const { return m_Gravity.y; }
623 
627  inline float Z() const { return m_Gravity.z; }
628 
646  virtual json_object* toJSONObject();
647 
655  virtual QEvent* getQSensorData();
656 
657 protected Q_SLOTS:
663  virtual void readSensorData(int aSocket);
664 
665 private:
666  nyx_sensor_gravity_event_item_t m_Gravity;
667 };
668 
673 {
674  Q_OBJECT
675 public:
682  NYXLinearAccelearationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
683 
687  inline float X() const { return m_LinearAcceleration.x; }
688 
692  inline float Y() const { return m_LinearAcceleration.y; }
693 
697  inline float Z() const { return m_LinearAcceleration.z; }
698 
702  inline float WorldX() const { return m_LinearAcceleration.world_x; }
703 
707  inline float WorldY() const { return m_LinearAcceleration.world_y; }
708 
712  inline float WorldZ() const { return m_LinearAcceleration.world_z; }
713 
734  virtual json_object* toJSONObject();
735 
743  virtual QEvent* getQSensorData();
744 
745 protected Q_SLOTS:
751  virtual void readSensorData(int aSocket);
752 
753 private:
754  nyx_sensor_linear_acceleration_event_item_t m_LinearAcceleration;
755 };
756 
761 {
762  Q_OBJECT
763 public:
770  NYXMagneticFieldSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
771 
775  inline int X() const { return m_MagneticField.x; }
776 
780  inline int Y() const { return m_MagneticField.y; }
781 
785  inline int Z() const { return m_MagneticField.z; }
786 
790  inline int rawX() const { return m_MagneticField.raw_x; }
791 
795  inline int rawY() const { return m_MagneticField.raw_y; }
796 
800  inline int rawZ() const { return m_MagneticField.raw_z; }
801 
821  virtual json_object* toJSONObject();
822 
830  virtual QEvent* getQSensorData();
831 
832 protected Q_SLOTS:
838  virtual void readSensorData(int aSocket);
839 
840 private:
841  nyx_sensor_magnetic_field_event_item_t m_MagneticField;
842 };
843 
848 {
849  Q_OBJECT
850 public:
857  NYXOrientationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
858 
863  {
864  return m_Orientation;
865  }
866 
870  const char* toPositionString();
871 
887  virtual json_object* toJSONObject();
888 
896  virtual QEvent* getQSensorData();
897 
898 protected:
903  virtual void postProcessSensorData();
904 
905 protected Q_SLOTS:
911  virtual void readSensorData(int aSocket);
912 
913 private:
922  OrientationEvent::Orientation mapAccelerometerOrientation(int aValue);
923 
924  // Data
925  OrientationEvent::Orientation m_Orientation;
926 };
927 
932 {
933  Q_OBJECT
934 public:
941  NYXScreenProximitySensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
942 
946  inline bool Present() const { return (bool)m_Present; }
947 
955  virtual QEvent* getQSensorData();
956 
964  virtual json_object* toJSONObject() { return 0; }
965 
966 protected Q_SLOTS:
972  virtual void readSensorData(int aSocket);
973 
974 private:
975  int m_Present;
976 };
977 
982 {
983  Q_OBJECT
984 public:
991  NYXRotationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
992 
997  inline float pitch() const { return m_RotationData.euler_angle.pitch; }
998 
1003  inline float roll() const { return m_RotationData.euler_angle.roll; }
1004 
1009  inline float yaw() const { return m_RotationData.euler_angle.yaw; }
1010 
1014  inline float quaternionW() const { return m_RotationData.quaternion_vector.w; }
1015  inline float quaternionX() const { return m_RotationData.quaternion_vector.x; }
1016  inline float quaternionY() const { return m_RotationData.quaternion_vector.y; }
1017  inline float quaternionZ() const { return m_RotationData.quaternion_vector.z; }
1018 
1022  inline const float* rotationMatrix() const { return m_RotationData.matrix; }
1023 
1049  virtual json_object* toJSONObject();
1050 
1058  virtual QEvent* getQSensorData();
1059 
1060 protected Q_SLOTS:
1066  virtual void readSensorData(int aSocket);
1067 
1068 protected:
1073  virtual void postProcessSensorData();
1074 
1075 private:
1076  nyx_sensor_rotation_event_item_t m_RotationData;
1077 };
1078 
1083 {
1084  Q_OBJECT
1085 public:
1092  NYXShakeSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
1093 
1098  {
1099  return m_ShakeState;
1100  }
1101 
1105  inline float shakeMagnitude() const { return m_ShakeMagnitude; }
1106 
1122  virtual json_object* toJSONObject();
1123 
1131  virtual QEvent* getQSensorData();
1132 
1133 protected Q_SLOTS:
1139  virtual void readSensorData(int aSocket);
1140 
1141 private:
1148  ShakeEvent::Shake mapShakeSensorEvent(int aValue);
1149 
1153  const char* toShakeStateString();
1154 
1155  // Data
1156  ShakeEvent::Shake m_ShakeState;
1157  float m_ShakeMagnitude;
1158 };
1159 
1166 {
1167  Q_OBJECT
1168 public:
1173 
1179  virtual bool on();
1180 
1186  virtual bool off();
1187 
1195  virtual bool setRate(SensorReportRate aRate);
1196 
1204  virtual void setOrientationAngle(int aAngle);
1205 
1211  virtual void scheduleDeletion();
1212 
1220  virtual json_object* toJSONObject();
1221 
1222 protected:
1230  NYXLogicalSensorConnectorBase (Sensor aSensorType, NYXConnectorObserver *aObserver, bool bCanPostEvent);
1231 
1236  virtual nyx_error_t openSensor () { return NYX_ERROR_NONE;}
1237 
1242  virtual void connectSensorSignalToSlot() { /* do nothing */ }
1243 
1244 protected Q_SLOTS:
1250  virtual void readSensorData(int ) { /* do nothing. It's an logical sensor and not the physical one */ }
1251 
1256 
1257 protected:
1258  std::vector<NYXConnectorBase *> m_SensorList;
1259 };
1260 
1269 {
1270  Q_OBJECT
1271 public:
1278  NYXLogicalAccelerometerSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
1279 
1287  virtual QEvent* getQSensorData();
1288 
1289 private:
1293  QEvent* readAllSensorData();
1294 };
1295 
1302 {
1303  Q_OBJECT
1304 public:
1311  NYXLogicalOrientationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
1312 
1320  virtual QEvent* getQSensorData();
1321 
1322 private:
1326  QEvent* readAllSensorData();
1327 };
1328 
1335 {
1336  Q_OBJECT
1337 public:
1344  NYXLogicalDeviceOrientationSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
1345 
1353  virtual QEvent* getQSensorData() { return 0; }
1354 };
1355 
1364 {
1365  Q_OBJECT
1366 public:
1373  NYXLogicalDeviceMotionSensorConnector (NYXConnectorObserver *aObserver, bool bCanPostEvent = true);
1374 
1382  virtual QEvent* getQSensorData() { return 0; }
1383 };
1384 
1385 #endif /* __NYX_SENSOR_CONNECTOR_H__ */