Isodriver refactor - part 1 (#81)

* isodriver.h: reflow comments, one declaration/line

* move delay to a struct that handles display settings

* Make changes related to isoDriver::window

 - move isoDriver::window to display struct
 - remove isoDriver::windowAtPause
 - remove isoDriver::setWindow
 - call isoDriver::timeWindowUpdated signal where deemed necessary

* Make changes related to isoDriver display settings

 - move x0, y0, x1, and y1 from isoDriver to DisplayControl
 - Replace some ternaries with std::max and std::min
 - Add some comments

* Move topRange and botRange from isoDriver into DisplayControl

* Move most of isoDriver::setVoltageRange into DisplayControl
This commit is contained in:
Sebastián Mestre 2019-05-11 20:58:10 -03:00 committed by Chris Esposito
parent 0c1604cb5e
commit b0e1d1eaf4
3 changed files with 242 additions and 207 deletions

View File

@ -45,12 +45,6 @@ void isoDriver::setAxes(QCustomPlot *newAxes){
qDebug() << "axes = " << axes;
}
void isoDriver::setWindow(int newWindow){
window = pow( (double)10, ( (double)newWindow / 10) );
windowAtPause = window;
qDebug() << "window = " << window;
}
void isoDriver::timerTick(void){
//qDebug() << "isoDriver SEZ Tick!";
if(firstFrame){
@ -216,8 +210,8 @@ void isoDriver::analogConvert(short *shortPtr, QVector<double> *doublePtr, int T
void isoDriver::digitalConvert(short *shortPtr, QVector<double> *doublePtr){
double *data = doublePtr->data();
double top = topRange - (topRange - botRange)/10;
double bot = botRange + (topRange - botRange)/10;
double top = display.topRange - (display.topRange - display.botRange) / 10;
double bot = display.botRange + (display.topRange - display.botRange) / 10;
for (int i=0;i<GRAPH_SAMPLES;i++){
data[i] = shortPtr[i] ? top : bot;
}
@ -232,7 +226,6 @@ void isoDriver::fileStreamConvert(float *floatPtr, QVector<double> *doublePtr){
}
void isoDriver::startTimer(){
/*if (isoTimer!=NULL){
delete isoTimer;
@ -255,70 +248,103 @@ void isoDriver::setVisible_CH2(bool visible){
axes->graph(1)->setVisible(visible);
}
void isoDriver::setVoltageRange(QWheelEvent *event){
void isoDriver::setVoltageRange(QWheelEvent* event)
{
if(doNotTouchGraph && !fileModeEnabled) return;
bool isProperlyPaused = properlyPaused();
double maxWindowSize = fileModeEnabled ? daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
display.setVoltageRange(event, isProperlyPaused, maxWindowSize, axes);
if (!(event->modifiers() == Qt::ControlModifier))
if (autoGainEnabled && !isProperlyPaused)
autoGain();
}
void DisplayControl::setVoltageRange (QWheelEvent* event, bool isProperlyPaused, double maxWindowSize, QCustomPlot* axes)
{
if (!(event->modifiers() == Qt::ControlModifier)){
double c = (topRange - botRange) / (double)400;
QCPRange range = axes->yAxis->range();
double pixPct = (double)100 - ((double)100 * (((double)axes->yAxis->pixelToCoord(event->y())-range.lower) / (double)(range.upper - range.lower)));
if (pixPct<0) pixPct = 0;
if (pixPct>100) pixPct = 100;
double pixPct = (double)100 - ((double)100 * (((double)axes->yAxis->pixelToCoord(event->y())-range.lower) / range.size()));
if (pixPct < 0) pixPct = 0;
if (pixPct > 100) pixPct = 100;
qDebug() << "WHEEL @ " << pixPct << "%";
qDebug() << range.upper;
//qDebug() << event->delta();
if (event->delta()==120){
topRange -= c* ((double)pixPct);
botRange += c* ((double)100 - (double)pixPct);
topRange -= c * ((double)pixPct);
botRange += c * ((double)100 - (double)pixPct);
}
else{
topRange += c* ((double)pixPct);
botRange -= c* ((double)100 - (double)pixPct);
topRange += c * ((double)pixPct);
botRange -= c * ((double)100 - (double)pixPct);
}
if (topRange > (double)20) topRange = (double)20;
if (botRange <- (double)20) botRange = (double)-20;
if (autoGainEnabled && !properlyPaused()) autoGain();
if (botRange < -(double)20) botRange = (double)-20;
topRangeUpdated(topRange);
botRangeUpdated(botRange);
}
else if(properlyPaused()){
else
{
double c = (window) / (double)200;
QCPRange range = axes->xAxis->range();
double pixPct = (double)100 * (((double)axes->xAxis->pixelToCoord(event->x())-range.lower) / (double)(range.upper - range.lower));
if (pixPct<0) pixPct = 0;
if (pixPct>100) pixPct = 100;
double pixPct = (double)100 * ((double)axes->xAxis->pixelToCoord(event->x()) - range.lower);
pixPct /= isProperlyPaused ? (double)(range.upper - range.lower)
: (double)(window);
if (pixPct < 0)
pixPct = 0;
if (pixPct > 100)
pixPct = 100;
qDebug() << "WHEEL @ " << pixPct << "%";
qDebug() << event->delta();
if (event->delta()==120){
window -= c* ((double)pixPct);
delay += c* ((double)100 - (double)pixPct) * pixPct/100;
delayUpdated(delay);
}
else{
window += c* ((double)pixPct);
delay -= c* ((double)100 - (double)pixPct) * pixPct/100;
delayUpdated(delay);
}
double mws = fileModeEnabled ? daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
if (window > mws)
if (not isProperlyPaused)
{
window = mws;
qDebug() << "TIGGERED";
qDebug() << "upper = " << range.upper << "lower = " << range.lower;
qDebug() << "window = " << window;
qDebug() << c * ((double)pixPct);
qDebug() << c * ((double)100 - (double)pixPct) * pixPct / 100;
}
if (event->delta() == 120)
{
window -= c * ((double)pixPct);
delay += c * ((double)100 - (double)pixPct) * pixPct / 100;
}
else
{
window += c * ((double)pixPct);
delay -= c * ((double)100 - (double)pixPct) * pixPct / 100;
}
// NOTE: delayUpdated and timeWindowUpdated are called more than once beyond here,
// maybe they should only be called once at the end?
delayUpdated(delay);
timeWindowUpdated(window);
qDebug() << window << delay;
if (window > maxWindowSize)
{
window = maxWindowSize;
timeWindowUpdated(window);
}
if ((window + delay) > mws)
if ((window + delay) > maxWindowSize)
{
delay -= window + delay - mws;
delay = maxWindowSize - window;
delayUpdated(delay);
}
if (delay < 0)
@ -326,54 +352,9 @@ void isoDriver::setVoltageRange(QWheelEvent *event){
delay = 0;
delayUpdated(delay);
}
qDebug() << window << delay;
} else {
qDebug() << "TIGGERED";
double c = (window) / (double)200;
QCPRange range = axes->xAxis->range();
double pixPct = (double)100 * (((double)axes->xAxis->pixelToCoord(event->x())-range.lower) / (double)(window));
if (pixPct<0) pixPct = 0;
if (pixPct>100) pixPct = 100;
qDebug() << "WHEEL @ " << pixPct << "%";
qDebug() << event->delta();
qDebug() << "upper = " << range.upper << "lower = " << range.lower;
qDebug() << "window = " << window;
qDebug() << c* ((double)pixPct);
qDebug() << c* ((double)100 - (double)pixPct) * pixPct/100;
if (event->delta()==120){
window -= c* ((double)pixPct);
delay += c* ((double)100 - (double)pixPct) * pixPct/100;
delayUpdated(delay);
timeWindowUpdated(window);
}
else{
window += c* ((double)pixPct);
delay -= c* ((double)100 - (double)pixPct) * pixPct/100;
delayUpdated(delay);
timeWindowUpdated(window);
}
double mws = fileModeEnabled ? daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
if (window > mws) window = mws;
if ((window + delay) > mws)
{
delay -= window + delay - mws;
delayUpdated(delay);
}
if (delay < 0)
{
delay = 0;
delayUpdated(delay);
}
windowAtPause = window;
qDebug() << window << delay;
}
//changeTimeAxis(event->delta()==-120);
//qDebug() << window;
}
bool isoDriver::properlyPaused(){
@ -397,10 +378,9 @@ void isoDriver::pauseEnable_CH1(bool enabled){
paused_CH1 = enabled;
if(!properlyPaused()) {
delay = 0;
delayUpdated(delay);
display.delay = 0;
delayUpdated(display.delay);
if (autoGainEnabled) autoGain();
//window = windowAtPause;
}
if(!enabled) clearBuffers(1,0,1);
@ -412,10 +392,9 @@ void isoDriver::pauseEnable_CH2(bool enabled){
paused_CH2 = enabled;
if(!properlyPaused()){
delay = 0;
delayUpdated(delay);
display.delay = 0;
delayUpdated(display.delay);
if (autoGainEnabled) autoGain();
//window = windowAtPause;
}
if(!enabled) clearBuffers(0,1,0);
@ -425,9 +404,8 @@ void isoDriver::pauseEnable_multimeter(bool enabled){
paused_multimeter = enabled;
if(!properlyPaused()) {
delay = 0;
delayUpdated(delay);
//window = windowAtPause;
display.delay = 0;
delayUpdated(display.delay);
}
if(!enabled) clearBuffers(1,0,0);
@ -436,8 +414,8 @@ void isoDriver::pauseEnable_multimeter(bool enabled){
void isoDriver::autoGain(){
double maxgain = vcc / (2 * ((double)topRange - vref) * R4/(R3+R4));
double mingain = vcc / (2 * ((double)botRange - vref) * R4/(R3+R4));
double maxgain = vcc / (2 * ((double)display.topRange - vref) * R4/(R3+R4));
double mingain = vcc / (2 * ((double)display.botRange - vref) * R4/(R3+R4));
maxgain = fmin(fabs(mingain) * 0.98, fabs(maxgain) * 0.98);
double snap[8] = {64, 32, 16, 8, 4, 2, 1, 0.5};
@ -477,16 +455,16 @@ void isoDriver::graphMousePress(QMouseEvent *event){
qDebug() << event->button();
if (horiCursorEnabled && (event->button() == Qt::LeftButton)){
placingHoriAxes = true;
y0 = axes->yAxis->pixelToCoord(event->y());
display.y0 = axes->yAxis->pixelToCoord(event->y());
#ifndef PLATFORM_ANDROID
}else if(vertCursorEnabled && (event->button() == Qt::RightButton)){
#else
}if(vertCursorEnabled){
#endif
placingVertAxes = true;
x0 = axes->xAxis->pixelToCoord(event->x());
display.x0 = axes->xAxis->pixelToCoord(event->x());
}
qDebug() << "x0 =" << x0 << "x1 =" << x1 << "y0 =" << y0 << "y1 =" << y1;
qDebug() << "x0 =" << display.x0 << "x1 =" << display.x1 << "y0 =" << display.y0 << "y1 =" << display.y1;
}
void isoDriver::graphMouseRelease(QMouseEvent *event){
@ -499,18 +477,18 @@ void isoDriver::graphMouseRelease(QMouseEvent *event){
#endif
placingVertAxes = false;
}
qDebug() << "x0 =" << x0 << "x1 =" << x1 << "y0 =" << y0 << "y1 =" << y1;
qDebug() << "x0 =" << display.x0 << "x1 =" << display.x1 << "y0 =" << display.y0 << "y1 =" << display.y1;
}
void isoDriver::graphMouseMove(QMouseEvent *event){
if(horiCursorEnabled && placingHoriAxes){
y1 = axes->yAxis->pixelToCoord(event->y());
display.y1 = axes->yAxis->pixelToCoord(event->y());
#ifndef PLATFORM_ANDROID
} else if(vertCursorEnabled && placingVertAxes){
#else
} if(vertCursorEnabled && placingVertAxes){
#endif
x1 = axes->xAxis->pixelToCoord(event->x());
display.x1 = axes->xAxis->pixelToCoord(event->x());
}
}
@ -536,25 +514,25 @@ void isoDriver::udateCursors(void){
QVector<double> vert0x(2), vert1x(2), hori0x(2), hori1x(2), vert0y(2), vert1y(2), hori0y(2), hori1y(2);
vert0x[0] = x0;
vert0x[1] = x0;
vert0y[0] = botRange;
vert0y[1] = topRange;
vert0x[0] = display.x0;
vert0x[1] = display.x0;
vert0y[0] = display.botRange;
vert0y[1] = display.topRange;
vert1x[0] = x1;
vert1x[1] = x1;
vert1y[0] = botRange;
vert1y[1] = topRange;
vert1x[0] = display.x1;
vert1x[1] = display.x1;
vert1y[0] = display.botRange;
vert1y[1] = display.topRange;
hori0x[0] = -window - delay;
hori0x[1] = -delay;
hori0y[0] = y0;
hori0y[1] = y0;
hori0x[0] = -display.window - display.delay;
hori0x[1] = -display.delay;
hori0y[0] = display.y0;
hori0y[1] = display.y0;
hori1x[0] = -window - delay;
hori1x[1] = -delay;
hori1y[0] = y1;
hori1y[1] = y1;
hori1x[0] = -display.window - display.delay;
hori1x[1] = -display.delay;
hori1y[0] = display.y1;
hori1y[1] = display.y1;
if(vertCursorEnabled){
axes->graph(2)->setData(vert0x, vert0y);
@ -571,13 +549,13 @@ void isoDriver::udateCursors(void){
QString *cursorStatsString = new QString();
v0->value = y0;
v1->value = y1;
dv->value = y0-y1;
t0->value = x0;
t1->value = x1;
dt->value = fabs(x0-x1);
f->value = 1/(x1-x0);
v0->value = display.y0;
v1->value = display.y1;
dv->value = display.y0-display.y1;
t0->value = display.x0;
t1->value = display.x1;
dt->value = fabs(display.x0 - display.x1);
f->value = 1 / (display.x1 - display.x0);
char temp_hori[64];
char temp_vert[64];
@ -647,7 +625,8 @@ void isoDriver::setTriggerMode(int newMode)
triggerStateChanged();
}
void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1 for ana, 2 for dig, -1 for ana750, -2 for file
//0 for off, 1 for ana, 2 for dig, -1 for ana750, -2 for file
void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode)
{
//qDebug() << "made it to frameActionGeneric";
if(!paused_CH1 && CH1_mode == - 1){
@ -688,7 +667,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
double triggerDelay = 0;
if (triggerEnabled)
{
triggerDelay = (triggerMode < 2) ? internalBuffer375_CH1->getDelayedTriggerPoint(window) - window : internalBuffer375_CH2->getDelayedTriggerPoint(window) - window;
triggerDelay = (triggerMode < 2) ? internalBuffer375_CH1->getDelayedTriggerPoint(display.window) - display.window : internalBuffer375_CH2->getDelayedTriggerPoint(display.window) - display.window;
if (triggerDelay < 0)
triggerDelay = 0;
@ -697,10 +676,10 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
if(singleShotEnabled && (triggerDelay != 0))
singleShotTriggered(1);
readData375_CH1 = internalBuffer375_CH1->readBuffer(window,GRAPH_SAMPLES,CH1_mode==2, delay + triggerDelay);
if(CH2_mode) readData375_CH2 = internalBuffer375_CH2->readBuffer(window,GRAPH_SAMPLES,CH2_mode==2, delay + triggerDelay);
if(CH1_mode == -1) readData750 = internalBuffer750->readBuffer(window,GRAPH_SAMPLES,false, delay + triggerDelay);
if(CH1_mode == -2) readDataFile = internalBufferFile->readBuffer(window,GRAPH_SAMPLES,false, delay);
readData375_CH1 = internalBuffer375_CH1->readBuffer(display.window,GRAPH_SAMPLES,CH1_mode==2, display.delay + triggerDelay);
if(CH2_mode) readData375_CH2 = internalBuffer375_CH2->readBuffer(display.window,GRAPH_SAMPLES,CH2_mode==2, display.delay + triggerDelay);
if(CH1_mode == -1) readData750 = internalBuffer750->readBuffer(display.window,GRAPH_SAMPLES,false, display.delay + triggerDelay);
if(CH1_mode == -2) readDataFile = internalBufferFile->readBuffer(display.window,GRAPH_SAMPLES,false, display.delay);
QVector<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES), CH2(GRAPH_SAMPLES);
@ -744,7 +723,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
for (double i=0; i<GRAPH_SAMPLES; i++){
x[i] = -(window*i)/((double)(GRAPH_SAMPLES-1)) - delay;
x[i] = -(display.window*i)/((double)(GRAPH_SAMPLES-1)) - display.delay;
if (x[i]>0) {
CH1[i] = 0;
CH2[i] = 0;
@ -760,8 +739,8 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
}else{
axes->graph(0)->setData(x,CH1);
if(CH2_mode) axes->graph(1)->setData(x,CH2);
axes->xAxis->setRange(-window-delay,-delay);
axes->yAxis->setRange(topRange, botRange);
axes->xAxis->setRange(-display.window - display.delay, -display.delay);
axes->yAxis->setRange(display.topRange, display.botRange);
}
if(snapshotEnabled_CH1){
@ -804,13 +783,13 @@ void isoDriver::multimeterAction(){
}
double triggerDelay = 0;
readData375_CH1 = internalBuffer375_CH1->readBuffer(window,GRAPH_SAMPLES, false, delay + ((triggerEnabled&&!paused_multimeter) ? triggerDelay + window/2 : 0));
readData375_CH1 = internalBuffer375_CH1->readBuffer(display.window,GRAPH_SAMPLES, false, display.delay + ((triggerEnabled&&!paused_multimeter) ? triggerDelay + display.window/2 : 0));
QVector<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES);
analogConvert(readData375_CH1.get(), &CH1, 2048, 0, 1); //No AC coupling!
for (double i=0; i<GRAPH_SAMPLES; i++){
x[i] = -(window*i)/((double)(GRAPH_SAMPLES-1)) - delay;
x[i] = -(display.window*i)/((double)(GRAPH_SAMPLES-1)) - display.delay;
if (x[i]>0) {
CH1[i] = 0;
}
@ -819,8 +798,8 @@ void isoDriver::multimeterAction(){
udateCursors();
axes->xAxis->setRange(-window-delay,-delay);
axes->yAxis->setRange(topRange, botRange);
axes->xAxis->setRange(-display.window - display.delay, -display.delay);
axes->yAxis->setRange(display.topRange, display.botRange);
axes->replot();
multimeterStats();
@ -1148,25 +1127,28 @@ void isoDriver::slowTimerTick(){
update_CH2 = true;
}
void isoDriver::setTopRange(double newTop){
topRange = newTop;
topRangeUpdated(topRange);
void isoDriver::setTopRange(double newTop)
{
// NOTE: Should this be clamped to 20?
display.topRange = newTop;
topRangeUpdated(display.topRange);
}
void isoDriver::setBotRange(double newBot){
botRange = newBot;
botRangeUpdated(botRange);
void isoDriver::setBotRange(double newBot)
{
// NOTE: Should this be clamped to 20?
display.botRange = newBot;
botRangeUpdated(display.botRange);
}
void isoDriver::setTimeWindow(double newWindow){
window = newWindow;
windowAtPause = window;
timeWindowUpdated(window);
display.window = newWindow;
timeWindowUpdated(display.window);
}
void isoDriver::setDelay(double newDelay){
delay = newDelay;
delayUpdated(delay);
display.delay = newDelay;
delayUpdated(display.delay);
}
void isoDriver::takeSnapshot(QString *fileName, unsigned char channel){
@ -1389,20 +1371,20 @@ void isoDriver::disableFileMode(){
//Shrink screen back, if necessary.
double mws = fileModeEnabled ? daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
if (window > mws)
if (display.window > mws)
{
window = mws;
timeWindowUpdated(window);
display.window = mws;
timeWindowUpdated(display.window);
}
if ((window + delay) > mws)
if ((display.window + display.delay) > mws)
{
delay -= window + delay - mws;
delayUpdated(delay);
display.delay -= display.window + display.delay - mws;
delayUpdated(display.delay);
}
if (delay < 0)
if (display.delay < 0)
{
delay = 0;
delayUpdated(delay);
display.delay = 0;
delayUpdated(display.delay);
}
}

View File

@ -15,9 +15,38 @@
class isoBuffer;
class isoBuffer_file;
//isoDriver is a huge class. It handles everything related to the isochronous IN stream - and perhaps that constraint was applied a bit too loosely (spot the C programmer...).
//Too much stuff is handled in this class, and it's too heavily entangled with the (generic/win/unix)UsbDriver classes.
//That is one of the things I plan on fixing, and in fact the reason why I began the commenting!
// isoDriver is a huge class. It handles everything related to the
// isochronous IN stream - and perhaps that constraint was applied
// a bit too loosely (spot the C programmer...).
// Too much stuff is handled in this class, and it's too heavily
// entangled with the (generic/win/unix)UsbDriver classes.
// That is one of the things I plan on fixing, and in fact
// the reason why I began the commenting!
class DisplayControl : public QObject
{
Q_OBJECT
public:
double delay = 0;
double window = 0.01;
double y0 = 0;
double y1 = 0;
double x0 = 0;
double x1 = 0;
double topRange = 2.5;
double botRange = -0.5;
void setVoltageRange (QWheelEvent* event, bool isProperlyPaused, double maxWindowSize, QCustomPlot* axes);
signals:
void topRangeUpdated(double);
void botRangeUpdated(double);
void timeWindowUpdated(double);
void delayUpdated(double);
};
class isoDriver : public QLabel
{
@ -26,26 +55,30 @@ public:
explicit isoDriver(QWidget *parent = 0);
void autoGain(void);
//Generic Vars
isoBuffer *internalBuffer375_CH1, *internalBuffer375_CH2, *internalBuffer750;
isoBuffer *internalBuffer375_CH1;
isoBuffer *internalBuffer375_CH2;
isoBuffer *internalBuffer750;
isoBuffer_file *internalBufferFile = NULL;
#if QCP_VER == 1
QCPItemText *cursorTextPtr;
#endif
genericUsbDriver *driver;
bool doNotTouchGraph = true;
double ch1_ref = 1.65, ch2_ref = 1.65;
double frontendGain_CH1 = (R4/(R3+R4)), frontendGain_CH2 = (R4/(R3+R4));
double ch1_ref = 1.65;
double ch2_ref = 1.65;
double frontendGain_CH1 = (R4/(R3+R4));
double frontendGain_CH2 = (R4/(R3+R4));
UartParity parity_CH1 = UartParity::None;
UartParity parity_CH2 = UartParity::None;
//State Vars
bool AC_CH1 = false, AC_CH2 = false;
bool AC_CH1 = false;
bool AC_CH2 = false;
bool cursorStatsEnabled = true;
int baudRate_CH1 = 9600, baudRate_CH2 = 9600;
int baudRate_CH1 = 9600;
int baudRate_CH2 = 9600;
double currentVmean;
//Display Control Vars (Variables that control how the buffers are displayed)
double delay = 0, window = 0.01;
double y0=0, y1=0, x0=0, x1=0;
double topRange=2.5, botRange=-0.5;
//Display Control Vars (Variables that control how the buffers are displayed)
DisplayControl display;
//Generic Functions
void setDriver(genericUsbDriver *newDriver);
void setAxes(QCustomPlot *newAxes);
@ -57,9 +90,14 @@ public:
double daq_maxWindowSize;
private:
//Those bloody bools that just Enable/Disable a single property
bool paused_CH1 = false, paused_CH2 = false, paused_multimeter = false;
bool paused_CH1 = false;
bool paused_CH2 = false;
bool paused_multimeter = false;
bool autoGainEnabled = true;
bool placingHoriAxes = false, placingVertAxes = false, horiCursorEnabled = false, vertCursorEnabled = false;
bool placingHoriAxes = false; // TODO: move into DisplayControl
bool placingVertAxes = false; // TODO: move into DisplayControl
bool horiCursorEnabled = false; // TODO: move into DisplayControl
bool vertCursorEnabled = false; // TODO: move into DisplayControl
bool triggerEnabled = false;
bool singleShotEnabled = false;
bool multimeterShow = true;
@ -75,9 +113,11 @@ private:
bool forceAmps = false;
bool forceOhms = false;
bool forceNFarads = false;
bool serialDecodeEnabled_CH1 = false, serialDecodeEnabled_CH2 = false;
bool serialDecodeEnabled_CH1 = false;
bool serialDecodeEnabled_CH2 = false;
bool XYmode = false;
bool update_CH1 = true, update_CH2 = true;
bool update_CH1 = true;
bool update_CH2 = true;
bool snapshotEnabled_CH1 = false;
bool snapshotEnabled_CH2 = false;
bool firstFrame = true;
@ -93,18 +133,29 @@ private:
void frameActionGeneric(char CH1_mode, char CH2_mode);
void triggerStateChanged();
//Variables that are just pointers to other classes/vars
QCustomPlot *axes;
QCustomPlot *axes; // TODO: move into DisplayControl
std::unique_ptr<short[]> readData375_CH1;
std::unique_ptr<short[]> readData375_CH2;
std::unique_ptr<short[]> readData750;
float *readDataFile;
char *isoTemp = NULL;
short *isoTemp_short = NULL;
siprint *v0, *v1, *dv, *t0, *t1, *dt, *f;
siprint *v0;
siprint *v1;
siprint *dv;
siprint *t0;
siprint *t1;
siprint *dt;
siprint *f;
//Scope/MM++ related variables
double currentVmax, currentVmin, currentVRMS;
double currentVmax;
double currentVmin;
double currentVRMS;
double multi = 0;
double xmin = 20, xmax = -20, ymin = 20, ymax = -20;
double xmin = 20;
double xmax = -20;
double ymin = 20;
double ymax = -20;
double estimated_resistance = 0;
int multimeterRsource = 0;
int triggerMode = 0;
@ -121,8 +172,9 @@ private:
i2c::i2cDecoder* twoWire = nullptr;
bool twoWireStateInvalid = true;
//Generic Vars
double windowAtPause = 0.01;
QTimer* isoTimer = NULL, *slowTimer = NULL, *fileTimer = NULL;
QTimer* isoTimer = NULL;
QTimer *slowTimer = NULL;
QTimer *fileTimer = NULL;
long total_read = 0;
unsigned int length;
QFile *snapshotFile_CH1;
@ -163,7 +215,6 @@ signals:
void timeWindowUpdated(double);
void delayUpdated(double);
public slots:
void setWindow(int newWindow);
void setVoltageRange(QWheelEvent *event);
void timerTick(void);
void pauseEnable_CH1(bool enabled);

View File

@ -4,6 +4,8 @@
#include <QDesktopServices>
#include "espospinbox.h"
#include <algorithm>
#define DO_QUOTE(X) #X
#define QUOTE(X) DO_QUOTE(X)
@ -1072,32 +1074,32 @@ void MainWindow::ctrlArrowDownTriggered(){
void MainWindow::cycleDelayRight(){
qDebug() << "RIGHT";
ui->controller_iso->delay -= ui->controller_iso->window/10;
if(ui->controller_iso->delay < 0) ui->controller_iso->delay = 0;
ui->controller_iso->delayUpdated(ui->controller_iso->delay);
ui->controller_iso->display.delay -= ui->controller_iso->display.window/10;
if(ui->controller_iso->display.delay < 0) ui->controller_iso->display.delay = 0;
ui->controller_iso->delayUpdated(ui->controller_iso->display.delay);
}
void MainWindow::cycleDelayLeft(){
qDebug() << "LEFT";
double mws = ui->controller_iso->fileModeEnabled ? ui->controller_iso->daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
ui->controller_iso->delay += ui->controller_iso->window/10;
if(ui->controller_iso->delay > (mws - ui->controller_iso->window)) ui->controller_iso->delay = (mws - ui->controller_iso->window);
ui->controller_iso->delayUpdated(ui->controller_iso->delay);
ui->controller_iso->display.delay += ui->controller_iso->display.window/10;
if(ui->controller_iso->display.delay > (mws - ui->controller_iso->display.window)) ui->controller_iso->display.delay = (mws - ui->controller_iso->display.window);
ui->controller_iso->delayUpdated(ui->controller_iso->display.delay);
}
void MainWindow::cycleDelayRight_large(){
qDebug() << "RIGHT";
ui->controller_iso->delay -= ui->controller_iso->window/2;
if(ui->controller_iso->delay < 0) ui->controller_iso->delay = 0;
ui->controller_iso->delayUpdated(ui->controller_iso->delay);
ui->controller_iso->display.delay -= ui->controller_iso->display.window/2;
if(ui->controller_iso->display.delay < 0) ui->controller_iso->display.delay = 0;
ui->controller_iso->delayUpdated(ui->controller_iso->display.delay);
}
void MainWindow::cycleDelayLeft_large(){
qDebug() << "LEFT";
double mws = ui->controller_iso->fileModeEnabled ? ui->controller_iso->daq_maxWindowSize : ((double)MAX_WINDOW_SIZE);
ui->controller_iso->delay += ui->controller_iso->window/2;
if(ui->controller_iso->delay > (mws - ui->controller_iso->window)) ui->controller_iso->delay = (mws - ui->controller_iso->window);
ui->controller_iso->delayUpdated(ui->controller_iso->delay);
ui->controller_iso->display.delay += ui->controller_iso->display.window/2;
if(ui->controller_iso->display.delay > (mws - ui->controller_iso->display.window)) ui->controller_iso->display.delay = (mws - ui->controller_iso->display.window);
ui->controller_iso->delayUpdated(ui->controller_iso->display.delay);
}
void MainWindow::enableLabradorDebugging(){
@ -1177,27 +1179,27 @@ void MainWindow::on_actionSnap_to_Cursors_triggered()
{
double xLeft, xRight, yBot, yTop;
yTop = ui->controller_iso->y1 > ui->controller_iso->y0 ? ui->controller_iso->y1 : ui->controller_iso->y0;
yBot = ui->controller_iso->y1 > ui->controller_iso->y0 ? ui->controller_iso->y0 : ui->controller_iso->y1;
yTop = std::max(ui->controller_iso->display.y1, ui->controller_iso->display.y0);
yBot = std::min(ui->controller_iso->display.y1, ui->controller_iso->display.y0);
xRight = ui->controller_iso->x1 > ui->controller_iso->x0 ? ui->controller_iso->x1 : ui->controller_iso->x0;
xLeft = ui->controller_iso->x1 > ui->controller_iso->x0 ? ui->controller_iso->x0 : ui->controller_iso->x1;
xRight = std::max(ui->controller_iso->display.x1, ui->controller_iso->display.x0);
xLeft = std::min(ui->controller_iso->display.x1, ui->controller_iso->display.x0);
if((yBot-yTop) != 0){
ui->controller_iso->topRange = yTop;
ui->controller_iso->botRange = yBot;
ui->controller_iso->display.topRange = yTop;
ui->controller_iso->display.botRange = yBot;
}
if((xLeft - xRight) != 0){
ui->controller_iso->delay = - xRight;
ui->controller_iso->window = xRight - xLeft;
ui->controller_iso->display.delay = - xRight;
ui->controller_iso->display.window = xRight - xLeft;
}
}
void MainWindow::on_actionEnter_Manually_triggered()
{
ui->controller_iso->delay = 0;
scopeRangeEnterDialog dialog(this, ui->controller_iso->topRange, ui->controller_iso->botRange, ui->controller_iso->window, ui->controller_iso->delay);
ui->controller_iso->display.delay = 0;
scopeRangeEnterDialog dialog(this, ui->controller_iso->display.topRange, ui->controller_iso->display.botRange, ui->controller_iso->display.window, ui->controller_iso->display.delay);
dialog.setModal(true);
connect(&dialog, SIGNAL(yTopUpdated(double)), ui->controller_iso, SLOT(setTopRange(double)));
connect(&dialog, SIGNAL(yBotUpdated(double)), ui->controller_iso, SLOT(setBotRange(double)));
@ -2300,7 +2302,7 @@ void MainWindow::on_actionShow_Range_Dialog_on_Main_Page_triggered(bool checked)
qDebug() << "on_actionShow_Range_Dialog_on_Main_Page_triggered" << checked;
if (checked)
{
scopeRangeSwitch = new scopeRangeEnterDialog(nullptr, false, ui->controller_iso->topRange, ui->controller_iso->botRange, ui->controller_iso->window, ui->controller_iso->delay);
scopeRangeSwitch = new scopeRangeEnterDialog(nullptr, false, ui->controller_iso->display.topRange, ui->controller_iso->display.botRange, ui->controller_iso->display.window, ui->controller_iso->display.delay);
scopeRangeSwitch->setWindowFlags(Qt::Widget);
ui->verticalLayout_5->insertWidget(2, scopeRangeSwitch);
connect(scopeRangeSwitch, SIGNAL(yTopUpdated(double)), ui->controller_iso, SLOT(setTopRange(double)));