Skip to content

Commit

Permalink
USB Settings window added.
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-plociennik committed Jul 3, 2013
1 parent 62fadb9 commit c7cb541
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/*
data/*
vc9/gamma-view.suo
vc9/gamma-view.ncb
vc9/gamma-view.vcproj.*
4 changes: 1 addition & 3 deletions src/block_fread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ wxInt32 GammaBlockFileRead::setParam(GammaParam_e param, void* value)

wxThread::ExitCode GammaBlockFileRead::Entry()
{


m_fileName.Assign("D:\\data\\20120813_184157.gvb"); //jednorodnosc
m_fileName.Assign("D:\\git\\gamma-view\\data\\20120813_184157.gvb"); //jednorodnosc
//m_fileName.Assign("20120813_200126.gvb"); //siatka
//m_fileName.Assign("5066901116_002707.gif");

Expand Down
29 changes: 29 additions & 0 deletions src/block_tr_us.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ void GammaBlockTransUS::processData(GammaData* pData)
pushData(pDataOut);
delete pDataOut;
}

wxInt32 GammaBlockTransUS::setParam(GammaParam_e param, void* value)
{
switch(param)
{
case GAMMA_PARAM_SET_TMARKER:
switch(*static_cast<GammaSettingTmarker_e*>(value))
{
case GAMMA_TMARKER_OFF:
m_timeDiv = 0; break;
case GAMMA_TMARKER_1MS:
m_timeDiv = 1; break;
case GAMMA_TMARKER_10MS:
m_timeDiv = 10; break;
case GAMMA_TMARKER_100MS:
m_timeDiv = 100; break;
case GAMMA_TMARKER_240MS:
m_timeDiv = 240; break;
default:
break;
}

break;
default:
return 0;
}

return 1;
}
1 change: 1 addition & 0 deletions src/block_tr_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GammaBlockTransUS : public GammaPipeSegment
GammaBlockTransUS(GammaManager* pManager);

void processData(GammaData* pData);
wxInt32 setParam(GammaParam_e param, void* value);

private:
unsigned long m_timeCounter;
Expand Down
75 changes: 59 additions & 16 deletions src/block_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "block_tr_us.h"
#include <wx/fileconf.h>

bool GammaBlockUSB::DeviceFind()
bool GammaBlockUSB::deviceFind()
{
#ifdef _WIN32
for( m_device = 0; m_device < m_USBDevice->DeviceCount(); m_device++ )
Expand Down Expand Up @@ -39,18 +39,18 @@ bool GammaBlockUSB::DeviceFind()
#endif
}

bool GammaBlockUSB::DeviceInit()
bool GammaBlockUSB::deviceInit()
{
wxConfigBase* config = wxFileConfig::Get();
wxConfigPathChanger changer(config, "/USBDevice/");

#ifdef _WIN32
if( DeviceReset() &&
DeviceSet(GAMMA_SET_ZOOM, config->ReadLong("Zoom", 128)) &&
DeviceSet(GAMMA_SET_SHIFT_X, config->ReadLong("ShiftX", 128)) &&
DeviceSet(GAMMA_SET_SHIFT_Y, config->ReadLong("ShiftY", 128)) &&
DeviceSet(GAMMA_SET_TMARKER, log10(config->ReadDouble("Tmarker", 10)) + 1) &&
DeviceSet(GAMMA_SET_GATE, config->ReadLong("GateOn", 0)) )
if( deviceReset() &&
deviceSet(GAMMA_SET_ZOOM, config->ReadLong("Zoom", 127)) &&
deviceSet(GAMMA_SET_SHIFT_X, config->ReadLong("ShiftX", 127)) &&
deviceSet(GAMMA_SET_SHIFT_Y, config->ReadLong("ShiftY", 127)) &&
deviceSet(GAMMA_SET_TMARKER, log10(config->ReadDouble("Tmarker", 10)) + 1) &&
deviceSet(GAMMA_SET_GATE, config->ReadLong("GateOn", 0)) )
{
wxLogStatus("Device init OK.");
return true;
Expand All @@ -65,22 +65,36 @@ bool GammaBlockUSB::DeviceInit()
#endif
}

bool GammaBlockUSB::DeviceReset()
bool GammaBlockUSB::deviceReset()
{
#ifdef _WIN32
return m_USBDevice->Reset();
if(m_USBDevice->IsOpen())
{
return m_USBDevice->Reset();
}
else
{
return false;
}
#else
return true;
#endif
}

bool GammaBlockUSB::DeviceSet(unsigned char setting, unsigned char value)
bool GammaBlockUSB::deviceSet(GammaSetting_e setting, wxUint8 value)
{
#ifdef _WIN32
unsigned char buffer[] = {setting, value};
long int length = 2;
if(m_USBDevice->IsOpen())
{
UCHAR buffer[] = {static_cast<UCHAR>(setting), value};
LONG length = sizeof(buffer);

return m_USBDevice->BulkOutEndPt->XferData(buffer, length);
return m_USBDevice->BulkOutEndPt->XferData(buffer, length);
}
else
{
return false;
}
#else
return true;
#endif
Expand All @@ -91,14 +105,13 @@ wxThread::ExitCode GammaBlockUSB::Entry()
//wxMutexLocker locker(m_processDataMutex);

#ifdef _WIN32
if( DeviceFind() && DeviceInit() )
if(deviceFind() && deviceInit() && m_USBDevice->IsOpen())
{
while( shouldBeRunning() )
{
GammaDataUSB* pDataOut(new GammaDataUSB);
long int length = 0x200;

//pDataOut->dateTime = wxDateTime::UNow();
m_USBDevice->BulkInEndPt->XferData(pDataOut->data, length);
wxASSERT(0x200 == length);

Expand All @@ -123,3 +136,33 @@ GammaBlockUSB::~GammaBlockUSB()
delete m_USBDevice;
#endif
}

wxInt32 GammaBlockUSB::setParam(GammaParam_e param, void* value)
{
wxUint8 value8 = *static_cast<wxUint8*>(value);
GammaSetting_e setting = GAMMA_SET_MAX;

switch(param)
{
case GAMMA_PARAM_SET_ZOOM:
setting = GAMMA_SET_ZOOM; break;
case GAMMA_PARAM_SET_SHIFT_X:
setting = GAMMA_SET_SHIFT_X; break;
case GAMMA_PARAM_SET_SHIFT_Y:
setting = GAMMA_SET_SHIFT_Y; break;
case GAMMA_PARAM_SET_TMARKER:
{
setting = GAMMA_SET_TMARKER;
GammaSettingTmarker_e tMarker = *static_cast<GammaSettingTmarker_e*>(value);
deviceSet(setting, tMarker);
return 1;
}
case GAMMA_PARAM_SET_GATE:
setting = GAMMA_SET_GATE; break;
default:
return 0;
}

deviceSet(setting, value8);
return 1;
}
12 changes: 7 additions & 5 deletions src/block_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define _GAMMA_VIEW_BLOCK_USB_H_

#ifdef _WIN32
#include <windows.h>
#include "CyAPI.h"
#endif

Expand All @@ -21,11 +22,12 @@ class GammaBlockUSB : public GammaPipeHead
GammaBlockUSB(GammaManager* pManager);
~GammaBlockUSB();

bool DeviceFind();
bool DeviceInit();
bool DeviceOpen();
bool DeviceReset();
bool DeviceSet(unsigned char setting, unsigned char value);
bool deviceFind();
bool deviceInit();
bool deviceOpen();
bool deviceReset();
bool deviceSet(GammaSetting_e setting, wxUint8 value);
wxInt32 setParam(GammaParam_e param, void* value);

protected:
wxThread::ExitCode Entry();
Expand Down
176 changes: 176 additions & 0 deletions src/d_settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
* @file d_settings.cpp
* @brief USB Settings Dialog
* @author Mateusz Plociennik
* @data 2013-07-01
*/

