-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.h
64 lines (48 loc) · 1.43 KB
/
encoder.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
#ifndef ENCODER_H
#define ENCODER_H
#include <array>
#include <cstdint>
#include <iostream>
#include <fstream>
#include <tuple>
#include <vector>
// types
struct NoteStatus {
const unsigned int key;
bool status = false;
};
using status_array = std::vector<NoteStatus>;
using array12 = std::array<uint_fast8_t,12>;
using array3 = std::array<uint_fast8_t,3>;
// security
void write_time();
void check_valid_pin(const uint_fast8_t pin);
void throw_and_flush();
template <typename T>
void check_duplicates (const T& arr) {
std::ofstream error_file {"/home/pi/error_file",std::ofstream::app};
for (size_t i=0;i<arr.size();++i) {
for (size_t j=0; j<arr.size();++j) {
if (j == i)
continue;
if (arr[j] == arr[i]){
write_time();
error_file << "Please check the pins: " << static_cast<int>(arr[j]) << " is used more than one time.\n";
std::cerr << "Pins error\n";
error_file.flush();
throw 1;
}
}
}
}
// setup
std::tuple<array12,array3> get_pins();
uint_fast8_t get_channel();
void set_output_pins(const array12&);
void set_input_pins(const array3&);
void light_on();
status_array get_notes_status_array();
// main loop
void send_message(uint_fast8_t, uint_fast8_t);
void loop( const array12& lines, const array3& columns, const uint_fast8_t channel, status_array& key_array);
#endif