mirror of
https://github.com/dwhinham/mt32-pi.git
synced 2026-10-26 22:11:05 +00:00
Minor cleanups in control classes
This commit is contained in:
1 parent
cf81664d2b
commit
fc98e0a198
4 files changed
+15
-14
No files matched your search
@@ -32,8 +32,8 @@ class CRotaryEncoder
|
||||
{
|
||||
public:
|
||||
#define ENUM_ENCODERTYPE(ENUM) \
|
||||
ENUM(Full, full) \
|
||||
ENUM(Half, half) \
|
||||
ENUM(Full, full) \
|
||||
ENUM(Half, half) \
|
||||
ENUM(Quarter, quarter)
|
||||
|
||||
CONFIG_ENUM(TEncoderType, ENUM_ENCODERTYPE);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <circle/timer.h>
|
||||
|
||||
#include "control/rotaryencoder.h"
|
||||
#include "utility.h"
|
||||
|
||||
// Based on encoder reading algorithm by Peter Dannegger: https://embdev.net/articles/Rotary_Encoders
|
||||
|
||||
@@ -96,8 +97,8 @@ s8 CRotaryEncoder::Read()
|
||||
// Apply acceleration curve
|
||||
if (nResult != 0)
|
||||
{
|
||||
const unsigned int nTicks = CTimer::Get()->GetClockTicks();
|
||||
const unsigned int nDeltaMillis = (nTicks - m_nLastReadTime) / 1000;
|
||||
const unsigned int nTicks = CTimer::GetClockTicks();
|
||||
const unsigned int nDeltaMillis = Utility::TicksToMillis(nTicks - m_nLastReadTime);
|
||||
|
||||
if (nDeltaMillis < AccelThresholdMillis)
|
||||
nResult *= RotaryAccelLookupTable[nDeltaMillis];
|
||||
|
||||
@@ -29,9 +29,9 @@ constexpr u8 GPIOPinButton3 = 22;
|
||||
constexpr u8 GPIOPinButton4 = 23;
|
||||
|
||||
constexpr u8 ButtonMask = 1 << static_cast<u8>(TButton::Button1) |
|
||||
1 << static_cast<u8>(TButton::Button2) |
|
||||
1 << static_cast<u8>(TButton::Button3) |
|
||||
1 << static_cast<u8>(TButton::Button4);
|
||||
1 << static_cast<u8>(TButton::Button2) |
|
||||
1 << static_cast<u8>(TButton::Button3) |
|
||||
1 << static_cast<u8>(TButton::Button4);
|
||||
|
||||
CControlSimpleButtons::CControlSimpleButtons(TEventQueue& pEventQueue)
|
||||
: CControl(pEventQueue),
|
||||
@@ -48,9 +48,9 @@ void CControlSimpleButtons::ReadGPIOPins()
|
||||
// Read current button state from GPIO pins
|
||||
const u32 nGPIOState = CGPIOPin::ReadAll();
|
||||
const u8 nButtonState = (((nGPIOState >> GPIOPinButton1) & 1) << static_cast<u8>(TButton::Button1)) |
|
||||
(((nGPIOState >> GPIOPinButton2) & 1) << static_cast<u8>(TButton::Button2)) |
|
||||
(((nGPIOState >> GPIOPinButton3) & 1) << static_cast<u8>(TButton::Button3)) |
|
||||
(((nGPIOState >> GPIOPinButton4) & 1) << static_cast<u8>(TButton::Button4));
|
||||
(((nGPIOState >> GPIOPinButton2) & 1) << static_cast<u8>(TButton::Button2)) |
|
||||
(((nGPIOState >> GPIOPinButton3) & 1) << static_cast<u8>(TButton::Button3)) |
|
||||
(((nGPIOState >> GPIOPinButton4) & 1) << static_cast<u8>(TButton::Button4));
|
||||
|
||||
DebounceButtonState(nButtonState, ButtonMask);
|
||||
}
|
||||
@@ -31,8 +31,8 @@ constexpr u8 GPIOPinEncoderCLK = 22;
|
||||
constexpr u8 GPIOPinEncoderDAT = 23;
|
||||
|
||||
constexpr u8 ButtonMask = 1 << static_cast<u8>(TButton::Button1) |
|
||||
1 << static_cast<u8>(TButton::Button2) |
|
||||
1 << static_cast<u8>(TButton::EncoderButton);
|
||||
1 << static_cast<u8>(TButton::Button2) |
|
||||
1 << static_cast<u8>(TButton::EncoderButton);
|
||||
|
||||
CControlSimpleEncoder::CControlSimpleEncoder(TEventQueue& pEventQueue, CRotaryEncoder::TEncoderType EncoderType, bool bEncoderReversed)
|
||||
: CControl(pEventQueue),
|
||||
@@ -64,8 +64,8 @@ void CControlSimpleEncoder::ReadGPIOPins()
|
||||
// Read current button state from GPIO pins
|
||||
const u32 nGPIOState = CGPIOPin::ReadAll();
|
||||
const u8 nButtonState = (((nGPIOState >> GPIOPinButton1) & 1) << static_cast<u8>(TButton::Button1)) |
|
||||
(((nGPIOState >> GPIOPinButton2) & 1) << static_cast<u8>(TButton::Button2)) |
|
||||
(((nGPIOState >> GPIOPinEncoderButton) & 1) << static_cast<u8>(TButton::EncoderButton));
|
||||
(((nGPIOState >> GPIOPinButton2) & 1) << static_cast<u8>(TButton::Button2)) |
|
||||
(((nGPIOState >> GPIOPinEncoderButton) & 1) << static_cast<u8>(TButton::EncoderButton));
|
||||
|
||||
DebounceButtonState(nButtonState, ButtonMask);
|
||||
|
||||
|
||||
Reference in new issue
Block a user