#include "d_settings.h"

enum
{
ID_GAMMA_SET_ZOOM = 10100,
ID_GAMMA_SET_SHIFT_X,
ID_GAMMA_SET_SHIFT_Y,
ID_GAMMA_SET_TMARKER,
ID_GAMMA_SET_GATE,
};

wxBEGIN_EVENT_TABLE(GammaUsbSettingsDialog, wxDialog)
EVT_CLOSE(GammaUsbSettingsDialog::onClose)
EVT_SPINCTRL(ID_GAMMA_SET_ZOOM, GammaUsbSettingsDialog::onSpinCtrl)
EVT_SPINCTRL(ID_GAMMA_SET_SHIFT_X, GammaUsbSettingsDialog::onSpinCtrl)
EVT_SPINCTRL(ID_GAMMA_SET_SHIFT_Y, GammaUsbSettingsDialog::onSpinCtrl)
EVT_CHOICE(ID_GAMMA_SET_TMARKER, GammaUsbSettingsDialog::onChoice)
EVT_CHOICE(ID_GAMMA_SET_GATE, GammaUsbSettingsDialog::onChoice)
EVT_BUTTON(wxID_OK, GammaUsbSettingsDialog::onButtonOk)
EVT_BUTTON(wxID_CANCEL, GammaUsbSettingsDialog::onButtonCancel)
wxEND_EVENT_TABLE()

