Skip to content

Commit

Permalink
Fix signalling of property changes to dataSaver. Fixed initialization…
Browse files Browse the repository at this point in the history
… of gain adjustment.
  • Loading branch information
daharoni committed Jan 17, 2020
1 parent 03a969d commit a3eed32
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VideoSliderControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Item {
property double min: 0.0
property double max: 100.0
property double stepSize: 1.0
property double startValue: 0.0
property double startValue: -1000.23948
property double displayValueScale: 1
property double displayValueOffset: 0
property double displayRotation: 0
Expand Down
5 changes: 2 additions & 3 deletions VideoSpinBoxControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ Item {
property var iconPath: "img/icon/ewl.ico"

property var displaySpinBoxValues: ["1", "2", "3"]
property var displayTextValues: [1,2,3]
property var displayTextValues: [1.0,2.0,3.0]
property var outputValues: [1, 2, 3]
property var startValue: "1"

onStartValueChanged: {
// print(startValue)
spinBox.value = displaySpinBoxValues.indexOf(startValue)
}

Expand Down Expand Up @@ -75,7 +74,7 @@ Item {

from: 0
to: root.displaySpinBoxValues.length - 1
value: 0
value: 100

textFromValue: function(value) {
return root.displaySpinBoxValues[value];
Expand Down
9 changes: 5 additions & 4 deletions backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QJsonArray>
#include <QThread>
#include <QObject>
#include <QVariant>

#include "miniscope.h"
#include "behaviorcam.h"
Expand Down Expand Up @@ -222,17 +223,17 @@ void backEnd::constructUserConfigGUI()
for (idx = 0; idx < ucMiniscopes.size(); idx++) {
miniscope.append(new Miniscope(this, ucMiniscopes[idx].toObject()));
QObject::connect(miniscope.last(),
SIGNAL (onPropertyChanged(QString, QString, double)),
SIGNAL (onPropertyChanged(QString, QString, QVariant)),
dataSaver,
SLOT (devicePropertyChanged(QString, QString, double)));
SLOT (devicePropertyChanged(QString, QString, QVariant)));
miniscope.last()->createView();
}
for (idx = 0; idx < ucBehaviorCams.size(); idx++) {
behavCam.append(new BehaviorCam(this, ucBehaviorCams[idx].toObject()));
QObject::connect(behavCam.last(),
SIGNAL (onPropertyChanged(QString, QString, double)),
SIGNAL (onPropertyChanged(QString, QString, QVariant)),
dataSaver,
SLOT (devicePropertyChanged(QString, QString, double)));
SLOT (devicePropertyChanged(QString, QString, QVariant)));
behavCam.last()->createView();
}
if (!ucExperiment.isEmpty()){
Expand Down
5 changes: 3 additions & 2 deletions behaviorcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QJsonArray>
#include <QQmlApplicationEngine>
#include <QVector>
#include <QVariant>

BehaviorCam::BehaviorCam(QObject *parent, QJsonObject ucBehavCam) :
QObject(parent),
Expand Down Expand Up @@ -228,7 +229,7 @@ void BehaviorCam::configureBehavCamControls() {
controlItem->setProperty(keys[j].toLatin1().data(), values[keys[j]].toDouble());
if (keys[j] == "startValue")
// sends signal on initial setup of controls
emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toDouble());
emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toVariant());
}
}
}
Expand Down Expand Up @@ -361,7 +362,7 @@ void BehaviorCam::handlePropCangedSignal(QString type, double displayValue, doub

// TODO: maybe add a check to make sure property successfully updates before signallng it has changed
// qDebug() << "Sending updated prop signal to backend";
emit onPropertyChanged(m_deviceName, type, displayValue);
emit onPropertyChanged(m_deviceName, type, QVariant(displayValue));

// TODO: Handle int values greater than 8 bits
// for (int i = 0; i < m_controlSendCommand[type].length(); i++) {
Expand Down
3 changes: 2 additions & 1 deletion behaviorcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QMap>
#include <QVector>
#include <QQuickItem>
#include <QVariant>

#include "videostreamocv.h"
#include "videodisplay.h"
Expand Down Expand Up @@ -42,7 +43,7 @@ class BehaviorCam : public QObject
signals:
// TODO: setup signals to configure camera in thread
// void setPropertyI2C(long preambleKey, QVector<quint8> packet);
void onPropertyChanged(QString devieName, QString propName, double propValue);
void onPropertyChanged(QString devieName, QString propName, QVariant propValue);
void sendMessage(QString msg);
void takeScreenShot(QString type);
void newFrameAvailable(QString name, int frameNum);
Expand Down
9 changes: 7 additions & 2 deletions datasaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <QCoreApplication>
#include <QFile>
#include <QTextStream>
#include <QVariant>
#include <QMetaType>

DataSaver::DataSaver(QObject *parent) :
QObject(parent),
Expand Down Expand Up @@ -244,7 +246,7 @@ void DataSaver::stopRecording()
noteFile->close();
}

