/
singlwolf
/
Radiola-2S3
Обзор
Документация
Войти
/
singlwolf
/
Radiola-2S3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/RotaryEncoder.h
68 строк
2 KB
SinglWolf
Public access
27 мар 2026, 07:00
27 мар 2026, 07:00
642fcfc
Код
Авторство
О чём код?
// RotaryEncoder.h // based on https://github.com/igorantolic/ai-esp32-rotary-encoder code #ifndef _YOENCODER_h #define _YOENCODER_h #include "Arduino.h" // IWYU pragma: export typedef enum { BUT_DOWN = 0, BUT_PUSHED = 1, BUT_UP = 2, BUT_RELEASED = 3, BUT_DISABLED = 99, } ButtonState; class RotaryEncoder { private: portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; portMUX_TYPE buttonMux = portMUX_INITIALIZER_UNLOCKED; volatile long encoder0Pos = 0; volatile int8_t lastMovementDirection = 0; // 1 right; -1 left volatile unsigned long lastMovementAt = 0; unsigned long rotaryAccelerationCoef = 150; bool _circleValues = false; bool isEnabled = true; int8_t encoderAPin = -1; int8_t encoderBPin = -1; long encoderSteps = 0; // long _minEncoderValue = -1 << 15; long _minEncoderValue = -32768; long _maxEncoderValue = 1 << 15; uint8_t old_AB = 0; long lastReadEncoder0Pos = 0; int8_t enc_states[16] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; void (*ISR_callback)() = NULL; public: RotaryEncoder(); void setBoundaries(long minValue = -100, long maxValue = 100, bool circleValues = false); void readEncoder_ISR(); void setup(void (*ISR_callback)(void)); void begin(int8_t encoderAPin, int8_t encoderBPin, uint8_t encoderSteps, bool internalPullup = true); void reset(long newValue = 0); void enable(); void disable(); long readEncoder(); void setEncoderValue(long newValue); long encoderChanged(); unsigned long getAcceleration() { return this->rotaryAccelerationCoef; } void setAcceleration(unsigned long acceleration) { this->rotaryAccelerationCoef = acceleration; } void disableAcceleration() { setAcceleration(0); } }; #endif