-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotaryEncoder.h
70 lines (53 loc) · 1.6 KB
/
RotaryEncoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
RotaryEncoder.h - Library for interfacing rotary encoders with STM32duino
Created by datenpirat, January 8, 2019.
Released into the public domain.
*/
#ifndef RotaryEncoder_h
#define RotaryEncoder_h
#include "Arduino.h"
class RotaryEncoder
{
public:
RotaryEncoder(int PIN1, int PIN2, int PINBTN);
void UseInterrupts();
int8_t Read();
int8_t GetEncoderValue();
uint8_t HasButtonChanged();
int8_t HasEncoderChanged();
uint8_t GetButtonIsPressing();
uint32_t GetButtonPressedTime();
uint8_t GetButtonPressedCount();
uint8_t GetButtonDown();
uint8_t GetButtonUp();
private:
typedef struct {
uint8_t pin;
volatile int8_t *p_val;
volatile uint32_t *p_tick;
} IRQHandlerParameters;
typedef struct {
uint8_t pin;
volatile uint32_t *p_lastRising = 0, *p_riseTime = 0, *p_fallTime = 0;
uint8_t *p_buttonChanged = 0, *p_buttonIsPressing = 0;
} BtnIRQHandlerParameters;
uint8_t _pin1;
uint8_t _pin2;
uint8_t _pinBtn;
uint8_t useInterrupts = 0;
uint8_t prevNextCode = 0;
uint16_t store=0;
static void IRQPIN1(void* p);
static void IRQPIN2(void* p);
static void IRQBTN(void* p);
volatile int8_t encoderPos = 0;
int8_t lastReportedPos = 1;
uint8_t rotating;
uint32_t lastTick;
IRQHandlerParameters ihp1;
IRQHandlerParameters ihp2;
BtnIRQHandlerParameters btnhp;
volatile uint32_t lastRising = 0, riseTime = 0, fallTime = 0;
uint8_t buttonChanged = 0, buttonIsPressing = 0;
};
#endif