-
Notifications
You must be signed in to change notification settings - Fork 0
/
nixie.hpp
160 lines (131 loc) · 3.72 KB
/
nixie.hpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of lambda_nixie_clock.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
#ifndef LAMBDA_NIXIE_CLOCK_NIXIE_HPP
#define LAMBDA_NIXIE_CLOCK_NIXIE_HPP
#include <common.h>
#include <array>
#include <functional>
typedef std::array<bool, 6> nixie_state_array;
/**
* Represents a Nixie tube state.
*/
class NixieState
{
private:
bool _show_number = false;
/** Represents the 4-bit number displayed by the nixie tube. */
uint8_t _number = 0;
bool _left_comma = false;
bool _right_comma = false;
public:
/**
* Returns whether the nixie tube should show a number.
* @return True if the nixie tube should show a number, else false.
*/
[[nodiscard]] bool show_number() const;
/**
* Sets whether the nixie tube should show a number.
* @param show True if the nixie tube should show a number.
*/
void show_number(bool show);
/**
* Turns on the nixie tube.
*/
void on();
/**
* Turns off the nixie tube.
*/
void off();
/**
* Returns the number the nixie tube displays.
* @return The number the nixie tube displays.
*/
[[nodiscard]] uint8_t number() const;
/**
* Sets the number the nixie tube displays.
* @param number A number between 0 and 9 (included).
*/
void number(uint8_t number);
/**
* Returns whether the left comma is displayed.
* @return True if the left comma is displayed, else false.
*/
[[nodiscard]] bool left_comma() const;
/**
* Sets whether the left comma is displayed.
* @param left_comma True if the left comma is displayed, else false.
*/
void left_comma(bool left_comma);
/**
* Returns whether the right comma is displayed.
* @return True if the right comma is displayed.
*/
[[nodiscard]] bool right_comma() const;
/**
* Sets whether the right comma is displayed.
* @param right_comma True if the right comma is displayed.
*/
void right_comma(bool right_comma);
/**
* Clears the nixie tube.
*
* The difference with {@link off()} is this also resets the number.
*/
void clear();
void from_string(const std::string& str);
[[nodiscard]] std::string to_string() const;
/**
* Returns the nixie tube state as a binary array.
* @param array The array.
*/
void to_binary(nixie_state_array& array);
/**
* Push to the shift registers the nixie tube state.
* @param commas True if commas are supported, else false.
*/
void push(bool commas = true);
};
/**
* Represents the nixie tube array of size NIXIE_COUNT.
*/
class NixieArray
{
private:
std::array<NixieState, NIXIE_COUNT> array;
public:
NixieArray();
void from_string(const std::string& str);
NixieState& at(size_t i);
/**
* Executes a provided function once for each array element.
* @param callback Function to execute on each element.
* @return This array.
*/
template<typename _Funct>
NixieArray& for_each(_Funct callback) {
for (size_t index = 0; index < NIXIE_COUNT; index++) {
callback(index, this->array[index]);
}
return *this;
}
/**
* Resets every nixie tube state.
*/
void reset();
[[nodiscard]] constexpr inline size_t size() const {
return NIXIE_COUNT;
}
/**
* Pushes to the shift register all the nixie tube states of this array.
* @param commas True if commas are supported, else false.
*/
void display(bool commas = true);
[[nodiscard]] std::string to_string() const;
};
#endif //LAMBDA_NIXIE_CLOCK_NIXIE_HPP