-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmenu.cpp
More file actions
203 lines (181 loc) · 5.07 KB
/
menu.cpp
File metadata and controls
203 lines (181 loc) · 5.07 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#ifndef MENU_CPP
#define MENU_CPP
#include "RawTerm.hpp"
namespace fs = std::filesystem;
void trans_rec_win();
void menu_call();
/********************-CLASS-**********************/
class menu {
private:
protected:
public:
void display_menu() {}
};
/******************-FUNCTIONS-*********************/
/*********************-END-************************/
/********************-CLASS-**********************/
class time_printing : public menu {
private:
static int time_enable;
protected:
public:
void enable_time();
void disable_time();
int get_enable_status();
};
/******************-FUNCTIONS-*********************/
int time_printing::time_enable = 0;
void time_printing::enable_time() { time_enable = 1; }
void time_printing::disable_time() { time_enable = 0; }
int time_printing::get_enable_status() { return time_enable; }
/*********************-END-************************/
time_printing timeObj;
/********************-CLASS-**********************/
class device : public menu {
private:
int device_idx;
protected:
public:
device();
ofstream outy;
void write(string);
void display_menu();
void switch_dev(int i);
int get_curr_dev();
};
/******************-FUNCTIONS-*********************/
device::device() : device_idx(0) {}
void device::switch_dev(int i) {
device_idx = i;
switch (i) {
case 0:
if (outy) outy.close();
outy.open("/dev/ttyUSB0", ios::binary | ios::out);
break;
case 1:
if (outy) outy.close();
outy.open("/dev/ttyUSB1", ios::binary | ios::out);
break;
case 2:
if (outy) outy.close();
outy.open("/dev/ttyACM0", ios::binary | ios::out);
break;
case 3:
if (outy) outy.close();
outy.open("/dev/ttyACM1", ios::binary | ios::out);
break;
}
}
void device::display_menu() { cout << "device called display_menu"; }
void device::write(string str) { outy << str.c_str() << endl; }
int device::get_curr_dev() { return device_idx; }
/*********************-END-************************/
/********************-CLASS-**********************/
class log_class : public device {
private:
static int log_generation_status;
static int open;
ofstream logan;
int num_logs(const string &, const string &);
protected:
public:
void enable_log();
void disable_log();
int get_log_status();
void open_file();
void generate_log(const char *str);
};
/******************-FUNCTIONS-*********************/
int log_class::open = 0;
int log_class::log_generation_status = 0;
int log_class::num_logs(const string &dir, const string &file) {
int file_count = 0;
for (auto &p : fs::directory_iterator(dir)) {
string filename = p.path().filename();
if (!filename.compare(0, file.size(), file)) file_count++;
}
return file_count;
}
void log_class::enable_log() { log_generation_status = 1; }
void log_class::disable_log() { log_generation_status = 0; }
int log_class::get_log_status() { return log_generation_status; }
void log_class::open_file() {
if (open == 0) {
const string LOGS_DIR = "logs";
string str_date = print_date();
fs::create_directory(LOGS_DIR);
fs::path log_filepath = LOGS_DIR;
int n = num_logs(LOGS_DIR, str_date);
log_filepath /= str_date + "_" + to_string(n);
logan.open(log_filepath.c_str(), ios::out | ios::binary);
}
open++;
}
void log_class::generate_log(const char *str) {
open_file();
logan << str << endl;
}
/*********************-END-************************/
// TODO
log_class logObj;
/********************-CLASS-**********************/
class ip_file : public device {
private:
protected:
public:
void file_input();
void display_menu();
};
/******************-FUNCTIONS-*********************/
void ip_file::file_input() { trans_rec_win(); }
void ip_file::display_menu() { cout << "device called display_menu"; }
/*********************-END-************************/
/********************-CLASS-**********************/
class baud {
private:
static int baud_status;
int baud_idx;
protected:
public:
void enable_baud();
void disable_baud();
int get_baud_status();
void switch_baud(int i);
int get_baud_idx();
};
/******************-FUNCTIONS-*********************/
int baud::baud_status;
void baud::enable_baud() { baud_status = 1; }
void baud::disable_baud() { baud_status = 0; }
int baud::get_baud_status() { return baud_status; }
void baud::switch_baud(int i) {
baud_idx = i;
switch (i) {
case 0:
break;
case 1:
break;
case 2:
break;
}
}
int baud::get_baud_idx() { return baud_idx; }
/*********************-END-************************/
/********************-CLASS-**********************/
class newline {
private:
static int newline_status;
protected:
public:
void enable_newline();
void disable_newline();
int get_nl_status(void);
};
/******************-FUNCTIONS-*********************/
int newline::newline_status;
void newline::enable_newline() { newline_status = 1; }
void newline::disable_newline() { newline_status = 0; }
int newline::get_nl_status(void) { return newline_status; }
/*********************-END-************************/
#include "Final_Project.cpp"
#endif // MENU_CPP