Skip to content

Commit f68452d

Browse files
committed
upd
1 parent efc3299 commit f68452d

File tree

4 files changed

+99
-95
lines changed

4 files changed

+99
-95
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ void loop() {
11411141
- Поддержка 4-х типов энкодеров
11421142
- Переписана документация
11431143
- EncButton теперь заменяет GyverLibs/VirtualButton (архивирована)
1144+
- v3.0.1 - перезалив для Wokwi
11441145
11451146
<a id="feedback"></a>
11461147
## Баги и обратная связь

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EncButton
2-
version=3.0
2+
version=3.0.1
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Light and powerful library for button and encoder operation for Arduino

src/EncButton.h

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,4 @@
33

44
#include "core/Button.h"
55
#include "core/Encoder.h"
6-
7-
#include "core/VirtEncButton.h"
8-
#include "core/utils.h"
9-
10-
// ===================== CLASS =====================
11-
class EncButton : public VirtEncButton {
12-
public:
13-
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
14-
EncButton(uint8_t encA = 0, uint8_t encB = 0, uint8_t btn = 0, uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
15-
init(encA, encB, btn, modeEnc, modeBtn);
16-
setButtonLevel(LOW);
17-
}
18-
19-
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
20-
void init(uint8_t encA = 0, uint8_t encB = 0, uint8_t btn = 0, uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
21-
e0 = encA;
22-
e1 = encB;
23-
b = btn;
24-
pinMode(e0, modeEnc);
25-
pinMode(e1, modeEnc);
26-
pinMode(b, modeBtn);
27-
initEnc(readEnc());
28-
}
29-
30-
// ====================== TICK ======================
31-
// функция обработки для вызова в прерывании энкодера
32-
int8_t tickISR() {
33-
return VirtEncButton::tickISR(readEnc());
34-
}
35-
36-
// функция обработки, вызывать в loop
37-
int8_t tick() {
38-
return VirtEncButton::tick(readEnc(), EBread(b));
39-
}
40-
41-
// ====================== READ ======================
42-
// прочитать значение кнопки
43-
bool readBtn() {
44-
return EBread(b) ^ read_bf(EB_INV);
45-
}
46-
47-
// прочитать значение энкодера
48-
int8_t readEnc() {
49-
return EBread(e0) | (EBread(e1) << 1);
50-
}
51-
52-
// ===================== PRIVATE =====================
53-
private:
54-
uint8_t e0, e1, b;
55-
};
56-
57-
// ===================== T CLASS =====================
58-
template <uint8_t ENCA, uint8_t ENCB, uint8_t BTN>
59-
class EncButtonT : public VirtEncButton {
60-
public:
61-
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
62-
EncButtonT(uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
63-
init(modeEnc, modeBtn);
64-
setButtonLevel(LOW);
65-
}
66-
67-
// настроить пины (pinmode энк, pinmode кнопка)
68-
void init(uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
69-
pinMode(ENCA, modeEnc);
70-
pinMode(ENCB, modeEnc);
71-
pinMode(BTN, modeBtn);
72-
initEnc(readEnc());
73-
}
74-
75-
// ====================== TICK ======================
76-
// функция обработки для вызова в прерывании энкодера
77-
int8_t tickISR() {
78-
return VirtEncButton::tickISR(readEnc());
79-
}
80-
81-
// функция обработки, вызывать в loop
82-
int8_t tick() {
83-
return VirtEncButton::tick(readEnc(), EBread(BTN));
84-
}
85-
86-
// ====================== READ ======================
87-
// прочитать значение кнопки
88-
bool readBtn() {
89-
return EBread(BTN) ^ read_bf(EB_INV);
90-
}
91-
92-
// прочитать значение энкодера
93-
int8_t readEnc() {
94-
return EBread(ENCA) | (EBread(ENCB) << 1);
95-
}
96-
97-
// ===================== PRIVATE =====================
98-
private:
99-
};
6+
#include "core/EncButton.h"

src/core/EncButton.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#pragma once
2+
#include <Arduino.h>
3+
4+
#include "VirtEncButton.h"
5+
#include "utils.h"
6+
7+
// ===================== CLASS =====================
8+
class EncButton : public VirtEncButton {
9+
public:
10+
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
11+
EncButton(uint8_t encA = 0, uint8_t encB = 0, uint8_t btn = 0, uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
12+
init(encA, encB, btn, modeEnc, modeBtn);
13+
setButtonLevel(LOW);
14+
}
15+
16+
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
17+
void init(uint8_t encA = 0, uint8_t encB = 0, uint8_t btn = 0, uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
18+
e0 = encA;
19+
e1 = encB;
20+
b = btn;
21+
pinMode(e0, modeEnc);
22+
pinMode(e1, modeEnc);
23+
pinMode(b, modeBtn);
24+
initEnc(readEnc());
25+
}
26+
27+
// ====================== TICK ======================
28+
// функция обработки для вызова в прерывании энкодера
29+
int8_t tickISR() {
30+
return VirtEncButton::tickISR(readEnc());
31+
}
32+
33+
// функция обработки, вызывать в loop
34+
int8_t tick() {
35+
return VirtEncButton::tick(readEnc(), EBread(b));
36+
}
37+
38+
// ====================== READ ======================
39+
// прочитать значение кнопки
40+
bool readBtn() {
41+
return EBread(b) ^ read_bf(EB_INV);
42+
}
43+
44+
// прочитать значение энкодера
45+
int8_t readEnc() {
46+
return EBread(e0) | (EBread(e1) << 1);
47+
}
48+
49+
// ===================== PRIVATE =====================
50+
private:
51+
uint8_t e0, e1, b;
52+
};
53+
54+
// ===================== T CLASS =====================
55+
template <uint8_t ENCA, uint8_t ENCB, uint8_t BTN>
56+
class EncButtonT : public VirtEncButton {
57+
public:
58+
// настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
59+
EncButtonT(uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
60+
init(modeEnc, modeBtn);
61+
setButtonLevel(LOW);
62+
}
63+
64+
// настроить пины (pinmode энк, pinmode кнопка)
65+
void init(uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
66+
pinMode(ENCA, modeEnc);
67+
pinMode(ENCB, modeEnc);
68+
pinMode(BTN, modeBtn);
69+
initEnc(readEnc());
70+
}
71+
72+
// ====================== TICK ======================
73+
// функция обработки для вызова в прерывании энкодера
74+
int8_t tickISR() {
75+
return VirtEncButton::tickISR(readEnc());
76+
}
77+
78+
// функция обработки, вызывать в loop
79+
int8_t tick() {
80+
return VirtEncButton::tick(readEnc(), EBread(BTN));
81+
}
82+
83+
// ====================== READ ======================
84+
// прочитать значение кнопки
85+
bool readBtn() {
86+
return EBread(BTN) ^ read_bf(EB_INV);
87+
}
88+
89+
// прочитать значение энкодера
90+
int8_t readEnc() {
91+
return EBread(ENCA) | (EBread(ENCB) << 1);
92+
}
93+
94+
// ===================== PRIVATE =====================
95+
private:
96+
};

0 commit comments

Comments
 (0)