forked from ChrisVeigl/BrainBay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ob_com_writer.cpp
171 lines (139 loc) · 4.69 KB
/
ob_com_writer.cpp
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
/* -----------------------------------------------------------------------------
BrainBay Version 1.7, GPL 2003-2010, contact: chris@shifz.org
MODULE: OB_COM_WRITER.CPP: contains functions for the Com-Port Writer
Author: Chris Veigl
The Com-Port Writer Object can be used to write Bytes to an opened Com-Port.
This will be usually a port where a bidirectional EEG-device like the
MONOLITH-EEG is connected to. Using this Object, Command- and Data Bytes can be
sent to the Device, for example to adjust the baud- or sampling rate.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; See the
GNU General Public License for more details.
-----------------------------------------------------------------------------*/
#include "brainBay.h"
#include "ob_com_writer.h"
LRESULT CALLBACK ComWriterDlgHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
char szdata[50];
COM_WRITEROBJ * st;
st = (COM_WRITEROBJ *) actobject;
if ((st==NULL)||(st->type!=OB_COM_WRITER)) return(FALSE);
switch( message )
{
case WM_INITDIALOG:
CheckDlgButton(hDlg, IDC_TRIGGER, st->en_trigger);
SetDlgItemInt(hDlg,IDC_COMMAND,st->command,0);
SetDlgItemInt(hDlg,IDC_DATA1,st->data1,0);
SetDlgItemInt(hDlg,IDC_DATA2,st->data2,0);
if (TTY.COMDEV==INVALID_HANDLE_VALUE)
SetDlgItemText(hDlg,IDC_STATUS,"COM-Port for EEG not available");
else if (st->cnt==0) SetDlgItemText(hDlg,IDC_STATUS,"ready to send");
else { sprintf(szdata,"%d frames written",st->cnt);
SetDlgItemText(hDlg,IDC_STATUS,szdata); }
break;
case WM_CLOSE:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_SENDCOMMAND:
st->command=(unsigned char) GetDlgItemInt(hDlg,IDC_COMMAND,NULL,0);
st->data1=(unsigned char) GetDlgItemInt(hDlg,IDC_DATA1,NULL,0);
st->data2=(unsigned char) GetDlgItemInt(hDlg,IDC_DATA2,NULL,0);
if (TTY.COMDEV!=INVALID_HANDLE_VALUE)
{
write_to_comport (st->command );
write_to_comport (st->data1 );
write_to_comport (st->data2 );
//if (!SetEvent(TTY.WriterEvent))
// if (WriterProc(NULL)) st->cnt++;
sprintf(szdata,"%d frames written",st->cnt);
SetDlgItemText(hDlg,IDC_STATUS,szdata);
}
break;
case IDC_TRIGGER:
st->en_trigger=IsDlgButtonChecked(hDlg, IDC_TRIGGER);
break;
case IDC_RESET:
st->cnt=0;
if (TTY.COMDEV!=INVALID_HANDLE_VALUE)
SetDlgItemText(hDlg,IDC_STATUS,"0 frames written");
break;
}
return TRUE;
break;
case WM_SIZE:
case WM_MOVE: update_toolbox_position(hDlg);
break;
}
return FALSE;
}
COM_WRITEROBJ::COM_WRITEROBJ(int num) : BASE_CL()
{
inports = 2;
width=75;
strcpy(in_ports[0].in_name,"trigger");
strcpy(in_ports[1].in_name,"data2");
input = INVALID_VALUE;
trigger=INVALID_VALUE;
input2 = INVALID_VALUE;
trigger2=INVALID_VALUE;
command=129; data1=0; data2=0; en_trigger=0; cnt=0;
}
void COM_WRITEROBJ::make_dialog(void) {display_toolbox(hDlg=CreateDialog(hInst, (LPCTSTR)IDD_COM_WRITERBOX, ghWndStatusbox, (DLGPROC)ComWriterDlgHandler)); }
void COM_WRITEROBJ::load(HANDLE hFile)
{
load_object_basics(this);
load_property("command",P_INT,&command);
load_property("data1",P_INT,&data1);
load_property("data2",P_INT,&data2);
load_property("trigger",P_INT,&en_trigger);
}
void COM_WRITEROBJ::save(HANDLE hFile)
{
save_object_basics(hFile, this);
save_property(hFile,"command",P_INT,&command);
save_property(hFile,"data1",P_INT,&data1);
save_property(hFile,"data2",P_INT,&data2);
save_property(hFile,"trigger",P_INT,&en_trigger);
}
void COM_WRITEROBJ::incoming_data(int port, float value)
{
if (port==0) input=value;
if (port==1) input2=value;
}
void COM_WRITEROBJ::work(void)
{
if ((TTY.COMDEV!=INVALID_HANDLE_VALUE) && (en_trigger) && (input!=INVALID_VALUE) && (trigger==INVALID_VALUE))
{
write_to_comport (command );
write_to_comport (data1 );
write_to_comport (data2 );
cnt++;
if (hDlg==ghWndToolbox)
{
char szdata[50];
sprintf(szdata,"%d frames written",cnt);
SetDlgItemText(hDlg,IDC_STATUS,szdata);
}
}
trigger=input;
if ((TTY.COMDEV!=INVALID_HANDLE_VALUE) && (en_trigger) && (input2!=trigger2) && (input2!=INVALID_VALUE))
{
write_to_comport (command );
write_to_comport (data1 );
write_to_comport ((unsigned char) input2);
cnt++;
if (hDlg==ghWndToolbox)
{
char szdata[50];
sprintf(szdata,"%d frames written",cnt);
SetDlgItemText(hDlg,IDC_STATUS,szdata);
}
}
trigger2=input2;
}
COM_WRITEROBJ::~COM_WRITEROBJ() {}