-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlgSerialConfig.cpp
More file actions
59 lines (52 loc) · 1.55 KB
/
dlgSerialConfig.cpp
File metadata and controls
59 lines (52 loc) · 1.55 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
#include "stdafx.h"
#include <tuple>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Browser.H>
#include <FL/Fl_Return_Button.H>
#include "enumser/enumser.h"
std::tuple<std::string, u32> dialog_SerialConfig( int w = 400, int h = 300 )
{
std::vector<UINT> ports;
std::vector<std::string> friendlyNames;
if( !CEnumerateSerial::UsingSetupAPI2(ports, friendlyNames) )
throw "Failure in EnumSer Library";
char buf[40];
int w2 = w/2, column_widths[] = { w-10, 0 };
Fl_Double_Window win(w, h);
Fl_Browser port(5, 5, w2-10, h-40);
port.column_widths(column_widths);
port.column_char(',');
port.type(FL_HOLD_BROWSER);
for(u32 i = 0; i < ports.size(); i++) {
sprintf_s(buf, "COM%u", ports[i]);
port.add(buf, (void*)ports[i]);
}
port.select(1,1);
Fl_Browser baud(5+w2, 5, w2-10, h-40);
baud.column_widths(column_widths);
baud.column_char(',');
baud.type(FL_HOLD_BROWSER);
for(u32 i : {CBR_38400, CBR_115200}) {
sprintf_s(buf, "%u", i);
baud.add(buf, (void*)i);
}
baud.select(1,1);
// Fl_Button refresh(w-200, h-31, 90, 25, "Refresh");
// refresh.callback([](Fl_Widget *w, void *p){
// // TODO
// }, &win);
Fl_Return_Button ok(w-100, h-31, 90, 25, "Select");
ok.callback([](Fl_Widget *w, void *p){
((Fl_Window*)p)->hide();
}, &win);
win.add(port);
win.add(baud);
win.add(ok);
win.end();
win.set_modal();
win.show();
while( win.shown() ) Fl::wait();
sprintf_s(buf, "\\\\.\\COM%u", (u32)port.data(port.value()));
return std::make_tuple(std::string(buf), (u32)baud.data(baud.value()));
}