GammaUsbSettingsDialog::GammaUsbSettingsDialog(GammaManager* pManager)
: wxDialog(NULL, wxID_ANY, _("USB Settings"))
, GammaPipeMgmt(pManager)
{
wxLogStatus("%s()", __FUNCTION__);

wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

// USB Settings

wxStaticBox* settingsBox = new wxStaticBox(this, wxID_ANY, _("USB Settings"));
wxStaticBoxSizer* settingsBoxSizer = new wxStaticBoxSizer(settingsBox, wxVERTICAL);

wxFlexGridSizer* settingsBoxGridSizer = new wxFlexGridSizer(0, 2, wxSize(0, 0));
settingsBoxGridSizer->AddGrowableCol(1);


wxStaticText* zoomLabel = new wxStaticText(this, wxID_ANY, wxT("Zoom: "));
settingsBoxGridSizer->Add(zoomLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

m_zoomSpinCtrl = new wxSpinCtrl(this, ID_GAMMA_SET_ZOOM, wxT("127"));
m_zoomSpinCtrl->SetMax(255);
settingsBoxGridSizer->Add(m_zoomSpinCtrl, 0, wxALL|wxEXPAND, 5);


wxStaticText* shiftXLabel = new wxStaticText(this, wxID_ANY, wxT("Shift X: "));
settingsBoxGridSizer->Add(shiftXLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

m_shiftXSpinCtrl = new wxSpinCtrl(this, ID_GAMMA_SET_SHIFT_X, wxT("127"));
m_shiftXSpinCtrl->SetMax(255);
settingsBoxGridSizer->Add(m_shiftXSpinCtrl, 0, wxALL|wxEXPAND, 5);


wxStaticText* shiftYLabel = new wxStaticText(this, wxID_ANY, wxT("Shift Y: "));
settingsBoxGridSizer->Add(shiftYLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

m_shiftYSpinCtrl = new wxSpinCtrl(this, ID_GAMMA_SET_SHIFT_Y, wxT("127"));
m_shiftYSpinCtrl->SetMax(255);
settingsBoxGridSizer->Add(m_shiftYSpinCtrl, 0, wxALL|wxEXPAND, 5);


wxStaticText* timeMarkerLabel = new wxStaticText(this, wxID_ANY, wxT("Time Marker: "));
settingsBoxGridSizer->Add(timeMarkerLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

m_timeMarkerChoice = new wxChoice(this, ID_GAMMA_SET_TMARKER);
m_timeMarkerChoice->Insert(wxT("Off"), GAMMA_TMARKER_OFF);
m_timeMarkerChoice->Insert(wxT("1 ms"), GAMMA_TMARKER_1MS);
m_timeMarkerChoice->Insert(wxT("10 ms"), GAMMA_TMARKER_10MS);
m_timeMarkerChoice->Insert(wxT("100 ms"), GAMMA_TMARKER_100MS);
m_timeMarkerChoice->Insert(wxT("240 ms"), GAMMA_TMARKER_240MS);
m_timeMarkerChoice->Select(GAMMA_TMARKER_10MS);
settingsBoxGridSizer->Add(m_timeMarkerChoice, 0, wxALL|wxEXPAND, 5);


wxStaticText* gateLabel = new wxStaticText(this, wxID_ANY, wxT("Gate: "));
settingsBoxGridSizer->Add(gateLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

m_gateChoice = new wxChoice(this, ID_GAMMA_SET_GATE);
m_gateChoice->Insert(wxT("Off"), 0);
m_gateChoice->Insert(wxT("On"), 1);
m_gateChoice->Select(0);
settingsBoxGridSizer->Add(m_gateChoice, 0, wxALL|wxEXPAND, 5);

settingsBoxSizer->Add(settingsBoxGridSizer, 0, wxALL|wxEXPAND, 5);
mainSizer->Add(settingsBoxSizer, 0, wxALL|wxEXPAND, 5);


wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
sdbSizer->AddButton(new wxButton(this, wxID_OK));
sdbSizer->AddButton(new wxButton(this, wxID_CANCEL));
sdbSizer->Realize();

mainSizer->Add(sdbSizer, 0, wxALL|wxEXPAND, 5);

this->SetSizerAndFit(mainSizer);

Show();
}

GammaUsbSettingsDialog::~GammaUsbSettingsDialog()
{
}

void GammaUsbSettingsDialog::onClose(wxCloseEvent& WXUNUSED(event))
{
this->Destroy();
}

void GammaUsbSettingsDialog::onButtonCancel(wxCommandEvent& WXUNUSED(event))
{
wxLogStatus("%s()", __FUNCTION__);
this->Close(true);
}

void GammaUsbSettingsDialog::onButtonOk(wxCommandEvent& WXUNUSED(event))
{
wxLogStatus("%s()", __FUNCTION__);

// TODO

this->Close(true);
}

void GammaUsbSettingsDialog::onSpinCtrl(wxSpinEvent& event)
{
wxUint8 value = event.GetValue();

switch(event.GetId())
{
case ID_GAMMA_SET_ZOOM:
getManager()->DataTierSetParam(GAMMA_PARAM_SET_ZOOM, &value);
break;
case ID_GAMMA_SET_SHIFT_X:
getManager()->DataTierSetParam(GAMMA_PARAM_SET_SHIFT_X, &value);
break;
case ID_GAMMA_SET_SHIFT_Y:
getManager()->DataTierSetParam(GAMMA_PARAM_SET_SHIFT_Y, &value);
break;
default:
return;
}
}

void GammaUsbSettingsDialog::onChoice(wxCommandEvent& event)
{
wxLogStatus("%s()", __FUNCTION__);



switch(event.GetId())
{
case ID_GAMMA_SET_TMARKER:
{
GammaSettingTmarker_e tMarker = static_cast<GammaSettingTmarker_e>(event.GetSelection());
getManager()->DataTierSetParam(GAMMA_PARAM_SET_TMARKER, &tMarker);
break;
}
case ID_GAMMA_SET_GATE:
{
wxUint8 value = event.GetSelection();
getManager()->DataTierSetParam(GAMMA_PARAM_SET_GATE, &value);
}
break;
default:
return;
}
}
Loading

0 comments on commit c7cb541

Please sign in to comment.