diff --git a/ECTrainer2/BitalMonitor.cpp b/ECTrainer2/BitalMonitor.cpp new file mode 100644 index 0000000..9732219 --- /dev/null +++ b/ECTrainer2/BitalMonitor.cpp @@ -0,0 +1,63 @@ +#include "ECTrainer.h" +#include "BitalMonitor.h" +#include +#include + +// �R���X�g���N�^ +BitalMonitor::BitalMonitor(ECTrainer* pEct) + :BaseProcess(pEct) { + +} + + +// ������ +bool BitalMonitor::Init() { + + bool rv = _Com.Open(4, _T("baud=19200 parity=N data=8 stop=1")); + + return rv; +} + +// ���[�v +bool BitalMonitor::MainLoop() { + + char lastBuf[256] = { '\0' }; + char comBuf[256] = { '\0' }; + char valueStr[10] = { '\0' }; + const char LF = 10; + + int count = 0; + while (_pEct->IsRunning()) { + + // �o�C�^�� + DWORD readBytes = _Com.Receive((BYTE*)comBuf, 256); + if (readBytes > 0) { + comBuf[readBytes] = '\0'; + //std::cout << "comBuf:" << comBuf << std::endl; + strcat_s(lastBuf, 256, comBuf); + //std::cout << "lastBuf:" << lastBuf << std::endl; + char* sp = lastBuf; + char* pt = sp; + for (; *pt != '\0'; pt++) { + if (*pt == LF) { + //*pt = '\0'; + //std::cout << "value:" << sp << std::endl; + if (*sp == '#') { + int RR = atoi(sp + 1); + if (RR > 0) _pEct->SetHeartBeat(60000 / RR); + //std::cout << "Read:" << RR << std::endl; + } + sp = pt + 1; + } + } + if (*sp == '\0') lastBuf[0] = '\0'; + else strcpy_s(lastBuf, 256, sp); + + //std::cout << "lastBuf2:" << lastBuf << std::endl; + } + Sleep(10); + //if (++count > 20) break; + } + + return true; +} diff --git a/ECTrainer2/BitalMonitor.h b/ECTrainer2/BitalMonitor.h new file mode 100644 index 0000000..fef6606 --- /dev/null +++ b/ECTrainer2/BitalMonitor.h @@ -0,0 +1,15 @@ +#pragma once + +#include "BaseProcess.h" +#include "GComPort.h" + + +class BitalMonitor : public BaseProcess +{ + GComPort _Com; + +public: + BitalMonitor(ECTrainer* pEct); + bool Init(); + bool MainLoop(); +}; diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index cc7b7a2..84c6b2c 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -7,116 +7,148 @@ #include "ImageProc.h" #include "EyeTrack.h" #include "TobiiREST.h" +#include "BitalMonitor.h" // �R���X�g���N�^ ECTrainer::ECTrainer(HINSTANCE hInstance) - : _pGui(NULL) - , _pSceneCam(NULL) - , _pStimulus(NULL) - , _pMarker(NULL) - , _pImageProc(NULL) - , _pEyeTrack(NULL) - , _pTobiiREST(NULL) - , _Running(true) + //: _pGui(NULL) + //, _pSceneCam(NULL) + //, _pStimulus(NULL) + //, _pMarker(NULL) + //, _pImageProc(NULL) + //, _pEyeTrack(NULL) + //, _pTobiiREST(NULL) + //, _pBital(NULL) + : _Running(true) , _HomographyOK(false) , _CalibResult(0) , _hInstance(hInstance) + , _HeartBeat(0) { _pMarker = new Marker(); - _pGui = new ECTrainerGUI(this); - _pImageProc = new ImageProc(this, _pMarker); - _pSceneCam = new SceneCamera(this, _pImageProc); - _pStimulus = new Stimulus(this, _pMarker); - _pEyeTrack = new EyeTrack(this, _pMarker); - _pTobiiREST = new TobiiREST(this); + //_pGui = new ECTrainerGUI(this); + //_pImageProc = new ImageProc(this, _pMarker); + //_pSceneCam = new SceneCamera(this, _pImageProc); + //_pStimulus = new Stimulus(this, _pMarker); + //_pEyeTrack = new EyeTrack(this, _pMarker); + //_pTobiiREST = new TobiiREST(this); + //_pBital = new BitalMonitor(this); + _pProcs[GUI] = new ECTrainerGUI(this); + _pProcs[IMGPROC] = new ImageProc(this, _pMarker); + _pProcs[SCNCAM] = new SceneCamera(this, (ImageProc*)_pProcs[IMGPROC]); + _pProcs[STIM] = new Stimulus(this, _pMarker); + _pProcs[EYETR] = new EyeTrack(this, _pMarker); + _pProcs[REST] = new TobiiREST(this); + _pProcs[BITAL] = new BitalMonitor(this); _MovieToShow = _T(""); } // �f�X�g���N�^ ECTrainer::~ECTrainer() { - if (_pGui) delete _pGui; - if (_pSceneCam) delete _pSceneCam; - if (_pStimulus) delete _pStimulus; - if (_pMarker) delete _pMarker; - if (_pImageProc) delete _pImageProc; - if (_pEyeTrack) delete _pEyeTrack; - if (_pTobiiREST) delete _pTobiiREST; + for (int i = 0; i < NUM; i++) { + if (_pProcs[i]) delete _pProcs[i]; + } + //if (_pGui) delete _pGui; + //if (_pSceneCam) delete _pSceneCam; + //if (_pStimulus) delete _pStimulus; + //if (_pMarker) delete _pMarker; + //if (_pImageProc) delete _pImageProc; + //if (_pEyeTrack) delete _pEyeTrack; + //if (_pTobiiREST) delete _pTobiiREST; + //if (_pBital) delete _pBital; } // ������ bool ECTrainer::Process() { - if (!_pGui->Init(_hInstance)) return false; - if (!_pSceneCam->Init()) return false; - if (!_pStimulus->Init()) return false; - if (!_pImageProc->Init()) return false; - if (!_pEyeTrack->Init()) return false; - if (!_pTobiiREST->Init()) return false; + if (!((ECTrainerGUI*)_pProcs[GUI])->Init(_hInstance)) return false; + for (int i = 0; i < NUM; i++) { + if (!_pProcs[i]->Init()) return false; + } + //if (!_pGui->Init(_hInstance)) return false; + //if (!_pSceneCam->Init()) return false; + //if (!_pStimulus->Init()) return false; + //if (!_pImageProc->Init()) return false; + //if (!_pEyeTrack->Init()) return false; + //if (!_pTobiiREST->Init()) return false; + //if (!_pBital->Init()) return false; - DWORD dwThreadIdSceneCam, dwThreadIdStimulus, dwThreadIdImageProc, dwThreadIdEyeTrack, dwThreadIdKeepAlive, dwThreadTobiiREST; - HANDLE hThreadSceneCam = CreateThread(NULL, 0, ThreadEntry, _pSceneCam, 0, &dwThreadIdSceneCam); - HANDLE hThreadStimulus = CreateThread(NULL, 0, ThreadEntry, _pStimulus, 0, &dwThreadIdStimulus); - HANDLE hThreadImageProc = CreateThread(NULL, 0, ThreadEntry, _pImageProc, 0, &dwThreadIdImageProc); - HANDLE hThreadEyeTrack = CreateThread(NULL, 0, ThreadEntry, _pEyeTrack, 0, &dwThreadIdEyeTrack); - HANDLE hThreadKeepAlive = CreateThread(NULL, 0, KeepAliveThreadEntry, this, 0, &dwThreadIdKeepAlive); - HANDLE hThreadTobiiREST = CreateThread(NULL, 0, ThreadEntry, _pTobiiREST, 0, &dwThreadTobiiREST); + const int N_THREADS = 7; + DWORD thIds[N_THREADS]; + HANDLE thHandles[N_THREADS]; + //DWORD dwThreadIdSceneCam, dwThreadIdStimulus, dwThreadIdImageProc, dwThreadIdEyeTrack, dwThreadIdKeepAlive, dwThreadIdTobiiREST, dwThreadIdBital; + thHandles[0] = CreateThread(NULL, 0, KeepAliveThreadEntry, this, 0, &thIds[0]); + for (int i = 1; i < NUM; i++) { + thHandles[i] = CreateThread(NULL, 0, ThreadEntry, _pProcs[i], 0, &thIds[i]); + } + //thHandles[0] = CreateThread(NULL, 0, ThreadEntry, _pSceneCam, 0, &thIds[0]); + //thHandles[1] = CreateThread(NULL, 0, ThreadEntry, _pStimulus, 0, &thIds[1]); + //thHandles[2] = CreateThread(NULL, 0, ThreadEntry, _pImageProc, 0, &thIds[2]); + //thHandles[3] = CreateThread(NULL, 0, ThreadEntry, _pEyeTrack, 0, &thIds[3]); + //thHandles[5] = CreateThread(NULL, 0, ThreadEntry, _pTobiiREST, 0, &thIds[5]); + //thHandles[6] = CreateThread(NULL, 0, ThreadEntry, _pBital, 0, &thIds[6]); - _pGui->MainLoop(); + //_pGui->MainLoop(); + _pProcs[GUI]->MainLoop(); - HANDLE handles[] = { hThreadSceneCam , hThreadStimulus, hThreadImageProc, hThreadEyeTrack, hThreadKeepAlive, hThreadTobiiREST }; + //HANDLE handles[] = { hThreadSceneCam , hThreadStimulus, hThreadImageProc, hThreadEyeTrack, hThreadKeepAlive, hThreadTobiiREST, hThreadBital }; DWORD timeOut = 1000; // �^�C���A�E�g(ms) - if (WaitForMultipleObjects(sizeof(handles) / sizeof(HANDLE), handles, TRUE, timeOut) != WAIT_TIMEOUT) { + if (WaitForMultipleObjects(N_THREADS, thHandles, TRUE, timeOut) != WAIT_TIMEOUT) { OutputDebugString(_T("All threads stopped sccessfully.\n")); } else { OutputDebugString(_T("Waiting threads stop timeout.\n")); } - if (hThreadSceneCam) CloseHandle(hThreadSceneCam); - if (hThreadStimulus) CloseHandle(hThreadStimulus); - if (hThreadImageProc) CloseHandle(hThreadImageProc); - if (hThreadEyeTrack) CloseHandle(hThreadEyeTrack); - if (hThreadKeepAlive) CloseHandle(hThreadKeepAlive); - if (hThreadTobiiREST) CloseHandle(hThreadTobiiREST); + for (int i = 0; i < N_THREADS; i++) { + if (thHandles[i]) CloseHandle(thHandles[i]); + } + //if (hThreadSceneCam) CloseHandle(hThreadSceneCam); + //if (hThreadStimulus) CloseHandle(hThreadStimulus); + //if (hThreadImageProc) CloseHandle(hThreadImageProc); + //if (hThreadEyeTrack) CloseHandle(hThreadEyeTrack); + //if (hThreadKeepAlive) CloseHandle(hThreadKeepAlive); + //if (hThreadTobiiREST) CloseHandle(hThreadTobiiREST); + //if (hThreadBital) CloseHandle(hThreadBital); return true; } // �L�����u���[�V�����J�n void ECTrainer::CalibStart() { - _pStimulus->SetPage(Stimulus::PAGES::CALIB); - _pTobiiREST->Start(); + ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::CALIB); + ((TobiiREST*)_pProcs[REST])->Start(); } // �L�����u���[�V�������ʕ\�� int ECTrainer::CheckCalibResult() { int res = _CalibResult; - if (res > 0) _pStimulus->SetPage(Stimulus::PAGES::CALIB_COMPLETE); - if (res < 0) _pStimulus->SetPage(Stimulus::PAGES::CALIB_FAILED); + if (res > 0) ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::CALIB_COMPLETE); + if (res < 0) ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::CALIB_FAILED); _CalibResult = 0; return res; } // �J�n void ECTrainer::StartStim() { - _pStimulus->SetPage(Stimulus::PAGES::START); + ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::START); } // �J�n void ECTrainer::StopStim() { - _pStimulus->SetPage(Stimulus::PAGES::STOP); + ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::STOP); } // ���� void ECTrainer::NextStim() { - _pStimulus->SetPage(Stimulus::PAGES::NEXT); + ((Stimulus*)_pProcs[STIM])->SetPage(Stimulus::PAGES::NEXT); } // ����摜�o�b�t�@�ɉ摜��ݒ� void ECTrainer::SetSceneBuffer(cv::Mat& img) { - _pGui->SetSceneBuffer(img); + ((ECTrainerGUI*)_pProcs[GUI])->SetSceneBuffer(img); } // �h���摜�o�b�t�@�ɉ摜��ݒ� void ECTrainer::SetDispBuffer(cv::Mat& img) { - _pGui->SetDispBuffer(img); + ((ECTrainerGUI*)_pProcs[GUI])->SetDispBuffer(img); } // ���ʃX���b�h�J�n�_ @@ -127,23 +159,23 @@ // KeepAlive�X���b�h�J�n�_ DWORD WINAPI ECTrainer::KeepAliveThreadEntry(LPVOID lpParameter) { - ((ECTrainer*)lpParameter)->_pEyeTrack->KeepAliveLoop(); + ((EyeTrack*)((ECTrainer*)lpParameter)->_pProcs[EYETR])->KeepAliveLoop(); return 0; } // ����摜���̒����_�ݒ� void ECTrainer::SetGazeV(cv::Point gazeV) { - _pEyeTrack->SetGazeV(gazeV); + ((EyeTrack*)_pProcs[EYETR])->SetGazeV(gazeV); } // ����摜���̒����_�擾 cv::Point ECTrainer::GetGazeV() { - return _pEyeTrack->GetGazeV(); + return ((EyeTrack*)_pProcs[EYETR])->GetGazeV(); } // �h���摜���̒����_�擾 cv::Point2f ECTrainer::GetGazeI() { - return _pEyeTrack->GetGazeI(); + return ((EyeTrack*)_pProcs[EYETR])->GetGazeI(); } // �E�ڂ̈ʒu�擾 @@ -160,5 +192,5 @@ // �o�b�e���[�c�ʎ擾 int ECTrainer::BatteryLevel() { - return _pTobiiREST->BatteryLevel(); + return ((TobiiREST*)_pProcs[REST])->BatteryLevel(); } \ No newline at end of file diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h index d0c0129..c7efa56 100644 --- a/ECTrainer2/ECTrainer.h +++ b/ECTrainer2/ECTrainer.h @@ -1,8 +1,6 @@ #pragma once #include -#include -#include #include "myOpenCV.h" #define ADDR "192.168.71.50" @@ -14,23 +12,29 @@ class ImageProc; class EyeTrack; class TobiiREST; +class BitalMonitor; +class BaseProcess; class ECTrainer { private: + enum BLOCK {GUI, IMGPROC, SCNCAM, STIM, EYETR, REST, BITAL, NUM }; HINSTANCE _hInstance; - ECTrainerGUI* _pGui; - SceneCamera* _pSceneCam; - Stimulus* _pStimulus; + BaseProcess* _pProcs[NUM]; + //ECTrainerGUI* _pGui; + //SceneCamera* _pSceneCam; + //Stimulus* _pStimulus; + //ImageProc* _pImageProc; + //EyeTrack* _pEyeTrack; + //TobiiREST* _pTobiiREST; + //BitalMonitor* _pBital; Marker* _pMarker; - ImageProc* _pImageProc; - EyeTrack* _pEyeTrack; - TobiiREST* _pTobiiREST; bool _Running; // ���s���t���O bool _HomographyOK; // �ϊ��s��̊l���L�� int _CalibResult; // �L�����u���[�V�������� 0:�����{ 1:���� -1:���s cv::Size _SceneSize; // ���E�J�����̉摜�T�C�Y std::wstring _MovieToShow; // �Đ����铮��t�@�C�� + int _HeartBeat; // �S���� // �X���b�h�J�n�_ static DWORD WINAPI ThreadEntry(LPVOID lpParameter); @@ -64,25 +68,7 @@ void SetCalibResult(int result) { _CalibResult = result; } void SetMovieToShow(std::wstring file) { _MovieToShow = file; } std::wstring GetMovieToShow() { return _MovieToShow; } + void SetHeartBeat(int hb) { _HeartBeat = hb; } + int GetHeartBeat() { return _HeartBeat; } - static std::wstring Multi2Wide(std::string const& src) - { - //std::size_t converted{}; - //std::vector dest(src.size(), L'\0'); - //if (::_mbstowcs_s_l(&converted, dest.data(), dest.size(), src.data(), _TRUNCATE, ::_create_locale(LC_ALL, "jpn")) != 0) { - // throw std::system_error{ errno, std::system_category() }; - //} - //dest.resize(std::char_traits::length(dest.data())); - //dest.shrink_to_fit(); - //return std::wstring(dest.begin(), dest.end()); - - auto const dest_size = ::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, nullptr, 0U); - std::vector dest(dest_size, L'\0'); - if (::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, dest.data(), dest.size()) == 0) { - throw std::system_error{ static_cast(::GetLastError()), std::system_category() }; - } - dest.resize(std::char_traits::length(dest.data())); - dest.shrink_to_fit(); - return std::wstring(dest.begin(), dest.end()); - } }; diff --git a/ECTrainer2/ECTrainer2.vcxproj b/ECTrainer2/ECTrainer2.vcxproj index 002bd6b..64b857a 100644 --- a/ECTrainer2/ECTrainer2.vcxproj +++ b/ECTrainer2/ECTrainer2.vcxproj @@ -143,9 +143,11 @@ + + @@ -156,13 +158,16 @@ + + + diff --git a/ECTrainer2/ECTrainer2.vcxproj.filters b/ECTrainer2/ECTrainer2.vcxproj.filters index 2499498..719b44b 100644 --- a/ECTrainer2/ECTrainer2.vcxproj.filters +++ b/ECTrainer2/ECTrainer2.vcxproj.filters @@ -48,6 +48,12 @@ ソース ファイル + + ソース ファイル + + + ソース ファイル + @@ -89,6 +95,15 @@ ヘッダー ファイル + + ヘッダー ファイル + + + ヘッダー ファイル + + + ヘッダー ファイル + diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 3ad1eab..f14b0a1 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -10,6 +10,7 @@ #define _WIN32_DCOM // CoInitializeEx�֐��̌Ăяo���ɕK�v + #define CVUI_IMPLEMENTATION #include "cvui.h" @@ -278,6 +279,8 @@ cvui::printf("Battery %d %%", _pEct->BatteryLevel()); bool snapshot = cvui::button(140, 30, "SNAPSHOT"); if (cvui::button(140, 30, "QUIT")) _pEct->Stop(); + cvui::printf("HeartBeat (bpm)", _pEct->GetHeartBeat()); + cvui::text(cv::format("%3d", _pEct->GetHeartBeat()), 2.0); cvui::endColumn(); cvui::text(_MainFrame, SCENE_BUFFER_POS.x, 100, "SCENE CAMERA"); cvui::image(_MainFrame, SCENE_BUFFER_POS.x, SCENE_BUFFER_POS.y, _SceneBuffer); diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index 6b046f1..f5420a9 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -9,6 +9,7 @@ #include #include + LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; } #define CHECK(x) { if(((HRESULT)(x)) < 0) return false; } diff --git a/ECTrainer2/EyeTrack.cpp b/ECTrainer2/EyeTrack.cpp index 367a60b..65b308b 100644 --- a/ECTrainer2/EyeTrack.cpp +++ b/ECTrainer2/EyeTrack.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "EyeTrack.h" #include "ECTrainer.h" #include "Marker.h" diff --git a/ECTrainer2/GComPort.cpp b/ECTrainer2/GComPort.cpp new file mode 100644 index 0000000..c3f64f5 --- /dev/null +++ b/ECTrainer2/GComPort.cpp @@ -0,0 +1,120 @@ +#include "GComPort.h" + +// �R���X�g���N�^ +GComPort::GComPort(void) : + mComHandle(INVALID_HANDLE_VALUE) +{ +} + +// �f�X�g���N�^(�I������) +GComPort::~GComPort(void) +{ + this->Close(); +} + +// �|�[�g��T���ĊJ�� +int GComPort::Open(TCHAR* config) +{ + for (int findPort = 1; findPort < 20; findPort++) { + if (this->Open(findPort, config)) { + this->Send((BYTE*)"s", 1); + Sleep(100); + BYTE buf[256]; + this->Receive(buf, 256); + // TRACE("port %d recv %s\n", findPort, (char*)buf); + if (!strncmp((char*)buf, "OK", 2)) return findPort; + } + } + return 0; +} + +// �|�[�g���J�� +bool GComPort::Open(int port, const TCHAR* config) +{ + // �|�[�g�ԍ������񐶐� + if (port < 1) return false; + TCHAR portStr[256]; + wsprintf(portStr, _T("\\\\.\\COM%d"), port); + + // Com�|�[�g���J�� + mComHandle = CreateFile(portStr, + GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + if (mComHandle == INVALID_HANDLE_VALUE) return false; + + // �|�[�g�ݒ� + DCB dcb; + GetCommState(mComHandle, &dcb); + BuildCommDCB(config, &dcb); + dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fOutxDsrFlow = FALSE; + dcb.fDsrSensitivity = FALSE; + dcb.fAbortOnError = FALSE; + SetCommState(mComHandle, &dcb); + + COMMTIMEOUTS timeout; + GetCommTimeouts(mComHandle, &timeout); + timeout.ReadIntervalTimeout = MAXDWORD; + timeout.ReadTotalTimeoutMultiplier = 1; + timeout.ReadTotalTimeoutConstant = 500; + timeout.WriteTotalTimeoutMultiplier = 1; + timeout.WriteTotalTimeoutConstant = 500; + SetCommTimeouts(mComHandle, &timeout); + + return true; +} + +// �|�[�g��‚��� +void GComPort::Close() +{ + if (mComHandle != INVALID_HANDLE_VALUE) + { + CloseHandle(mComHandle); + mComHandle = INVALID_HANDLE_VALUE; + } +} + +// �f�[�^���M +DWORD GComPort::Send(const BYTE* data, DWORD dataLen) +{ + if (mComHandle == INVALID_HANDLE_VALUE) return 0; + + DWORD sendSize; // ���M�����o�C�g�� + WriteFile(mComHandle, data, dataLen, &sendSize, NULL); + // TRACE("COM SEND: %s", (char*)data); + + return sendSize; +} + +// �f�[�^��M +DWORD GComPort::Receive(BYTE* buffer, DWORD bufferLen) +{ + if (mComHandle == INVALID_HANDLE_VALUE) return 0; + + DWORD errors; + COMSTAT stat; + ClearCommError(mComHandle, &errors, &stat); + DWORD queSize = stat.cbInQue; + if (queSize < 1) return 0; + + if (bufferLen < queSize) queSize = bufferLen; + DWORD receiveSize; // ��M�����o�C�g�� + ReadFile(mComHandle, buffer, queSize, &receiveSize, NULL); + if (receiveSize < bufferLen) buffer[receiveSize] = '\0'; // ��M�f�[�^�ɏI�[������lj� + + // TRACE("COM RECV: %s", (char*)buffer); + + return receiveSize; +} + +// �^�C���A�E�g�t���f�[�^��M +DWORD GComPort::WaitReceive(BYTE* buffer, DWORD bufferLen, const int timeout) +{ + if (mComHandle == INVALID_HANDLE_VALUE) return 0; + + int receiveSize; + for (int i = 0; i < timeout && + (receiveSize = this->Receive(buffer, bufferLen)) < 1; i++) Sleep(1); + + return receiveSize; +} diff --git a/ECTrainer2/GComPort.h b/ECTrainer2/GComPort.h new file mode 100644 index 0000000..ea06251 --- /dev/null +++ b/ECTrainer2/GComPort.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +class GComPort +{ + HANDLE mComHandle; + +public: + + GComPort(void); + ~GComPort(void); + int Open(TCHAR* config); + bool Open(int port, const TCHAR* config); + void Close(); + DWORD Send(const BYTE* data, DWORD dataLen); + DWORD Receive(BYTE* buffer, DWORD bufferLen); + DWORD WaitReceive(BYTE* buffer, DWORD bufferLen, int timeout); +}; diff --git a/ECTrainer2/MyWinUtils.h b/ECTrainer2/MyWinUtils.h index 6f70f09..f6c00a4 100644 --- a/ECTrainer2/MyWinUtils.h +++ b/ECTrainer2/MyWinUtils.h @@ -1 +1,28 @@ #pragma once + +#include +#include +#include +#include +#include + +static std::wstring Multi2Wide(std::string const& src) +{ + //std::size_t converted{}; + //std::vector dest(src.size(), L'\0'); + //if (::_mbstowcs_s_l(&converted, dest.data(), dest.size(), src.data(), _TRUNCATE, ::_create_locale(LC_ALL, "jpn")) != 0) { + // throw std::system_error{ errno, std::system_category() }; + //} + //dest.resize(std::char_traits::length(dest.data())); + //dest.shrink_to_fit(); + //return std::wstring(dest.begin(), dest.end()); + + auto const dest_size = ::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, nullptr, 0U); + std::vector dest(dest_size, L'\0'); + if (::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, dest.data(), (int)dest.size()) == 0) { + throw std::system_error{ static_cast(::GetLastError()), std::system_category() }; + } + dest.resize(std::char_traits::length(dest.data())); + dest.shrink_to_fit(); + return std::wstring(dest.begin(), dest.end()); +} diff --git a/ECTrainer2/StimData.txt b/ECTrainer2/StimData.txt index 5f536df..ab5fab5 100644 --- a/ECTrainer2/StimData.txt +++ b/ECTrainer2/StimData.txt @@ -2,7 +2,5 @@ 1 ../images/CalibCheck2.png 4 _ 0 1 ../images/CalibCheck3.png 4 _ 0 1 ../images/CalibCheck4.png 4 _ 0 -1 ../images/LookNose.png 5 _ 0 -2 ../movies/test1_0525.avi 30 ../movies/test1.csv 2 -1 ../images/LookEyes.png 5 _ 0 -2 ../movies/test0421.avi 30 ../movies/test0421.csv 1 +1 ../images/visit01_004.png 5 _ 0 +2 ../movies/visit01_004.avi 30 ../movies/visit01_004.csv 2 diff --git a/ECTrainer2/Stimulus.cpp b/ECTrainer2/Stimulus.cpp index 8c71060..bf4b6b2 100644 --- a/ECTrainer2/Stimulus.cpp +++ b/ECTrainer2/Stimulus.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "MyWinUtils.h" // �R���X�g���N�^ Stimulus::Stimulus(ECTrainer* pEct, Marker* pMarker) @@ -73,7 +74,7 @@ } _pEct->SetDispBuffer(_DispBuffer); } else { - std::wstring mov = ECTrainer::Multi2Wide(_StimInfoSet[_StimNo].filename); + std::wstring mov = Multi2Wide(_StimInfoSet[_StimNo].filename); _pEct->SetMovieToShow(mov); } return true; diff --git "a/\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270\345\233\263.xlsx" "b/\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270\345\233\263.xlsx" index cc230fc..6d212e7 100644 --- "a/\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270\345\233\263.xlsx" +++ "b/\343\203\241\343\203\203\343\202\273\343\203\274\343\202\270\345\233\263.xlsx" Binary files differ