-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconsole.h
More file actions
135 lines (103 loc) · 4.54 KB
/
Copy pathconsole.h
File metadata and controls
135 lines (103 loc) · 4.54 KB
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
// (C) 2018-2026 by Folkert van Heusden
// Released under MIT license
#pragma once
#include "gen.h"
#include <functional>
#include <optional>
#include <string>
#if !defined(BUILD_FOR_PICO2W) && !defined(TEENSY4_1)
#include <thread>
#endif
#include <vector>
#include "my_lock.h"
#include "utils.h"
#if defined(_WIN32)
#include "win32.h"
#endif
class blinkenlights;
class bus;
class console;
class cpu;
class ddp;
class tty;
using explode_func_t = std::optional<std::string> (*)(console *const cnsl, const std::string & current_in);
class console
{
public:
enum panel_mode_t { PM_BITS, PM_ADDRESS1, PM_ADDRESS2 };
private:
my_threadsafe_queue<char> input_buffer;
my_lock put_string_lock;
protected:
kek_event_t *const stop_event { nullptr };
abool stop_panel { false };
blinkenlights *p_blinkenlights { nullptr };
ddp *p_ddp { nullptr };
panel_mode_t panel_mode { PM_BITS }; // TODO: atomic_int or locking (altough int...)
bus *b { nullptr };
#if !defined(BUILD_FOR_PICO2W) && !defined(TEENSY4_1)
std::thread *th_kb { nullptr };
std::thread *th_panel { nullptr };
#endif
int refreshrate { 15 };
abool disk_read_activity_flag { false };
abool disk_write_activity_flag { false };
abool network_activity_flag { false };
abool running_flag { false };
abool do_test_panel { false };
uint8_t brightness { 16 };
bool stop_thread_flag { false };
const int t_width { 0 };
const int t_height { 0 };
char *screen_buffer { nullptr };
uint8_t tx { 0 };
uint8_t ty { 0 };
abool timestamps { false };
const uint64_t start_ts { get_us() };
bool escape { false };
std::string escape_buffer;
const size_t n_edit_lines_hist { 8 }; // maximum number of previous edit-lines
std::vector<std::string> edit_lines_hist;
std::string debug_buffer;
tty *have_data_cb_notifier { nullptr };
virtual int wait_for_char_ll(const int timeout) = 0;
virtual void put_char_ll (const char c ) = 0;
public:
console(kek_event_t *const stop_event, const int t_width = 80, const int t_height = 25);
virtual ~console();
virtual void begin();
void set_bus(bus *const b) { this->b = b; }
void start_thread();
void stop_thread();
bool poll_char();
int get_char();
std::optional<int> wait_char(const int timeout_ms);
std::string read_line(const std::string & prompt, const explode_func_t & ef = nullptr);
void flush_input();
void set_data_cb_notifier(auto notifier) { have_data_cb_notifier = notifier; }
void enable_timestamp(const bool state) { timestamps = state; }
void emit_backspace();
void put_char(const char c);
void put_string(const std::string & what);
virtual void put_string_lf(const std::string & what) = 0;
virtual void resize_terminal() = 0;
virtual void refresh_virtual_terminal() = 0;
virtual void operator()();
abool * get_running_flag() { return &running_flag; }
abool * get_disk_read_activity_flag() { return &disk_read_activity_flag; }
abool * get_disk_write_activity_flag() { return &disk_write_activity_flag; }
abool * get_network_activity_flag() { return &network_activity_flag; }
void generate_panel_colors(std::vector<std::tuple<uint8_t, uint8_t, uint8_t> > & to, const size_t n_leds, bus *const b, cpu *const c, const uint8_t brightness);
void set_panel_mode(const panel_mode_t pm);
void set_panel_brightness(const uint8_t b);
void set_blinkenlights_panel(blinkenlights *const p_blinkenlights);
void set_ddp_panel(ddp *const p_ddp);
void stop_panel_thread() { stop_panel = true; }
virtual void panel_update_thread() = 0;
int get_refreshrate( ) const { return refreshrate; }
void set_refreshrate(const int rate) { refreshrate = rate; }
void test_panel() { do_test_panel = true; }
virtual void set_LED_state(const bool state);
virtual void pulse_LED ( );
virtual void ui_event_loop() = 0;
};