-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdso_gui.hpp
456 lines (403 loc) · 14 KB
/
dso_gui.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
#pragma once
//=====================================================================//
/*! @file
@brief DSO GUI クラス
@author 平松邦仁 (hira@rvf-rc45.net)
@copyright Copyright (C) 2020, 2022 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "gui/widget_director.hpp"
#include "capture.hpp"
#include "render_wave.hpp"
#include "refclk.hpp"
namespace dsos {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief 波形描画クラス
@param[in] RENDER 描画クラス
@param[in] TOUCH タッチ・クラス
@param[in] CAPTURE キャプチャー・クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <class RENDER, class TOUCH, class CAPTURE>
class dso_gui : public render_base {
static constexpr int16_t BTN_GRID = 40;
static constexpr int16_t BTN_SIZE = 38;
RENDER& render_;
TOUCH& touch_;
CAPTURE& capture_;
uint16_t capture_cycle_;
typedef gui::widget_director<RENDER, TOUCH, 32> WIDD;
WIDD widd_;
typedef render_wave<RENDER, TOUCH, CAPTURE> RENDER_WAVE;
RENDER_WAVE render_wave_;
typedef gui::widget WIDGET;
typedef gui::button BUTTON;
BUTTON ch0_btn_;
BUTTON ch1_btn_;
BUTTON smp_btn_;
BUTTON trg_btn_;
BUTTON mes_btn_;
BUTTON opt_btn_;
typedef gui::menu MENU;
MENU ch0_mult_menu_;
MENU ch0_mode_menu_;
MENU ch0_volt_menu_;
MENU ch1_mult_menu_;
MENU ch1_mode_menu_;
MENU ch1_volt_menu_;
MENU trg_menu_;
MENU smp_unit_menu_;
MENU smp_fine_menu_;
MENU mes_menu_;
MENU opt_menu_;
uint8_t smp_unit_;
uint8_t smp_fine_;
uint32_t trg_update_;
refclk refclk_;
bool widd_last_;
bool wave_last_;
WIDGET* last_focus_;
// メニュー表示を行っている場合に、ルートボタンをストールさせる。
void side_button_stall_(BUTTON& mybtn, bool stall) noexcept
{
if(&mybtn != &ch0_btn_) {
if(stall) ch0_btn_.set_state(BUTTON::STATE::STALL);
else ch0_btn_.enable();
}
if(&mybtn != &ch1_btn_) {
if(stall) ch1_btn_.set_state(BUTTON::STATE::STALL);
else ch1_btn_.enable();
}
if(&mybtn != &trg_btn_) {
if(stall) trg_btn_.set_state(BUTTON::STATE::STALL);
else trg_btn_.enable();
}
if(&mybtn != &smp_btn_) {
if(stall) smp_btn_.set_state(BUTTON::STATE::STALL);
else smp_btn_.enable();
}
if(&mybtn != &mes_btn_) {
if(stall) mes_btn_.set_state(BUTTON::STATE::STALL);
else mes_btn_.enable();
}
if(&mybtn != &opt_btn_) {
if(stall) opt_btn_.set_state(BUTTON::STATE::STALL);
else opt_btn_.enable();
}
}
void setup_smp_fine_() noexcept
{
const char* p = nullptr;
switch(smp_unit_) {
case 0:
p = SMP_FINE0_STR;
break;
case 1:
p = SMP_FINE1_STR;
break;
case 2:
p = SMP_FINE2_STR;
break;
case 3:
p = SMP_FINE3_STR;
break;
case 4:
p = SMP_FINE4_STR;
break;
default:
break;
}
smp_fine_menu_.set_title(p);
}
void setup_ch0_() noexcept
{
auto mult = static_cast<CH_MULT>(ch0_mult_menu_.get_select_pos());
render_wave_.set_ch0_mult(mult);
auto mode = static_cast<CH_MODE>(ch0_mode_menu_.get_select_pos());
render_wave_.set_ch0_mode(mode);
auto vol = static_cast<CH_VOLT>(ch0_volt_menu_.get_select_pos());
render_wave_.set_ch0_volt(vol);
}
void setup_ch1_() noexcept
{
auto mult = static_cast<CH_MULT>(ch1_mult_menu_.get_select_pos());
render_wave_.set_ch1_mult(mult);
auto mode = static_cast<CH_MODE>(ch1_mode_menu_.get_select_pos());
render_wave_.set_ch1_mode(mode);
auto vol = static_cast<CH_VOLT>(ch1_volt_menu_.get_select_pos());
render_wave_.set_ch1_volt(vol);
}
void exec_capture_() noexcept
{
auto trg = static_cast<TRG_MODE>(trg_menu_.get_select_pos());
if(trg != CAPTURE::TRG_MODE::STOP) {
auto idx = smp_unit_menu_.get_select_pos() * 3 + smp_fine_menu_.get_select_pos();
uint32_t sr = AD_SAMPLE_RATE[idx];
capture_.set_samplerate(sr * 1000);
}
capture_.turn_ch_mode(0, static_cast<CH_MODE>(ch0_mode_menu_.get_select_pos()));
capture_.turn_ch_mode(1, static_cast<CH_MODE>(ch1_mode_menu_.get_select_pos()));
capture_.set_trg_mode(trg, render_wave_.get_trg_value());
}
void draw_focus_(WIDGET* w) noexcept
{
render_.set_fore_color(w->get_base_color());
const auto& org = w->at_location().org;
render_.line_h(org.y + BTN_SIZE - 9, org.x + 6, BTN_SIZE - 6 * 2);
render_.line_h(org.y + BTN_SIZE - 8, org.x + 6, BTN_SIZE - 6 * 2);
render_.line_h(org.y + BTN_SIZE - 7, org.x + 6, BTN_SIZE - 6 * 2);
}
public:
//-----------------------------------------------------------------//
/*!
@brief コンストラクタ
@param[in] render 描画クラス
@param[in] touch タッチ・クラス
@param[in] capture キャプチャー・クラス
*/
//-----------------------------------------------------------------//
dso_gui(RENDER& render, TOUCH& touch, CAPTURE& capture) noexcept :
render_(render), touch_(touch), capture_(capture),
capture_cycle_(0),
widd_(render, touch),
render_wave_(render_, touch_, capture_),
ch0_btn_(vtx::srect(442, 16+BTN_GRID*0, BTN_SIZE, BTN_SIZE), "CH0"),
ch1_btn_(vtx::srect(442, 16+BTN_GRID*1, BTN_SIZE, BTN_SIZE), "CH1"),
smp_btn_(vtx::srect(442, 16+BTN_GRID*2, BTN_SIZE, BTN_SIZE), "Smp"),
trg_btn_(vtx::srect(442, 16+BTN_GRID*3, BTN_SIZE, BTN_SIZE), "Trg"),
mes_btn_(vtx::srect(442, 16+BTN_GRID*4, BTN_SIZE, BTN_SIZE), "Mes"),
opt_btn_(vtx::srect(442, 16+BTN_GRID*5, BTN_SIZE, BTN_SIZE), "Opt"),
ch0_mult_menu_(vtx::srect(442-90*3, 16, 80, 0), CAPTURE::CH_MULT_STR),
ch0_mode_menu_(vtx::srect(442-90*2, 16, 80, 0), CAPTURE::CH_MODE_STR),
ch0_volt_menu_(vtx::srect(442-90*1, 16, 80, 0), CAPTURE::CH_VOLT_STR),
ch1_mult_menu_(vtx::srect(442-90*3, 16, 80, 0), CAPTURE::CH_MULT_STR),
ch1_mode_menu_(vtx::srect(442-90*2, 16, 80, 0), CAPTURE::CH_MODE_STR),
ch1_volt_menu_(vtx::srect(442-90*1, 16, 80, 0), CAPTURE::CH_VOLT_STR),
trg_menu_(vtx::srect(442-100, 16, 90, 0), CAPTURE::TRG_MODE_STR),
smp_unit_menu_(vtx::srect(442-90*2, 16, 80, 0), SMP_UNIT_STR, false),
smp_fine_menu_(vtx::srect(442-90*1, 16, 80, 0), ""),
mes_menu_(vtx::srect(442-100*1, 16, 90, 0), MES_MODE_STR),
opt_menu_(vtx::srect(442-100*1, 16, 90, 0), OPTION_STR),
smp_unit_(0), smp_fine_(0),
trg_update_(0),
refclk_(), widd_last_(false), wave_last_(false),
last_focus_(nullptr)
{ }
//-----------------------------------------------------------------//
/*!
@brief 開始
*/
//-----------------------------------------------------------------//
void start() noexcept
{
ch0_btn_.set_layer(WIDGET::LAYER::_0);
ch0_btn_.set_base_color(CH0_COLOR);
ch0_btn_.enable();
ch0_btn_.at_select_func() = [=](uint32_t id) {
bool ena = ch0_mode_menu_.get_state() == WIDGET::STATE::ENABLE;
ch0_mult_menu_.enable(!ena);
ch0_mode_menu_.enable(!ena);
ch0_volt_menu_.enable(!ena);
side_button_stall_(ch0_btn_, !ena);
if(ena) { // メニューを閉じる瞬間
setup_ch0_();
}
};
ch1_btn_.set_layer(WIDGET::LAYER::_0);
ch1_btn_.set_base_color(CH1_COLOR);
ch1_btn_.enable();
ch1_btn_.at_select_func() = [=](uint32_t id) {
bool ena = ch1_mode_menu_.get_state() == WIDGET::STATE::ENABLE;
ch1_mult_menu_.enable(!ena);
ch1_mode_menu_.enable(!ena);
ch1_volt_menu_.enable(!ena);
side_button_stall_(ch1_btn_, !ena);
if(ena) { // メニューを閉じる瞬間
setup_ch1_();
}
};
smp_btn_.set_layer(WIDGET::LAYER::_0);
smp_btn_.set_base_color(SMP_COLOR);
smp_btn_.enable();
smp_btn_.at_select_func() = [=](uint32_t id) {
bool ena = smp_unit_menu_.get_state() == WIDGET::STATE::ENABLE;
smp_unit_menu_.enable(!ena);
setup_smp_fine_();
smp_fine_menu_.enable(!ena);
side_button_stall_(smp_btn_, !ena);
if(ena) {
auto smp = static_cast<SMP_MODE>(smp_fine_menu_.get_select_pos()
+ smp_unit_menu_.get_select_pos() * SMP_FINE_NUM);
render_wave_.set_smp_mode(smp);
}
};
trg_btn_.set_layer(WIDGET::LAYER::_0);
trg_btn_.set_base_color(TRG_COLOR);
trg_btn_.enable();
trg_btn_.at_select_func() = [=](uint32_t id) {
bool ena = trg_menu_.get_state() == WIDGET::STATE::ENABLE;
trg_menu_.enable(!ena);
side_button_stall_(trg_btn_, !ena);
if(ena) { // メニューを閉じる瞬間
exec_capture_();
}
};
mes_btn_.set_layer(WIDGET::LAYER::_0);
mes_btn_.set_base_color(MES_COLOR);
mes_btn_.enable();
mes_btn_.at_select_func() = [=](uint32_t id) {
bool ena = mes_menu_.get_state() == WIDGET::STATE::ENABLE;
mes_menu_.enable(!ena);
side_button_stall_(mes_btn_, !ena);
if(ena) {
render_wave_.set_measere(static_cast<MEASERE>(mes_menu_.get_select_pos()));
}
};
mes_menu_.set_layer(WIDGET::LAYER::_0);
mes_menu_.set_base_color(MES_COLOR);
opt_btn_.set_layer(WIDGET::LAYER::_0);
opt_btn_.enable();
opt_btn_.at_select_func() = [=](uint32_t id) {
bool ena = opt_menu_.get_state() == WIDGET::STATE::ENABLE;
opt_menu_.enable(!ena);
side_button_stall_(opt_btn_, !ena);
if(ena) {
auto opt = static_cast<OPT_MODE>(opt_menu_.get_select_pos());
if(opt != OPT_MODE::NONE) {
}
}
};
opt_menu_.set_layer(WIDGET::LAYER::_0);
ch0_mult_menu_.set_layer(WIDGET::LAYER::_0);
ch0_mult_menu_.set_base_color(CH0_COLOR);
ch0_mode_menu_.set_layer(WIDGET::LAYER::_0);
ch0_mode_menu_.set_base_color(CH0_COLOR);
ch0_volt_menu_.set_layer(WIDGET::LAYER::_0);
ch0_volt_menu_.set_base_color(CH0_COLOR);
ch1_mult_menu_.set_layer(WIDGET::LAYER::_0);
ch1_mult_menu_.set_base_color(CH1_COLOR);
ch1_mode_menu_.set_layer(WIDGET::LAYER::_0);
ch1_mode_menu_.set_base_color(CH1_COLOR);
ch1_volt_menu_.set_layer(WIDGET::LAYER::_0);
ch1_volt_menu_.set_base_color(CH1_COLOR);
trg_menu_.set_layer(WIDGET::LAYER::_0);
trg_menu_.set_base_color(TRG_COLOR);
smp_unit_menu_.set_layer(WIDGET::LAYER::_0);
smp_unit_menu_.set_base_color(SMP_COLOR);
smp_unit_menu_.at_select_func() = [=](uint32_t pos, uint32_t num) {
smp_unit_ = pos;
setup_smp_fine_();
};
smp_fine_menu_.set_layer(WIDGET::LAYER::_0);
smp_fine_menu_.set_base_color(SMP_COLOR);
smp_fine_menu_.at_select_func() = [=](uint32_t pos, uint32_t num) {
smp_fine_ = pos;
};
capture_cycle_ = capture_.get_capture_cycle();
capture_.set_trg_mode(TRG_MODE::SINGLE, 0);
// 基準波出力開始
refclk_.start();
last_focus_ = &ch0_btn_;
render_wave_.set_target(TARGET::CH0);
}
//-----------------------------------------------------------------//
/*!
@brief 更新 @n
※毎フレーム呼ぶ
*/
//-----------------------------------------------------------------//
void update() noexcept
{
widd_last_ = widd_.update();
// ダブルバッファ時の widget 管理のケア
if(render_.is_double_buffer()) {
// GUI 操作が発生したら、ダブルバッファの両方に同じ絵を作る。
if(!widd_last_) {
widd_.refresh();
}
}
// CH0, CH1, Smp(Time) ボタンのフォーカスを描画
{
auto w = widd_.get_current_widget();
if(w == &ch0_btn_) {
draw_focus_(w);
last_focus_ = w;
render_wave_.set_target(TARGET::CH0);
} else if(w == &ch1_btn_) {
draw_focus_(w);
last_focus_ = w;
render_wave_.set_target(TARGET::CH1);
} else if(last_focus_ != nullptr) {
draw_focus_(last_focus_);
}
}
// キャプチャーをやり直す条件
if(!wave_last_) { // 前のトリガー描画が終了した~
bool capture = false;
if(trg_update_ != render_wave_.get_trg_update()) { // トリガー電圧が変更になった!
trg_update_ = render_wave_.get_trg_update();
auto trg = static_cast<TRG_MODE>(trg_menu_.get_select_pos());
if(trg == CAPTURE::TRG_MODE::CH0_POS || trg == CAPTURE::TRG_MODE::CH0_NEG
|| trg == CAPTURE::TRG_MODE::CH1_POS || trg == CAPTURE::TRG_MODE::CH1_NEG) {
capture = true;
}
}
// チャネル倍率変更、チャネルモード変更、チャネル電圧レンジ変更
auto trg = static_cast<TRG_MODE>(trg_menu_.get_select_pos());
if(trg != TRG_MODE::STOP && trg != TRG_MODE::SINGLE) { // トリガーモードが 'NONE', 'SINGLE' 以外は常にキャプチャーを行う。
capture = true;
}
if(capture) {
exec_capture_();
}
}
uint32_t n = 0;
if(ch0_mode_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
} else if(ch1_mode_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
} else if(trg_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
} else if(smp_unit_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
} else if(mes_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
} else if(opt_menu_.get_state() == gui::widget::STATE::ENABLE) {
++n;
}
if(n == 0) { // メニュー選択時はバイパスする。
bool f = render_wave_.ui_service(); // タッチ操作による画面更新が必要な場合「true」が戻る。
// 波形をキャプチャーしたら描画
if(!wave_last_) {
auto cycle = capture_.get_capture_cycle();
if(cycle != capture_cycle_) {
capture_cycle_ = cycle;
if(static_cast<TRG_MODE>(trg_menu_.get_select_pos()) == TRG_MODE::AUTO) { // AUTO の場合、トリガー位置を自動で検出する。
capture_.auto_analize();
}
f = true;
}
}
if(f) {
render_wave_.update();
wave_last_ = true;
} else if(wave_last_) { // ダブルバッファに書き込む為、同じ描画を行う
render_wave_.update();
wave_last_ = false;
}
render_wave_.update_info();
}
render_.flip();
}
//-----------------------------------------------------------------//
/*!
@brief widget_director の参照
@return widget_director
*/
//-----------------------------------------------------------------//
auto& at_widd() noexcept { return widd_; }
};
}