Skip to content

Commit

Permalink
Merge pull request #20 from Aharoni-Lab/dev-usb
Browse files Browse the repository at this point in the history
Dev usb
  • Loading branch information
daharoni authored Sep 11, 2020
2 parents dce6c55 + a802a0f commit 4e48dff
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21 deletions.
28 changes: 27 additions & 1 deletion deviceConfigs/behaviorCams.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,33 @@
"controlSettings": {
}
},

"WebCam-320x240": {
"sensor": "",
"frameRate": 30,
"width": 320,
"height": 240,
"isColor": true,
"controlSettings": {
}
},
"WebCam-640x480": {
"sensor": "",
"frameRate": 30,
"width": 640,
"height": 480,
"isColor": true,
"controlSettings": {
}
},
"WebCam-1280x720": {
"sensor": "",
"frameRate": 30,
"width": 1280,
"height": 720,
"isColor": true,
"controlSettings": {
}
},
"Minicam-Mono-XGA": {
"qmlFile": "qrc:/behaviorCam.qml",
"sensor": "MT9P031",
Expand Down
2 changes: 1 addition & 1 deletion deviceConfigs/miniscopes.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"max": 100,
"stepSize": 1,
"displayValueScale": -2.55,
"displayValueOffset": 0,
"displayValueOffset": -255,
"sendCommand": [
{
"protocol": "I2C",
Expand Down
2 changes: 1 addition & 1 deletion source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ backEnd::backEnd(QObject *parent) :
for (int i = 0; i < unAvailableCodec.length(); i++)
tempStr += unAvailableCodec[i] + ", ";

setUserConfigDisplay("Select a User Configuration file.\n\nAvailable compression Codecs on your computer are:\n" + m_availableCodecList +
setUserConfigDisplay("Select a User Configuration file.\n\nSupported devices are listed in the .json files in the deviceConfig folder.\n\nAvailable compression Codecs on your computer are:\n" + m_availableCodecList +
"\n\nUnavailable compression Codes on your computer are:\n" + tempStr.chopped(2));

// QObject::connect(this, SIGNAL (userConfigFileNameChanged()), this, SLOT( handleUserConfigFileNameChanged() ));
Expand Down
31 changes: 23 additions & 8 deletions source/behaviorcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ BehaviorCam::BehaviorCam(QObject *parent, QJsonObject ucBehavCam) :

m_ucBehavCam = ucBehavCam; // hold user config for this Miniscope

parseUserConfigBehavCam();

getBehavCamConfig(m_ucBehavCam["deviceType"].toString()); // holds specific Miniscope configuration

parseUserConfigBehavCam();

// TODO: Handle cases where there is more than webcams and MiniCAMs
if (m_ucBehavCam["deviceType"].toString() == "WebCam") {
if (m_ucBehavCam["deviceType"].toString().toLower().contains("webcam")) {
isMiniCAM = false;
m_daqFrameNum = nullptr;
}
Expand Down Expand Up @@ -220,10 +220,14 @@ void BehaviorCam::parseUserConfigBehavCam() {
m_roiBoundingBox[1] = m_ucBehavCam["ROI"].toObject()["topEdge"].toInt(-1);
m_roiBoundingBox[2] = m_ucBehavCam["ROI"].toObject()["width"].toInt(-1);
m_roiBoundingBox[3] = m_ucBehavCam["ROI"].toObject()["height"].toInt(-1);


// TODO: Throw error is values are incorrect or missing
}
else {
m_roiBoundingBox[0] = 0;
m_roiBoundingBox[1] = 0;
m_roiBoundingBox[2] = m_cBehavCam["width"].toInt(-1);
m_roiBoundingBox[3] = m_cBehavCam["height"].toInt(-1);
}
}

void BehaviorCam::sendInitCommands()
Expand Down Expand Up @@ -285,7 +289,6 @@ void BehaviorCam::getBehavCamConfig(QString deviceType) {
QJsonDocument d = QJsonDocument::fromJson(jsonFile.toUtf8());
QJsonObject jObj = d.object();
m_cBehavCam = jObj[deviceType].toObject();

}

void BehaviorCam::configureBehavCamControls() {
Expand Down Expand Up @@ -605,19 +608,31 @@ void BehaviorCam::handleSetRoiClicked()

void BehaviorCam::handleNewROI(int leftEdge, int topEdge, int width, int height)
{
m_roiIsDefined = true;
// First scale the local position values to pixel values
m_roiBoundingBox[0] = round(leftEdge/m_ucBehavCam["windowScale"].toDouble(1));
m_roiBoundingBox[1] = round(topEdge/m_ucBehavCam["windowScale"].toDouble(1));
m_roiBoundingBox[2] = round(width/m_ucBehavCam["windowScale"].toDouble(1));
m_roiBoundingBox[3] = round(height/m_ucBehavCam["windowScale"].toDouble(1));

if ((m_roiBoundingBox[0] + m_roiBoundingBox[2]) > m_cBehavCam["width"].toInt(-1)) {
// Edge is off screen
m_roiBoundingBox[2] = m_cBehavCam["width"].toInt(-1) - m_roiBoundingBox[0];
sendMessage("Warning: Right edge of ROI drawn beyond right edge of video. If this is incorrect you can change the width and height values in deviceCnfigs/behaviorCams.json");
}
if ((m_roiBoundingBox[1] + m_roiBoundingBox[3]) > m_cBehavCam["height"].toInt(-1)) {
// Edge is off screen
m_roiBoundingBox[3] = m_cBehavCam["height"].toInt(-1) - m_roiBoundingBox[1];
sendMessage("Warning: Bottm edge of ROI drawn beyond bottom edge of video. If this is incorrect you can change the width and height values in deviceCnfigs/behaviorCams.json");

}

sendMessage("ROI Set to [" + QString::number(m_roiBoundingBox[0]) + ", " +
QString::number(m_roiBoundingBox[1]) + ", " +
QString::number(m_roiBoundingBox[2]) + ", " +
QString::number(m_roiBoundingBox[3]) + "]");

// TODO: Make sure ROI gets saved in meta data
// TODO: enable ROI button
// TODO: Correct ROI if out of bounds

}

Expand Down
2 changes: 1 addition & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "backend.h"

#define VERSION_NUMBER "1.00"
#define VERSION_NUMBER "1.02"
// TODO: have exit button close everything

// For Window's deployment
Expand Down
2 changes: 1 addition & 1 deletion userConfigs/UserConfigExample_V4_BNO_Miniscope.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"filterBadData": true
},
"streamHeadOrientation_OLD": true,
"deviceID": 0,
"deviceID": 1,
"showSaturation": true,
"compressionOptions": ["MJPG","MJ2C","XVID","FFV1"],
"compression": "FFV1",
Expand Down
17 changes: 9 additions & 8 deletions userConfigs/UserConfigExample_WebCam.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"researcherName": "Dr_Miniscope",
"dataDirectory": "C:/Users/DBAharoni/Documents/Data",
"dataDirectory": "C:/Users/dbaha/Documents/Data",
"directoryStructure": [
"researcherName",
"experimentName",
Expand All @@ -26,19 +26,20 @@
"cameras": [
{
"deviceName": "BehavCam 0",
"deviceType": "WebCam",
"deviceType": "WebCam-1280x720",
"deviceID": 0,
"showSaturation": true,
"ROI": {
"notes": "This defines the bounding box of the portion of the video that is saved to disk",
"leftEdge": 10,
"topEdge": 20,
"width": 300,
"height": 200
"notes": "This defines the bounding box of the portion of the video that is saved to disk",
"note3": "Edge values are zero indexed",
"leftEdge": 0,
"topEdge": 0,
"width": 640,
"height": 480
},
"cameraCalibrationFileLocation": "",
"compressionOptions": ["MJPG","MJ2C","XVID","FFV1"],
"compression": "FFV1",
"compression": "MJPG",
"framesPerFile": 1000,
"windowScale": 0.75,
"windowX": 800,
Expand Down

0 comments on commit 4e48dff

Please sign in to comment.