void DataSaver::devicePropertyChanged(QString deviceName, QString propName, double propValue)
void DataSaver::devicePropertyChanged(QString deviceName, QString propName, QVariant propValue)
{
deviceProperties[deviceName][propName] = propValue;
qDebug() << deviceName << propName << propValue;
Expand Down Expand Up @@ -339,7 +341,10 @@ QJsonDocument DataSaver::constructMiniscopeMetaData(int idx)
// loop through device properties at the start of recording
QStringList keys = deviceProperties[deviceName].keys();
for (int i = 0; i < keys.length(); i++) {
metaData[keys[i]] = deviceProperties[deviceName][keys[i]];
if (deviceProperties[deviceName][keys[i]].userType() == QMetaType::QString)
metaData[keys[i]] = deviceProperties[deviceName][keys[i]].toString();
else
metaData[keys[i]] = deviceProperties[deviceName][keys[i]].toDouble();
}

jDoc.setObject(metaData);
Expand Down
5 changes: 3 additions & 2 deletions datasaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QFile>
#include <QTextStream>
#include <QAtomicInt>
#include <QVariant>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
Expand Down Expand Up @@ -37,7 +38,7 @@ public slots:
void startRunning();
void startRecording();
void stopRecording();
void devicePropertyChanged(QString deviceName, QString propName, double propValue);
void devicePropertyChanged(QString deviceName, QString propName, QVariant propValue);
void takeScreenShot(QString type);
void takeNote(QString note);

Expand All @@ -50,7 +51,7 @@ public slots:
QDateTime recordStartDateTime;
QMap<QString,QString> deviceDirectory;

QMap<QString, QMap<QString, double>> deviceProperties;
QMap<QString, QMap<QString, QVariant>> deviceProperties;

// Probably shoud turn all of this into a single struct
QMap<QString, cv::Mat*> frameBuffer;
Expand Down
15 changes: 9 additions & 6 deletions miniscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Miniscope::Miniscope(QObject *parent, QJsonObject ucMiniscope) :
sendInitCommands();

videoStreamThread->start();

// Short sleep to make i2c initialize commands be sent before loading in user config controls
QThread::msleep(500);
}

void Miniscope::createView()
Expand All @@ -110,7 +113,7 @@ void Miniscope::createView()
QObject::connect(rootObject, SIGNAL( takeScreenShotSignal() ),
this, SLOT( handleTakeScreenShotSignal() ));
QObject::connect(rootObject, SIGNAL( vidPropChangedSignal(QString, double, double) ),
this, SLOT( handlePropCangedSignal(QString, double, double) ));
this, SLOT( handlePropChangedSignal(QString, double, double) ));

configureMiniscopeControls();
vidDisplay = rootObject->findChild<VideoDisplay*>("vD");
Expand Down Expand Up @@ -238,15 +241,15 @@ void Miniscope::configureMiniscopeControls() {
}
else if (values[keys[j]].isString()) {
controlItem->setProperty(keys[j].toLatin1().data(), values[keys[j]].toString());
// if (keys[j] == "startValue")
if (keys[j] == "startValue")
// sends signal on initial setup of controls
// emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toString());
emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toVariant());
}
else {
controlItem->setProperty(keys[j].toLatin1().data(), values[keys[j]].toDouble());
if (keys[j] == "startValue")
// sends signal on initial setup of controls
emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toDouble());
emit onPropertyChanged(m_deviceName, controlName[i], values["startValue"].toVariant());
}
}
}
Expand Down Expand Up @@ -370,7 +373,7 @@ void Miniscope::sendNewFrame(){
}


void Miniscope::handlePropCangedSignal(QString type, double displayValue, double i2cValue)
void Miniscope::handlePropChangedSignal(QString type, double displayValue, double i2cValue)
{
// type is the objectName of the control
// value is the control value that was just updated
Expand All @@ -392,7 +395,7 @@ void Miniscope::handlePropCangedSignal(QString type, double displayValue, double

// TODO: maybe add a check to make sure property successfully updates before signallng it has changed
// qDebug() << "Sending updated prop signal to backend";
emit onPropertyChanged(m_deviceName, type, displayValue);
emit onPropertyChanged(m_deviceName, type, QVariant(displayValue));

// TODO: Handle int values greater than 8 bits
for (int i = 0; i < m_controlSendCommand[type].length(); i++) {
Expand Down
5 changes: 3 additions & 2 deletions miniscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QMap>
#include <QVector>
#include <QQuickItem>
#include <QVariant>

#include "videostreamocv.h"
#include "videodisplay.h"
Expand Down Expand Up @@ -51,14 +52,14 @@ class Miniscope : public QObject
signals:
// TODO: setup signals to configure camera in thread
void setPropertyI2C(long preambleKey, QVector<quint8> packet);
void onPropertyChanged(QString devieName, QString propName, double propValue);
void onPropertyChanged(QString devieName, QString propName, QVariant propValue);
void sendMessage(QString msg);
void takeScreenShot(QString type);

public slots:
void sendNewFrame();
void testSlot(QString, double);
void handlePropCangedSignal(QString type, double displayValue, double i2cValue);
void handlePropChangedSignal(QString type, double displayValue, double i2cValue);
void handleTakeScreenShotSignal();
void close();

Expand Down
4 changes: 2 additions & 2 deletions userConfigs/UserConfigExample.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"windowX": 800,
"windowY": 100,
"gain": "Low",
"ewl": 30,
"led0": 10,
"ewl": 50,
"led0": 30,
"frameRate": "30FPS"
}
],
Expand Down

0 comments on commit a3eed32

Please sign in to comment.