CPP-TOOLBOX
Loading...
Searching...
No Matches
temporal_binary_signal.hpp
Go to the documentation of this file.
1#ifndef TEMPORAL_BINARY_SIGNAL_HPP
2#define TEMPORAL_BINARY_SIGNAL_HPP
3
4#include <iostream>
5#include <vector>
6#include <chrono>
7
9
10enum class State { on, off, just_on, just_off };
11
13 public:
14 TemporalBinarySignal(); // construct
15 TemporalBinarySignal(const TemporalBinarySignal &other); // copy
16 TemporalBinarySignal(TemporalBinarySignal &&other) noexcept; // move
17 ~TemporalBinarySignal(); // destruct
18 TemporalBinarySignal &operator=(const TemporalBinarySignal &other); // copy assignment
19 TemporalBinarySignal &operator=(TemporalBinarySignal &&other) noexcept; // move assignment
20
24
25 void set_signal(bool value);
26 void set_on();
27 void set_off();
28 void toggle_state();
29 // todo about to add a history buffer as to when it was called, then we can do analsis on that I think..
30 // process must be called every timestep
31 void process();
33 std::string get_current_state_string();
34
35 // this function should be called
36 State get_next_state() const;
37
38 bool logging_enabled = false;
39
40 bool is_on() const;
41 bool is_off() const;
42 bool is_just_on() const;
43 bool is_just_off() const;
44 bool has_just_changed() const;
45
46 bool next_is_on() const;
47 bool next_is_off() const;
48 bool next_is_just_on() const;
49 bool next_is_just_off() const;
50 bool next_has_just_changed() const;
51
52 bool is_on(State state) const;
53 bool is_off(State state) const;
54 bool is_just_on(State state) const;
55 bool is_just_off(State state) const;
56
57 // true iff signal has entered the just on state twice within the last second
58 bool is_double_tapped();
59
60 // static function to process all active signals
61 static void process_all();
62
63 private:
64 State current_state; // current state of the temporal binary signal
65 bool raw_signal;
66 int num_times_signal_set_since_last_process = 0;
67
68 ExpiringTemporalVector<State> state_history{5};
69
70 // static container to keep track of all active signals
71 static std::vector<TemporalBinarySignal *> active_signals;
72};
73
74#endif // TEMPORAL_BINARY_SIGNAL_HPP
A vector-like container where elements expire after a certain time limit and can be retrieved by time...
Definition expiring_temporal_vector.hpp:13
void set_signal(bool value)
Definition temporal_binary_signal.cpp:67
void add_to_active_signals()
Definition temporal_binary_signal.cpp:45
bool next_is_just_off() const
Definition temporal_binary_signal.cpp:118
void set_on()
Definition temporal_binary_signal.cpp:69
void process()
Definition temporal_binary_signal.cpp:75
TemporalBinarySignal & operator=(const TemporalBinarySignal &other)
Definition temporal_binary_signal.cpp:25
TemporalBinarySignal()
Definition temporal_binary_signal.cpp:7
bool has_just_changed() const
Definition temporal_binary_signal.cpp:113
static void process_all()
Definition temporal_binary_signal.cpp:147
bool next_has_just_changed() const
Definition temporal_binary_signal.cpp:119
void set_off()
Definition temporal_binary_signal.cpp:71
bool is_off() const
Definition temporal_binary_signal.cpp:110
bool next_is_on() const
Definition temporal_binary_signal.cpp:115
void toggle_state()
Definition temporal_binary_signal.cpp:73
bool next_is_just_on() const
Definition temporal_binary_signal.cpp:117
bool next_is_off() const
Definition temporal_binary_signal.cpp:116
State get_next_state() const
Definition temporal_binary_signal.cpp:83
~TemporalBinarySignal()
Definition temporal_binary_signal.cpp:23
State get_current_state() const
Definition temporal_binary_signal.cpp:81
bool is_on() const
Definition temporal_binary_signal.cpp:109
bool logging_enabled
Definition temporal_binary_signal.hpp:38
void display_num_active_signals()
Definition temporal_binary_signal.cpp:49
bool is_just_off() const
Definition temporal_binary_signal.cpp:112
std::string get_current_state_string()
Definition temporal_binary_signal.cpp:53
bool is_just_on() const
Definition temporal_binary_signal.cpp:111
void remove_from_active_signals()
Definition temporal_binary_signal.cpp:46
bool is_double_tapped()
Definition temporal_binary_signal.cpp:127
State
Definition temporal_binary_signal.hpp:10
@ just_off
Definition temporal_binary_signal.hpp:10
@ off
Definition temporal_binary_signal.hpp:10
@ just_on
Definition temporal_binary_signal.hpp:10
@ on
Definition temporal_binary_signal.hpp:10