qvibra.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "qvibra.h"
  2. #include "qvibra_p.h"
  3. #include <math.h>
  4. #include <QDebug>
  5. QVibra::QVibra(QObject *parent) :
  6. QObject(parent)
  7. ,m_rotation(QVibra::Positive)
  8. {
  9. QT_TRAP_THROWING(d = QVibraPrivate::NewL(this));
  10. }
  11. QVibra::~QVibra()
  12. {
  13. delete d;
  14. }
  15. bool QVibra::start(int duration, int intensity)
  16. {
  17. int m_intensity = Min<int>(abs(intensity), 100);
  18. return ( this->d ) ? this->d->start(duration, ((this->m_rotation==QVibra::Positive) ? m_intensity : -m_intensity)) : false;
  19. }
  20. bool QVibra::stop()
  21. {
  22. return ( this->d ) ? this->d->stop() : false;
  23. }
  24. void QVibra::reserve()
  25. {
  26. if( this->d ) this->d->reserve();
  27. }
  28. void QVibra::release()
  29. {
  30. if( this->d ) this->d->release();
  31. }
  32. QVibra::Status QVibra::currentStatus() const
  33. {
  34. return (this->d) ? d->currentStatus() : StatusNotAllowed;
  35. }
  36. QVibra::EngineRotation QVibra::rotation(){
  37. return this->m_rotation;
  38. }
  39. void QVibra::setRotation(EngineRotation value){
  40. this->m_rotation = value;
  41. }
  42. QVibra::Error QVibra::error() const
  43. {
  44. return (this->d) ? d->error() : NotCreated;
  45. }
  46. QString QVibra::errorString() const
  47. {
  48. QString result = "";
  49. if (this->d) {
  50. switch(d->error()) {
  51. case QVibra::NoError : result = "NoError"; break;
  52. case QVibra::OutOfMemoryError : result = "OutOfMemoryError"; break;
  53. case QVibra::ArgumentError : result = "ArgumentError"; break;
  54. case QVibra::VibraInUseError : result = "VibraInUseError"; break;
  55. case QVibra::HardwareError : result = "HardwareError"; break;
  56. case QVibra::TimeOutError : result = "TimeOutError"; break;
  57. case QVibra::VibraLockedError : result = "VibraLockedError"; break; // Vibra is locked down because too much continuous use or explicitly blocked by for example some vibration sensitive accessory
  58. case QVibra::AccessDeniedError: result = "AccessDeniedError"; break;
  59. case QVibra::UnknownError : result = "UnknownError"; break;
  60. //case QVibra::NotCreated : result = "NotCreated"; break;
  61. default: result = "UnknownError"; break;
  62. }
  63. }
  64. return result;
  65. }