sensors.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <QDebug>
  2. #include <QWebFrame>
  3. #include <QMainWindow>
  4. #include <QString>
  5. #include <QDateTime>
  6. #include <QMessageBox>
  7. #include "Sensors.h"
  8. #include "SymbianSDKSensors.h"
  9. Sensors::Sensors()
  10. {
  11. qDebug() << "Sensors object created";
  12. m_symbianSDKSensors = new SymbianSDKSensors(*this);
  13. }
  14. Sensors::~Sensors()
  15. {
  16. delete m_symbianSDKSensors;
  17. }
  18. void Sensors::setEnvironment(QMainWindow *parentWindow, QWebFrame *webFrame)
  19. {
  20. m_parentWindow = parentWindow;
  21. m_webFrame = webFrame;
  22. webFrame->addToJavaScriptWindowObject("sensor", this);
  23. }
  24. void Sensors::findSensorChannel(const QString &criteria)
  25. {
  26. m_symbianSDKSensors->findSensorChannel(criteria);
  27. }
  28. void Sensors::addChannelInfo(int ChannelId, int ContextType, int Quantity, int ChannelType, const QString &Location, const QString &VendorId, int DataItemSize, int ChannelDataTypeId)
  29. {
  30. QString javaScriptString = QString("addChannelInfo(%1, %2, %3, %4, \"%5\", \"%6\", %7, %8)").arg(ChannelId).arg(ContextType).arg(Quantity).arg(ChannelType).arg(Location).arg(VendorId).arg(DataItemSize).arg(ChannelDataTypeId);
  31. m_webFrame->evaluateJavaScript(javaScriptString);
  32. }
  33. void Sensors::accelerometerEvent(int transactionId, int axisX, int axisY, int axisZ, long timeStamp)
  34. {
  35. // 2 - Event completed
  36. // 4 - Event error
  37. // 9 - Event in progress
  38. QString javaScriptString = QString("accelerometerAxisDataEvent(%1, 2, \"AxisData\", \"%2\", %3, %4, %5)").arg(transactionId).arg(QDateTime::currentDateTime().toString()).arg(axisX).arg(axisY).arg(axisZ);
  39. m_webFrame->evaluateJavaScript(javaScriptString);
  40. }
  41. void Sensors::orientationEvent(int transactionId, int deviceOrientation, long timeStamp)
  42. {
  43. QString devOrient("");
  44. switch(deviceOrientation)
  45. {
  46. case 0:
  47. devOrient = "Undefined";
  48. break;
  49. case 1:
  50. devOrient = "DisplayUp";
  51. break;
  52. case 2:
  53. devOrient = "DisplayDown";
  54. break;
  55. case 3:
  56. devOrient = "DisplayLeftUp";
  57. break;
  58. case 4:
  59. devOrient = "DisplayRightUp";
  60. break;
  61. case 5:
  62. devOrient = "DisplayUpwards";
  63. break;
  64. case 6:
  65. devOrient = "DisplayDownwards";
  66. break;
  67. }
  68. QString javaScriptString = QString("orientationDataEvent(%1, 2, \"OrientationData\", \"%2\", \"%3\")").arg(transactionId).arg(QDateTime::currentDateTime().toString()).arg(devOrient);
  69. m_webFrame->evaluateJavaScript(javaScriptString);
  70. }
  71. void Sensors::tappingEvent(int transactionId, int direction, long timeStamp)
  72. {
  73. QString javaScriptString = QString("accelerometerDoubleTappingDataEvent(%1, 2, \"DoubleTappingData\", \"%2\", %3)").arg(transactionId).arg(QDateTime::currentDateTime().toString()).arg(direction);
  74. m_webFrame->evaluateJavaScript(javaScriptString);
  75. }
  76. int Sensors::registerForNotification(const QString &listeningType, int ChannelId, int ContextType, int Quantity, int ChannelType, const QString &Location, const QString &VendorId, int DataItemSize, int ChannelDataTypeId)
  77. {
  78. // TODO check here listening type
  79. int retval = -1;
  80. retval = m_symbianSDKSensors->registerForNotification(ChannelId, ContextType, Quantity, ChannelType, Location, VendorId, DataItemSize, ChannelDataTypeId);
  81. return retval;
  82. }
  83. void Sensors::cancel(int criteria)
  84. {
  85. m_symbianSDKSensors->cancel(criteria);
  86. }
  87. void Sensors::getChannelProperty(const QString &listeningType, int ChannelId, int ContectType, int Quantity, int ChannelType, const QString &location, const QString &VendorId, int DataItemSize, int ChannelDataTypeId, const QString &PropertyId)
  88. {
  89. }