-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrot_encoder.cpp
63 lines (53 loc) · 1.2 KB
/
rot_encoder.cpp
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
/*
* author : Shuichi TAKANO
* since : Sun Jun 09 2024 11:49:36
*/
#include "rot_encoder.h"
#include <math.h>
#include "board.h"
#include <stdio.h>
void RotEncoder::update(int dclk, int velocity)
{
rct_ += dclk;
int v = velocity * scale_;
int ct_s = abs(v);
if (ct_s == 0)
{
return;
}
int clk_ct = CPU_CLOCK / ct_s;
if (rct_ >= clk_ct)
{
// rct_ -= clk_ct;
rct_ = 0;
if (v > 0)
{
++state_;
}
else
{
--state_;
}
state_ &= 3;
}
}
std::pair<bool, bool> RotEncoder::getEncState() const
{
static constexpr std::pair<bool, bool> table[] = {
{false, false},
{true, false},
{true, true},
{false, true},
};
return table[state_];
}
uint32_t RotEncoder::overrideButton(uint32_t buttons, int bitA, int bitB) const
{
auto [a, b] = getEncState();
buttons &= ~((1u << bitA) | (1u << bitB));
buttons |= (a << bitA) | (b << bitB);
return buttons;
}
// コントローラーに紐付けられると良い
// LR, UDがアサインされていない時だけ動作するといいかも
// 次は連射フェッチいちをやろう