Skip to content

Commit

Permalink
Add check if scope has CONTROL_SETCOUPLING controlCode before sending it
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Siegert committed Oct 17, 2019
1 parent 548c787 commit 3f6b16c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
10 changes: 8 additions & 2 deletions openhantek/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ set(EXECTYPE "")
if(WIN32 AND MINGW)
set(EXECTYPE WIN32)
endif()
if(APPLE)
set(EXECTYPE MACOSX_BUNDLE)
endif()

# make executable
add_executable(${PROJECT_NAME} ${EXECTYPE} ${SRC} ${HEADERS} ${UI} ${QRC} ${TRANSLATION_BIN_FILES} ${TRANSLATION_QRC})
Expand Down Expand Up @@ -66,7 +69,10 @@ if(NOT WIN32)
endif()

# install commands
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "bin")

if (APPLE)
install(TARGETS ${PROJECT_NAME} BUNDLE DESTINATION ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/MacOS/${PROJECT_NAME})
else()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "bin")
endif()
include(../cmake/copy_qt5_dlls_to_bin_dir.cmake)

26 changes: 12 additions & 14 deletions openhantek/src/docks/VoltageDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QDockWidget>
#include <QLabel>
#include <QSignalBlocker>
#include <QDebug>

#include <cmath>

Expand Down Expand Up @@ -44,17 +45,17 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio
dockLayout = new QGridLayout();
dockLayout->setColumnMinimumWidth(0, 64);
dockLayout->setColumnStretch(1, 1);

dockLayout->setSpacing(5);
// Initialize elements
int row = 0;
for (ChannelID channel = 0; channel < scope->voltage.size(); ++channel) {
ChannelBlock b;

b.miscComboBox=(new QComboBox());
b.gainComboBox=(new QComboBox());
b.invertCheckBox=(new QCheckBox(tr("Invert")));
b.attnCheckBox=(new QCheckBox(tr("X10")));
b.usedCheckBox=(new QCheckBox(scope->voltage[channel].name));
b.miscComboBox = new QComboBox();
b.gainComboBox = new QComboBox();
b.invertCheckBox = new QCheckBox(tr("Invert"));
b.attnCheckBox = new QCheckBox(tr("x10"));
b.usedCheckBox = new QCheckBox(scope->voltage[channel].name);

channelBlocks.push_back(std::move(b));

Expand Down Expand Up @@ -93,12 +94,12 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio

connect(b.gainComboBox, SELECT<int>::OVERLOAD_OF(&QComboBox::currentIndexChanged), [this,channel](int index) {
this->scope->voltage[channel].gainStepIndex = (unsigned)index;
emit gainChanged(channel, this->scope->gain(channel));
emit gainChanged( channel, this->scope->gain(channel) );
});
connect(b.attnCheckBox, &QAbstractButton::toggled, [this,channel](bool attn) {
this->setAttn( channel, attn );
this->scope->voltage[channel].probeUsed = attn;
this->scope->voltage[channel].probeAttn = attn ? ATTENUATION : 1;
setAttn( channel, attn );
emit probeAttnChanged( channel, attn, attn ? ATTENUATION : 1 ); // make sure to set the probe first, since this will influence the gain
emit gainChanged(channel, this->scope->gain(channel));
});
Expand All @@ -107,11 +108,11 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio
emit invertedChanged( channel, checked );
});
connect(b.miscComboBox, SELECT<int>::OVERLOAD_OF(&QComboBox::currentIndexChanged), [this,channel,spec,scope](int index) {
this->scope->voltage[channel].couplingOrMathIndex = (unsigned)index;
if (channel < spec->channels) {
this->setCoupling(channel, (unsigned)index);
//setCoupling(channel, (unsigned)index);
emit couplingChanged(channel, scope->coupling(channel, spec));
} else {
this->scope->voltage[channel].couplingOrMathIndex = (unsigned)index;
emit modeChanged(Dso::getMathMode(this->scope->voltage[channel]));
}
});
Expand All @@ -136,8 +137,7 @@ void VoltageDock::setCoupling(ChannelID channel, unsigned couplingIndex) {
if (channel >= spec->channels) return;
if (couplingIndex >= spec->couplings.size()) return;
QSignalBlocker blocker(channelBlocks[channel].miscComboBox);
channelBlocks[channel].miscComboBox->setCurrentIndex((int)couplingIndex);
this->scope->voltage[channel].couplingOrMathIndex = couplingIndex;
channelBlocks[channel].miscComboBox->setCurrentIndex((int)couplingIndex);
}

void VoltageDock::setGain(ChannelID channel, unsigned gainStepIndex) {
Expand All @@ -155,8 +155,6 @@ void VoltageDock::setAttn(ChannelID channel, bool attn) {
channelBlocks[channel].gainComboBox->addItems( attn ? attnStrings : gainStrings );
channelBlocks[channel].gainComboBox->setCurrentIndex( index );
channelBlocks[channel].attnCheckBox->setChecked(attn);
this->scope->voltage[channel].probeUsed = attn;
this->scope->voltage[channel].probeAttn = attn ? ATTENUATION : 1.0;
}

void VoltageDock::setMode(unsigned mathModeIndex) {
Expand Down
10 changes: 7 additions & 3 deletions openhantek/src/hantekdso/hantekdsocontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ Dso::ErrorCode HantekDsoControl::setCoupling(ChannelID channel, Dso::Coupling co
if (channel >= specification->channels)
return Dso::ErrorCode::PARAMETER;

modifyCommand<ControlSetCoupling>(ControlCode::CONTROL_SETCOUPLING)
->setCoupling(channel, coupling == Dso::Coupling::DC);

if (hasCommand(ControlCode::CONTROL_SETCOUPLING)) // don't send command if it is not implemented (like on the 6022)
modifyCommand<ControlSetCoupling>(ControlCode::CONTROL_SETCOUPLING)
->setCoupling(channel, coupling == Dso::Coupling::DC);
controlsettings.voltage[channel].coupling = coupling;
return Dso::ErrorCode::NONE;
}
Expand Down Expand Up @@ -734,6 +734,10 @@ Dso::ErrorCode HantekDsoControl::stringCommand(const QString &commandString) {
return Dso::ErrorCode::UNSUPPORTED;
}

bool HantekDsoControl::hasCommand(Hantek::ControlCode code)
{
return (control[uint8_t(code)] != 0);
}

void HantekDsoControl::addCommand(ControlCommand *newCommand, bool pending) {
newCommand->pending = pending;
Expand Down
1 change: 1 addition & 0 deletions openhantek/src/hantekdso/hantekdsocontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class HantekDsoControl : public QObject {
/// \return See ::Dso::ErrorCode.
Dso::ErrorCode stringCommand(const QString &commandString);

bool hasCommand(Hantek::ControlCode code);
void addCommand(ControlCommand *newCommand, bool pending = true);
template <class T> T *modifyCommand(Hantek::ControlCode code) {
control[(uint8_t)code]->pending = true;
Expand Down

0 comments on commit 3f6b16c

Please sign in to comment.