-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_iup.cpp
More file actions
90 lines (69 loc) · 2.09 KB
/
main_iup.cpp
File metadata and controls
90 lines (69 loc) · 2.09 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
#include <Windows.h>
#include <stdlib.h>
#include <iup.h>
#pragma comment(lib, "iup.lib")
#pragma comment(lib, "comctl32.lib")
#include "bob.h"
#include "serial.h"
Ihandle *gtext = NULL;
serial_t *gserial;
int proc_idle( Ihandle *ih ) { // Icallback
// Check Buffers
gserial->dump([&](str_c str) {
IupSetAttribute(gtext, "APPEND", str);
});
return 0;
};
Ihandle* iup_item(const char* str, Icallback fn) {
auto ih = IupItem( str, NULL);
IupSetCallback( ih, "ACTION", fn);
return ih;
}
#include <thread>
int main_iup( int argc, char *argv[] ) {
block_buffer_t buffer;
serial_t serial("COM2");
gserial = &serial;
Ihandle *dlg, *multitext, *menubar;
HANDLE evt_stop = CreateEvent(nullptr, true, false, nullptr);
std::thread serial_thread(serial_main, std::ref(serial), std::ref(buffer), evt_stop);
IupOpen(&argc, &argv);
gtext = multitext = IupText(NULL);
IupSetAttribute(multitext, "MULTILINE", "YES");
IupSetAttribute(multitext, "EXPAND", "YES");
IupSetAttribute(multitext, "BORDER","NO");
IupSetAttribute(multitext, "BGCOLOR","#111111");
IupSetAttribute(multitext, "FGCOLOR","#DDDDDD");
IupSetAttribute(multitext, "FONT","Consolas 12");
IupSetAttribute(multitext, "READONLY","YES");
IupSetAttribute(multitext, "APPENDNEWLINE","NO");
IupSetFunction("IDLE_ACTION", proc_idle);
menubar = IupMenu(
IupSubmenu("COM", IupMenu(
IupItem("Set Rate", NULL),
IupSeparator(),
IupItem("Logging", NULL),
NULL)),
iup_item("Heater Auto", [](Ihandle *ih) -> int {
gserial->transmit("hau\r");
return IUP_DEFAULT;
}),
iup_item("Heater Enable", [](Ihandle *ih) -> int {
bool en = 0==strcmp("ON", IupGetAttribute(ih, "VALUE"));
gserial->transmit( en ? "hds\r" : "hen\r");
IupSetAttribute(ih, "VALUE", en ? "OFF" : "ON" );
return IUP_DEFAULT;
}),
IupItem("Send", NULL),
NULL);
dlg = IupDialog(multitext);
IupSetAttribute(dlg, "TITLE", "Testware");
IupSetAttribute(dlg, "SIZE", "HALFxHALF");
IupSetAttributeHandle(dlg, "MENU", menubar);
IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
IupMainLoop();
IupClose();
SetEvent(evt_stop);
serial_thread.join();
return 0;
}