forked from akafugu/VFDDeluxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotary.h
70 lines (54 loc) · 1.53 KB
/
rotary.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
/*
* VFD Deluxe - Firmware for VFD Modular Clock mk2
* (C) 2011-13 Akafugu Corporation
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*/
#ifndef ROTARY_H_
#define ROTARY_H_
#include "features.h"
#ifdef HAVE_ROTARY
#include <stdbool.h>
#include <avr/io.h>
class Rotary {
public:
Rotary()
: m_rotary_raw_pos(0)
, m_min(0)
, m_max(12*4)
, m_rotary_pos(0)
, m_divider(4)
{}
// fixme: set pins properly using arduino functions
void begin();
void setDivider(uint8_t divider);
void setRange(uint8_t from, uint8_t to);
void setPosition(uint8_t value);
void wrap();
void save();
void restore();
uint8_t getPosition();
uint8_t getRawPosition();
private:
//uint8_t m_encoder_state;
// Raw position of rotary encoder (4 ticks per click)
uint8_t m_rotary_raw_pos;
// max and min value
uint8_t m_min, m_max;
// Current position of rotary encoder
uint8_t m_rotary_pos;
// Divider for rotary encoder position
uint8_t m_divider;
// saved values
uint8_t m_saved_pos, m_saved_min, m_saved_max;
};
#endif // HAVE_ROTARY
#endif // ROTARY_H_