-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemporal_binary_signal.hpp
74 lines (57 loc) · 2.37 KB
/
temporal_binary_signal.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
#ifndef TEMPORAL_BINARY_SIGNAL_HPP
#define TEMPORAL_BINARY_SIGNAL_HPP
#include <iostream>
#include <vector>
#include <chrono>
#include "sbpt_generated_includes.hpp"
enum class State { on, off, just_on, just_off };
class TemporalBinarySignal {
public:
TemporalBinarySignal(); // construct
TemporalBinarySignal(const TemporalBinarySignal &other); // copy
TemporalBinarySignal(TemporalBinarySignal &&other) noexcept; // move
~TemporalBinarySignal(); // destruct
TemporalBinarySignal &operator=(const TemporalBinarySignal &other); // copy assignment
TemporalBinarySignal &operator=(TemporalBinarySignal &&other) noexcept; // move assignment
void add_to_active_signals();
void remove_from_active_signals();
void display_num_active_signals();
void set_signal(bool value);
void set_on();
void set_off();
void toggle_state();
// todo about to add a history buffer as to when it was called, then we can do analsis on that I think..
// process must be called every timestep
void process();
State get_current_state() const;
std::string get_current_state_string();
// this function should be called
State get_next_state() const;
bool logging_enabled = false;
bool is_on() const;
bool is_off() const;
bool is_just_on() const;
bool is_just_off() const;
bool has_just_changed() const;
bool next_is_on() const;
bool next_is_off() const;
bool next_is_just_on() const;
bool next_is_just_off() const;
bool next_has_just_changed() const;
bool is_on(State state) const;
bool is_off(State state) const;
bool is_just_on(State state) const;
bool is_just_off(State state) const;
// true iff signal has entered the just on state twice within the last second
bool is_double_tapped();
// static function to process all active signals
static void process_all();
private:
State current_state; // current state of the temporal binary signal
bool raw_signal;
int num_times_signal_set_since_last_process = 0;
ExpiringTemporalVector<State> state_history{std::chrono::seconds(5)};
// static container to keep track of all active signals
static std::vector<TemporalBinarySignal *> active_signals;
};
#endif // TEMPORAL_BINARY_SIGNAL_HPP