diff options
Diffstat (limited to 'rotaryencoder.cpp')
| -rw-r--r-- | rotaryencoder.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/rotaryencoder.cpp b/rotaryencoder.cpp index 41d56e8..62ca33d 100644 --- a/rotaryencoder.cpp +++ b/rotaryencoder.cpp @@ -26,7 +26,7 @@ const std::vector<int> encoderTable = { 0, 1, -1, 0, -1, 0, 0, 1, 1, 0, 0, -1, 0, -1, 1, 0 }; -volatile int64_t positionSteps; +volatile int32_t positionSteps; volatile uint8_t state; void pin_isr(void) { @@ -55,8 +55,14 @@ void pin_isr(void) { } } -rotaryencoder::rotaryencoder() +RotaryEncoder::RotaryEncoder() { + if (!m_self) { + m_self = this; + } else { + qWarning() << "normally there should be only one instance of RotaryEncoder"; + } + QElapsedTimer t; t.start(); @@ -101,7 +107,19 @@ rotaryencoder::rotaryencoder() // } } -int64_t rotaryencoder::position() const +RotaryEncoder::~RotaryEncoder() +{ + if (m_self == this) { + m_self = nullptr; + } +} + +RotaryEncoder *RotaryEncoder::instance() +{ + return m_self; +} + +int32_t RotaryEncoder::position() const { return ::positionSteps; } |
