summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp66
-rw-r--r--src/camera/icamera.h1
-rw-r--r--src/camera/innomakerov9281.cpp18
-rw-r--r--src/camera/innomakerov9281.h2
-rw-r--r--src/camera/ov9281.h5
-rw-r--r--src/constants.h1
6 files changed, 68 insertions, 25 deletions
diff --git a/main.cpp b/main.cpp
index 53fb08b..df80796 100644
--- a/main.cpp
+++ b/main.cpp
@@ -143,7 +143,7 @@ int main(int argc, char* argv[])
InnoMakerOV9281 innoMakerCam;
qDebug() << "init:" << innoMakerCam.init();
qDebug() << "set exposure:" << innoMakerCam.setExposureTimeUs(3000);
- qDebug() << "set gain:" << innoMakerCam.setGain(3000);
+ qDebug() << "set gain:" << innoMakerCam.setGain(0);
innoMakerCam.startStream();
QThread::sleep(3);
@@ -552,7 +552,7 @@ int main(int argc, char* argv[])
qHttpServer.route(
"/v1/sensor/params",
[&](const QHttpServerRequest& request) -> QHttpServerResponse {
- std::cout << "http: params" << std::endl;
+ // std::cout << "http: params" << std::endl;
switch (request.method())
{
case QHttpServerRequest::Method::Get: {
@@ -587,7 +587,7 @@ int main(int argc, char* argv[])
}
case QHttpServerRequest::Method::Post: {
- qDebug() << "request body:" << request.body();
+ // qDebug() << "request body:" << request.body();
auto json = QJsonDocument::fromJson(request.body()).object();
@@ -599,7 +599,7 @@ int main(int argc, char* argv[])
return QHttpServerResponse::StatusCode::
RequestRangeNotSatisfiable;
- qDebug() << "set new exposure time:" << value;
+ // qDebug() << "set new exposure time:" << value;
// requested_params.exposureTime = value;
if (!camera->setExposureTimeUs(value))
@@ -607,37 +607,57 @@ int main(int argc, char* argv[])
RequestRangeNotSatisfiable;
}
+ if (json.contains(gainKey))
+ {
+ const int32_t value{json[gainKey].toInt()};
+
+ if (value == 0)
+ return QHttpServerResponse::StatusCode::
+ RequestRangeNotSatisfiable;
+
+ // qDebug() << "set gain:" << value;
+
+ // requested_params.exposureTime = value;
+ if (!camera->setGain(value))
+ return QHttpServerResponse::StatusCode::
+ RequestRangeNotSatisfiable;
+ }
+
if (json.contains(laserLevelKey))
{
const int32_t value{json[laserLevelKey].toInt()};
- if (value == 0)
- {
- return QHttpServerResponse::StatusCode::NotFound;
- }
+ // if (value == 0)
+ // {
+ // return QHttpServerResponse::StatusCode::NotFound;
+ // }
+
+ // qDebug() << "set new laserLevel:" << value;
+ if (!camera->setLaserLevel(value))
+ return QHttpServerResponse::StatusCode::
+ RequestRangeNotSatisfiable;
- qDebug() << "set new laserLevel:" << value;
requested_params.laserLevel = value;
- const QString laserLevelFile{
- "/sys/class/pwm/pwmchip2/pwm1/duty_cycle"};
- QFile f{laserLevelFile};
+ // const QString laserLevelFile{
+ // "/sys/class/pwm/pwmchip2/pwm1/duty_cycle"};
+ // QFile f{laserLevelFile};
- if (!f.open(QFile::ReadWrite))
- {
- qDebug() << "cannot open laser level file:"
- << f.errorString();
- qDebug() << "file path is" << f.fileName();
- return QHttpServerResponse::StatusCode::InternalServerError;
- }
+ // if (!f.open(QFile::ReadWrite))
+ // {
+ // qDebug() << "cannot open laser level file:"
+ // << f.errorString();
+ // qDebug() << "file path is" << f.fileName();
+ // return QHttpServerResponse::StatusCode::InternalServerError;
+ // }
- QTextStream s{&f};
+ // QTextStream s{&f};
- s << value;
+ // s << value;
- s >> requested_params.laserLevel;
+ // s >> requested_params.laserLevel;
- qDebug() << "done with laser level";
+ // qDebug() << "done with laser level";
}
return QHttpServerResponse(request.body());
diff --git a/src/camera/icamera.h b/src/camera/icamera.h
index 588b23e..3fccc4b 100644
--- a/src/camera/icamera.h
+++ b/src/camera/icamera.h
@@ -34,6 +34,7 @@ class ICamera
public:
virtual bool setExposureTimeUs(int value) = 0;
virtual bool setGain(int value) = 0;
+ virtual bool setLaserLevel(int value) = 0;
public:
libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
diff --git a/src/camera/innomakerov9281.cpp b/src/camera/innomakerov9281.cpp
index 73ceacb..56550ed 100644
--- a/src/camera/innomakerov9281.cpp
+++ b/src/camera/innomakerov9281.cpp
@@ -146,15 +146,29 @@ bool InnoMakerOV9281::setExposureTimeUs(int valueUs)
// valueNs = (valueNs / exposureStep) * exposureStep;
// std::clamp(valueNs, exposureStep, exposureStep * maxExposureStepMultiplier);
-
+ // setGain(rand() % 254);
+ // setGain(3);
+ // setLaserLevel(rand() % 0x7fffffff);
+ // setLaserLevel(rand() % 100);
+ // int exp = rand() % 10;
+ // return setCamParam(V4L2_CID_EXPOSURE, exp * exp * exp * exp * exp * exp);
return setCamParam(V4L2_CID_EXPOSURE, valueUs);
}
bool InnoMakerOV9281::setGain(int value)
{
+ std::cout << __func__ << ": " << value << std::endl << std::flush;
+
return setCamParam(V4L2_CID_GAIN, value);
}
+bool InnoMakerOV9281::setLaserLevel(int value)
+{
+ std::cout << __func__ << ": " << value << std::endl << std::flush;
+
+ return setCamParam(V4L2_CID_FLASH_TIMEOUT, value);
+}
+
bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value)
{
v4l2_control ctl{v4l2controlId, value};
@@ -344,7 +358,7 @@ bool InnoMakerOV9281::getImage(Image &image)
if (elapsedTime > 1000.)
{
- // fprintf(stderr, "fps: %d, sec: %d\n", counter, curr.tv_sec);
+ fprintf(stderr, "fps: %d, sec: %d\n", counter, curr.tv_sec);
fprintf(stderr,
"sum: %d,\tcorr: %d,\tval: %d\n",
sum_elapsed_ns / 1000 / counter,
diff --git a/src/camera/innomakerov9281.h b/src/camera/innomakerov9281.h
index 8c3a14e..ccfe1ac 100644
--- a/src/camera/innomakerov9281.h
+++ b/src/camera/innomakerov9281.h
@@ -31,6 +31,8 @@ public:
bool setExposureTimeUs(int value) override;
bool setGain(int value) override;
+ bool setLaserLevel(int value) override;
+
bool getImage(Image &image);
public:
diff --git a/src/camera/ov9281.h b/src/camera/ov9281.h
index 6014483..e4b7417 100644
--- a/src/camera/ov9281.h
+++ b/src/camera/ov9281.h
@@ -47,6 +47,11 @@ public:
assert(false);
return false;
};
+ bool setLaserLevel(int value) override
+ {
+ assert(false);
+ return false;
+ };
// signals
public:
diff --git a/src/constants.h b/src/constants.h
index b7fd7bc..4f37fe5 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -22,5 +22,6 @@ constexpr uint16_t discretesInRage{16384};
// http json keys
const QString exposureTimeKey = "exposureTime";
const QString laserLevelKey = "laserLevel";
+const QString gainKey = "gain";
const QString dumpsRoot{QStringLiteral("/home/user/dumps")};