diff options
| author | Nikita Kostovsky <luntik2012@gmail.com> | 2025-01-26 11:55:53 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <luntik2012@gmail.com> | 2025-01-26 11:55:53 +0100 |
| commit | 90503471c49ef6ab795a61a2dc7df1e35761fa7e (patch) | |
| tree | c919bc493838185eae947a80e16b6f593d825fbc | |
| parent | 626f08162b07a49e8683bfb04a71ac02faa9b12d (diff) | |
use callbacks for pixels/image, update http resps, load calibration tables in separate threads
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | imagealgos.cpp | 2 | ||||
| -rw-r--r-- | main.cpp | 180 | ||||
| -rw-r--r-- | src/camera/icamera.h | 6 | ||||
| -rw-r--r-- | src/camera/innomakerov9281.cpp | 152 | ||||
| -rw-r--r-- | src/camera/innomakerov9281.h | 6 | ||||
| -rw-r--r-- | src/camera/ov9281.h | 13 |
7 files changed, 250 insertions, 110 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b0cabb..01bf27f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(CMAKE_AUTORCC OFF) # set(TARGET_SYSROOT /home/nikita/rpi/rpi-sysroot) set(TARGET_SYSROOT /home/nikita/rpi/rpi_zero-sysroot) set(CMAKE_SYSROOT ${TARGET_SYSROOT}) +message("CMAKE_SYSROOT: ${CMAKE_SYSROOT}") set(CMAKE_LIBRARY_PATH ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu) # arch: diff --git a/imagealgos.cpp b/imagealgos.cpp index 80a1c92..801c588 100644 --- a/imagealgos.cpp +++ b/imagealgos.cpp @@ -65,7 +65,7 @@ size_t pgm_save(std::shared_ptr<Image> img, FILE *outfile, bool really_save) } } - std::cout << "written pgm image" << std::endl; + // std::cout << "written pgm image" << std::endl; return n; } @@ -38,7 +38,8 @@ #include <QtConcurrent/QtConcurrent> #define try_apply_config() \ - if (!applyConfig(config)) { \ + if (!applyConfig(config)) \ + { \ camera->release(); \ cm->stop(); \ \ @@ -83,17 +84,19 @@ CalibrationTablePtr calibrationTableX; auto printPixels = [](const auto& pixels) { for (size_t i = (img_width - 10) / 2; i < img_width - ((img_width - 10) / 2); - ++i) { + ++i) + { std::cout << pixels[i] << " "; } std::cout << std::endl; }; -void onNewImage( - std::shared_ptr<Image> image) +void onNewImage(std::shared_ptr<Image> image) { - std::cout << __func__ << std::endl << std::flush; - if (!image) { + // std::cout << __func__ << std::endl << std::flush; + + if (!image) + { qDebug() << __func__ << "no image"; return; } @@ -101,18 +104,22 @@ void onNewImage( ::img = image; } -void onNewPixels( - std::shared_ptr<Pixels> pixels) +void onNewPixels(std::shared_ptr<Pixels> pixels) { - if (!pixels) { + // std::cout << __func__ << std::endl << std::flush; + + if (!pixels) + { qDebug() << __func__ << "got null pixels"; } - if (!*pixels) { + if (!*pixels) + { // qDebug() << __func__ << "got empty pixels"; } - for (size_t i = 640 - 5; i < 640 + 5; i++) { + for (size_t i = 640 - 5; i < 640 + 5; i++) + { // std::cout << pixels->pixels[i] << " "; } @@ -127,12 +134,15 @@ int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); + QList<QFuture<void>> initializers; + #ifdef INNO_MAKER - if (false) { + if (false) + { std::cout << std::boolalpha; InnoMakerOV9281 innoMakerCam; qDebug() << "init:" << innoMakerCam.init(); - qDebug() << "set exposure:" << innoMakerCam.setExposureTimeMs(3000); + qDebug() << "set exposure:" << innoMakerCam.setExposureTimeUs(3000); qDebug() << "set gain:" << innoMakerCam.setGain(3000); innoMakerCam.startStream(); @@ -155,22 +165,32 @@ int main(int argc, char* argv[]) // if (false) qDebug() << "size of raw profile" << sizeof(Pixels); - if (true) { + if (true) + { // open binary calibration table - if (true) { - if (!openCalibrationTable("/home/user/dumps/binz.calibration_table", - ::calibrationTableZ)) { - exit(EXIT_FAILURE); - } - // interpolate(::calibrationTableZ); - if (!openCalibrationTable("/home/user/dumps/binx.calibration_table", - ::calibrationTableX)) { - exit(EXIT_FAILURE); - } - // interpolate(::calibrationTableX); + if (true) + { + initializers << QtConcurrent::run([&]() { + if (!openCalibrationTable( + "/home/user/dumps/binz.calibration_table", + ::calibrationTableZ)) + { + exit(EXIT_FAILURE); + } + }); + + initializers << QtConcurrent::run([&]() { + if (!openCalibrationTable( + "/home/user/dumps/binx.calibration_table", + ::calibrationTableX)) + { + exit(EXIT_FAILURE); + } + }); } - if (false) { + if (false) + { // z // if (!openCalibrationTable( // "/home/user/dumps/binz.calibration_table", @@ -246,8 +266,10 @@ int main(int argc, char* argv[]) } // load binary calibration dumps and calibrate - if (false) { - if (true) { + if (false) + { + if (true) + { auto rawProfiles = openDump("/home/user/dumps/binz"); // auto rawProfiles = openDump("/home/user/dumps/z"); qDebug() << "raw z-profiles count is" << rawProfiles.size(); @@ -272,7 +294,8 @@ int main(int argc, char* argv[]) interpolate(::calibrationTableZ); if (!dump(::calibrationTableZ, - "/home/user/dumps/binz.calibration_table")) { + "/home/user/dumps/binz.calibration_table")) + { qApp->exit(EXIT_FAILURE); } // calibrationTableToImage(::calibrationTableZ) @@ -283,7 +306,8 @@ int main(int argc, char* argv[]) qDebug() << "--------------------------------------------------------"; - if (true) { + if (true) + { auto rawProfiles = openDump("/home/user/dumps/binx"); qDebug() << "raw x-profiles count is" << rawProfiles.size(); // qDebug() << "height" << calibrationColumnHeight; @@ -305,7 +329,9 @@ int main(int argc, char* argv[]) interpolate(::calibrationTableX); - if (!dump(::calibrationTableX, "/home/user/dumps/binx.calibration_table")) { + if (!dump(::calibrationTableX, + "/home/user/dumps/binx.calibration_table")) + { qApp->exit(EXIT_FAILURE); } @@ -315,14 +341,6 @@ int main(int argc, char* argv[]) } } - QCryptographicHash hashZ(QCryptographicHash::Sha256); - hashZ.addData(QByteArrayView((char *) ::calibrationTableZ.data(), sizeof(CalibrationTable))); - qDebug() << "hash z" << sizeof(::calibrationTableZ) << hashZ.result().toHex(); - - QCryptographicHash hashX(QCryptographicHash::Sha256); - hashX.addData(QByteArrayView((char *) ::calibrationTableX.data(), sizeof(CalibrationTable))); - qDebug() << "hash x" << sizeof(::calibrationTableX) << hashX.result().toHex(); - // exit(EXIT_SUCCESS); // if (!initLaser()) { @@ -351,7 +369,8 @@ int main(int argc, char* argv[]) const auto cameras = InnoMakerOV9281::search(); // const auto cameras = - if (cameras.empty()) { + if (cameras.empty()) + { std::cerr << "No cameras were identified on the system." << std::endl; #ifndef INNO_MAKER cm->stop(); @@ -369,8 +388,14 @@ int main(int argc, char* argv[]) std::cout << "connect everything" << std::endl; camera->newPixels.connect(&onNewPixels); camera->newImage.connect(&onNewImage); + camera->newImageCallback = &onNewImage; + camera->newPixelsCallback = &onNewPixels; + + for (auto& i : initializers) + i.waitForFinished(); - if (!camera->startStream()) { + if (!camera->startStream()) + { #ifndef INNO_MAKER cm->stop(); #endif @@ -380,22 +405,22 @@ int main(int argc, char* argv[]) QHttpServer qHttpServer; qHttpServer.route("/v1/sensor/image", [&]() { - std::cout << "http: image" << std::endl << std::flush; + // std::cout << "http: image" << std::endl << std::flush; // FILE *f = fopen("/tmp/img.pgm", "w"); // static bool save = false; pgm_save(::img); // save = false; std::lock_guard<std::mutex> lg(pgm_image_mtx); - qDebug() << "mutex locked"; - qDebug() << "image saved to array"; + // qDebug() << "mutex locked"; + // qDebug() << "image saved to array"; return QByteArray((const char*) pgm_image, pgm_image_size); }); qHttpServer.route("/v1/sensor/image2", [&]() { - std::cout << "http: image2" << std::endl; + // std::cout << "http: image2" << std::endl; pgm_save(::img); std::lock_guard<std::mutex> lg(pgm_image_mtx); - qDebug() << "image2"; + // qDebug() << "image2"; return QByteArray((const char*) pgm_image, pgm_image_size); }); // qHttpServer.route("/v1/sensor/exposureTimeUs", [&]() { @@ -403,12 +428,13 @@ int main(int argc, char* argv[]) // return "123"; // }); qHttpServer.route("/v1/pixels", [&]() { - std::cout << "http: pixels" << std::endl; + // std::cout << "http: pixels" << std::endl; std::lock_guard<std::mutex> lg(pgm_image_mtx); QJsonArray pixels; - for (size_t i = 0; i < img_width; ++i) { + for (size_t i = 0; i < img_width; ++i) + { // pixels << img_height - img.pixels[i]; pixels << ::pixels.pixels[i]; } @@ -426,7 +452,8 @@ int main(int argc, char* argv[]) QJsonArray jsonLines; - for (const auto& l : lines) { + for (const auto& l : lines) + { jsonLines << QJsonArray{QJsonArray{l.p1().x(), l.p1().y()}, QJsonArray{l.p2().x(), l.p2().y()}}; } @@ -436,10 +463,13 @@ int main(int argc, char* argv[]) return QHttpServerResponse(QJsonDocument(json).toJson()); }); - qHttpServer.route("/v1/profile", [&]() { - std::cout << "http: profile" << std::endl; + qHttpServer.route("/v1/profile", [&]() -> QHttpServerResponse { + // std::cout << "http: profile" << std::endl; std::lock_guard<std::mutex> lg(pgm_image_mtx); + if (!::calibrationTableZ || !::calibrationTableX) + return QHttpServerResponse::StatusCode::ServiceUnavailable; + const Profile profile(::pixels, ::calibrationTableZ, ::calibrationTableX); @@ -453,7 +483,8 @@ int main(int argc, char* argv[]) .route("/v1/commands/resetEncoder", [&](const QHttpServerRequest& request) -> QHttpServerResponse { std::cout << "http: resetEncoder" << std::endl; - if (request.method() != QHttpServerRequest::Method::Post) { + if (request.method() != QHttpServerRequest::Method::Post) + { return QHttpServerResponse::StatusCode::NotFound; } @@ -468,7 +499,8 @@ int main(int argc, char* argv[]) .route("/v1/commands/startCalibration", [&](const QHttpServerRequest& request) -> QHttpServerResponse { std::cout << "http: startCalibration" << std::endl; - if (request.method() != QHttpServerRequest::Method::Post) { + if (request.method() != QHttpServerRequest::Method::Post) + { return QHttpServerResponse::StatusCode::NotFound; } @@ -485,7 +517,8 @@ int main(int argc, char* argv[]) .route("/v1/commands/gCode", [&](const QHttpServerRequest& request) -> QHttpServerResponse { std::cout << "http: gCode" << std::endl; - if (request.method() != QHttpServerRequest::Method::Post) { + if (request.method() != QHttpServerRequest::Method::Post) + { return QHttpServerResponse::StatusCode::NotFound; } @@ -520,7 +553,8 @@ int main(int argc, char* argv[]) "/v1/sensor/params", [&](const QHttpServerRequest& request) -> QHttpServerResponse { std::cout << "http: params" << std::endl; - switch (request.method()) { + switch (request.method()) + { case QHttpServerRequest::Method::Get: { std::lock_guard<std::mutex> lg(pgm_image_mtx); QJsonObject json; @@ -557,21 +591,28 @@ int main(int argc, char* argv[]) auto json = QJsonDocument::fromJson(request.body()).object(); - if (json.contains(exposureTimeKey)) { + if (json.contains(exposureTimeKey)) + { const int32_t value{json[exposureTimeKey].toInt()}; - if (value == 0) { - return QHttpServerResponse::StatusCode::NotFound; - } + if (value == 0) + return QHttpServerResponse::StatusCode:: + RequestRangeNotSatisfiable; qDebug() << "set new exposure time:" << value; - requested_params.exposureTime = value; + + // requested_params.exposureTime = value; + if (!camera->setExposureTimeUs(value)) + return QHttpServerResponse::StatusCode:: + RequestRangeNotSatisfiable; } - if (json.contains(laserLevelKey)) { + if (json.contains(laserLevelKey)) + { const int32_t value{json[laserLevelKey].toInt()}; - if (value == 0) { + if (value == 0) + { return QHttpServerResponse::StatusCode::NotFound; } @@ -582,7 +623,8 @@ int main(int argc, char* argv[]) "/sys/class/pwm/pwmchip2/pwm1/duty_cycle"}; QFile f{laserLevelFile}; - if (!f.open(QFile::ReadWrite)) { + if (!f.open(QFile::ReadWrite)) + { qDebug() << "cannot open laser level file:" << f.errorString(); qDebug() << "file path is" << f.fileName(); @@ -667,7 +709,8 @@ bool initLaser() QFile f{pwmExportFile}; - if (!f.open(QFile::WriteOnly)) { + if (!f.open(QFile::WriteOnly)) + { qWarning() << "cannot open" << f.fileName() << "for writing"; qWarning() << "error:" << f.errorString(); @@ -684,7 +727,8 @@ bool initLaser() f.close(); f.setFileName(periodFilename); - if (!f.open(QFile::WriteOnly)) { + if (!f.open(QFile::WriteOnly)) + { qWarning() << "cannot open" << f.fileName() << "for writing"; qWarning() << "error:" << f.errorString(); @@ -699,7 +743,8 @@ bool initLaser() f.close(); f.setFileName(dutyCycleFilename); - if (!f.open(QFile::WriteOnly)) { + if (!f.open(QFile::WriteOnly)) + { qWarning() << "cannot open" << f.fileName() << "for writing"; qWarning() << "error:" << f.errorString(); @@ -714,7 +759,8 @@ bool initLaser() f.close(); f.setFileName(enableFilename); - if (!f.open(QFile::WriteOnly)) { + if (!f.open(QFile::WriteOnly)) + { qWarning() << "cannot open" << f.fileName() << "for writing"; qWarning() << "error:" << f.errorString(); diff --git a/src/camera/icamera.h b/src/camera/icamera.h index 4245a68..588b23e 100644 --- a/src/camera/icamera.h +++ b/src/camera/icamera.h @@ -32,8 +32,14 @@ class ICamera { public: + virtual bool setExposureTimeUs(int value) = 0; + virtual bool setGain(int value) = 0; + +public: libcamera::Signal<std::shared_ptr<Pixels>> newPixels; libcamera::Signal<std::shared_ptr<Image>> newImage; + std::function<void(std::shared_ptr<Pixels>)> newPixelsCallback; + std::function<void(std::shared_ptr<Image>)> newImageCallback; public: virtual bool startStream() = 0; diff --git a/src/camera/innomakerov9281.cpp b/src/camera/innomakerov9281.cpp index a2d3136..73ceacb 100644 --- a/src/camera/innomakerov9281.cpp +++ b/src/camera/innomakerov9281.cpp @@ -15,7 +15,8 @@ // #include "rotaryencoder.h" #define LOGD(...) \ - do { \ + do \ + { \ printf(__VA_ARGS__); \ printf("\n"); \ } while (0) @@ -38,19 +39,23 @@ InnoMakerOV9281::~InnoMakerOV9281() int ret{-1}; - for (int i = 0; i < BUFFER_COUNT; ++i) { + for (int i = 0; i < BUFFER_COUNT; ++i) + { ret = munmap(video_buffer_ptr[i], img_size); - if (ret < 0) { + if (ret < 0) + { DBG("Munmap failed!!."); } } // std::cout << __func__ << std::endl; - if (m_cam_fd >= 0) { + if (m_cam_fd >= 0) + { int ret = close(m_cam_fd); - if (ret == -1) { + if (ret == -1) + { // std::cout << __func__ // << ": cannot close camera: " << strerror(errno) // << std::endl; @@ -69,7 +74,7 @@ std::vector<std::shared_ptr<ICamera> > InnoMakerOV9281::search() if (!cam->init()) return {}; - if (!cam->setExposureTimeMs(3000)) + if (!cam->setExposureTimeUs(3000)) return {}; if (!cam->setGain(3000)) @@ -83,20 +88,30 @@ bool InnoMakerOV9281::startStream() m_streamThread = std::jthread{[&](std::stop_token stopToken) { std::cout << "InnoMakerOV9281: start stream" << std::endl; - while (!stopToken.stop_requested()) { + while (!stopToken.stop_requested()) + { std::shared_ptr<Image> image = std::make_shared<Image>(); getImage(*image); // FIXME: backup emit value #ifdef emit #undef emit - std::cout << "emit new image" << std::endl << std::flush; - newImage.emit(image); - auto pixels = image->pixels(); - newPixels.emit(pixels); + // std::cout << "emit new image" << std::endl << std::flush; + // newImage.emit(image); + if (newImageCallback) + { + newImageCallback(image); + } + // newPixels.emit(pixels); + if (newPixelsCallback) + { + auto pixels = image->pixels(); + newPixelsCallback(pixels); + } } #define emit #endif - std::cout << "InnoMakerOV9281: stream interruption requested" << std::endl; + std::cout << "InnoMakerOV9281: stream interruption requested" + << std::endl; }}; return true; @@ -116,9 +131,23 @@ bool InnoMakerOV9281::init() return true; } -bool InnoMakerOV9281::setExposureTimeMs(int value) +bool InnoMakerOV9281::setExposureTimeUs(int valueUs) { - return setCamParam(V4L2_CID_EXPOSURE, value); + std::cout << __func__ << ": " << valueUs << std::endl << std::flush; + + /* + * Shutter Time. Value is from 8721ns to 8721*885ns, must be integral + * multiple of 8721ns . + * 8721xN(N =1,2,3,4,5.....855) + */ + // constexpr int exposureStep{8721}; + // constexpr int maxExposureStepMultiplier{885}; + // auto valueNs = valueUs; + // valueNs = (valueNs / exposureStep) * exposureStep; + + // std::clamp(valueNs, exposureStep, exposureStep * maxExposureStepMultiplier); + + return setCamParam(V4L2_CID_EXPOSURE, valueUs); } bool InnoMakerOV9281::setGain(int value) @@ -132,7 +161,8 @@ bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value) int ret = ioctl(m_cam_fd, VIDIOC_S_CTRL, &ctl); - if (ret < 0) { + if (ret < 0) + { fprintf(stderr, "cannot set cam param: id - %d, error - '%s'\n", v4l2controlId, @@ -141,6 +171,20 @@ bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value) return false; } + ret = ioctl(m_cam_fd, VIDIOC_G_CTRL, &ctl); + + if (ret < 0) + { + fprintf(stderr, + "cannot get cam param: id - %d, error - '%s'\n", + v4l2controlId, + strerror(errno)); + + return false; + } + + std::cout << __func__ << ": new value is " << ctl.value << std::endl; + return true; } @@ -148,8 +192,12 @@ bool InnoMakerOV9281::openCam() { m_cam_fd = open(videoDevice, O_RDWR); - if (m_cam_fd < 0) { - fprintf(stderr, "cannot open cam '%s', error: '%s'\n", videoDevice, strerror(errno)); + if (m_cam_fd < 0) + { + fprintf(stderr, + "cannot open cam '%s', error: '%s'\n", + videoDevice, + strerror(errno)); return false; } @@ -161,8 +209,12 @@ bool InnoMakerOV9281::selectCam(int camIdx) int input = camIdx; int ret = ioctl(m_cam_fd, VIDIOC_S_INPUT, &input); - if (ret < 0) { - fprintf(stderr, "cannot select cam: idx - %d, error - '%s'\n", camIdx, strerror(errno)); + if (ret < 0) + { + fprintf(stderr, + "cannot select cam: idx - %d, error - '%s'\n", + camIdx, + strerror(errno)); return false; } @@ -181,8 +233,11 @@ bool InnoMakerOV9281::initCam() int ret = ioctl(m_cam_fd, VIDIOC_TRY_FMT, &format); - if (ret < 0) { - fprintf(stderr, "cannot try cam format: error - '%s'\n", strerror(errno)); + if (ret < 0) + { + fprintf(stderr, + "cannot try cam format: error - '%s'\n", + strerror(errno)); return false; } @@ -192,8 +247,11 @@ bool InnoMakerOV9281::initCam() ret = ioctl(m_cam_fd, VIDIOC_S_FMT, &format); - if (ret < 0) { - fprintf(stderr, "cannot set cam format: error - '%s'\n", strerror(errno)); + if (ret < 0) + { + fprintf(stderr, + "cannot set cam format: error - '%s'\n", + strerror(errno)); return false; } @@ -204,13 +262,17 @@ bool InnoMakerOV9281::initCam() request.memory = V4L2_MEMORY_MMAP; ret = ioctl(m_cam_fd, VIDIOC_REQBUFS, &request); - if (ret < 0) { - fprintf(stderr, "cannot set cam request buffers: ioctl error - '%s'\n", strerror(errno)); + if (ret < 0) + { + fprintf(stderr, + "cannot set cam request buffers: ioctl error - '%s'\n", + strerror(errno)); return false; } - if (request.count < BUFFER_COUNT) { + if (request.count < BUFFER_COUNT) + { fprintf(stderr, "cannot set cam request buffers\n"); return false; @@ -221,20 +283,27 @@ bool InnoMakerOV9281::initCam() buffer.type = request.type; buffer.memory = V4L2_MEMORY_MMAP; - for (uint32_t i = 0; i < request.count; i++) { + for (uint32_t i = 0; i < request.count; i++) + { buffer.index = i; ret = ioctl(m_cam_fd, VIDIOC_QUERYBUF, &buffer); - if (ret < 0) { + if (ret < 0) + { DBG("ioctl(VIDIOC_QUERYBUF) failed %d(%s)", errno, strerror(errno)); return false; } DBG("buffer.length: %d", buffer.length); DBG("buffer.m.offset: %d", buffer.m.offset); - video_buffer_ptr[i] = (uint8_t *) - mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, m_cam_fd, buffer.m.offset); - if (video_buffer_ptr[i] == MAP_FAILED) { + video_buffer_ptr[i] = (uint8_t *) mmap(NULL, + buffer.length, + PROT_READ | PROT_WRITE, + MAP_SHARED, + m_cam_fd, + buffer.m.offset); + if (video_buffer_ptr[i] == MAP_FAILED) + { DBG("mmap() failed %d(%s)", errno, strerror(errno)); return false; } @@ -243,7 +312,8 @@ bool InnoMakerOV9281::initCam() buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; ret = ioctl(m_cam_fd, VIDIOC_QBUF, &buffer); - if (ret != 0) { + if (ret != 0) + { DBG("ioctl(VIDIOC_QBUF) failed %d(%s)", errno, strerror(errno)); return false; } @@ -251,7 +321,8 @@ bool InnoMakerOV9281::initCam() int buffer_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; ret = ioctl(m_cam_fd, VIDIOC_STREAMON, &buffer_type); - if (ret != 0) { + if (ret != 0) + { DBG("ioctl(VIDIOC_STREAMON) failed %d(%s)", errno, strerror(errno)); return false; } @@ -271,7 +342,8 @@ bool InnoMakerOV9281::getImage(Image &image) double elapsedTime = (curr.tv_sec - prev.tv_sec) * 1000.0; // sec to ms elapsedTime += (curr.tv_usec - prev.tv_usec) / 1000.0; // us to ms - if (elapsedTime > 1000.) { + if (elapsedTime > 1000.) + { // fprintf(stderr, "fps: %d, sec: %d\n", counter, curr.tv_sec); fprintf(stderr, "sum: %d,\tcorr: %d,\tval: %d\n", @@ -298,12 +370,14 @@ bool InnoMakerOV9281::getImage(Image &image) ret = ioctl(m_cam_fd, VIDIOC_DQBUF, &buffer); - if (ret != 0) { + if (ret != 0) + { DBG("ioctl(VIDIOC_DQBUF) failed %d(%s)", errno, strerror(errno)); return false; } - if (buffer.index < 0 || buffer.index >= BUFFER_COUNT) { + if (buffer.index < 0 || buffer.index >= BUFFER_COUNT) + { DBG("invalid buffer index: %d", buffer.index); return false; } @@ -313,12 +387,14 @@ bool InnoMakerOV9281::getImage(Image &image) // TODO: fill // image.counters.encoderPosition = RotaryEncoder::instance()->position(); image.counters.measurementCounter = buffer.sequence; - image.counters.timestampUs = buffer.timestamp.tv_sec * 1000 * 1000 + buffer.timestamp.tv_usec; + image.counters.timestampUs = buffer.timestamp.tv_sec * 1000 * 1000 + + buffer.timestamp.tv_usec; memcpy(image.data, video_buffer_ptr[buffer.index], img_size); ret = ioctl(m_cam_fd, VIDIOC_QBUF, &buffer); - if (ret != 0) { + if (ret != 0) + { DBG("ioctl(VIDIOC_QBUF) failed %d(%s)", errno, strerror(errno)); return false; } diff --git a/src/camera/innomakerov9281.h b/src/camera/innomakerov9281.h index 2c1fb7c..8c3a14e 100644 --- a/src/camera/innomakerov9281.h +++ b/src/camera/innomakerov9281.h @@ -24,12 +24,12 @@ public: static std::vector<std::shared_ptr<ICamera>> search(); public: - bool startStream(); + bool startStream() override; bool init(); - bool setExposureTimeMs(int value); - bool setGain(int value); + bool setExposureTimeUs(int value) override; + bool setGain(int value) override; bool getImage(Image &image); diff --git a/src/camera/ov9281.h b/src/camera/ov9281.h index 83a86ac..6014483 100644 --- a/src/camera/ov9281.h +++ b/src/camera/ov9281.h @@ -23,7 +23,7 @@ class Pixels; class OV9281 : public QObject, public ICamera { - Q_OBJECT + // Q_OBJECT public: ~OV9281(); @@ -37,6 +37,17 @@ public: bool startStream() override; void printControls(); + bool setExposureTimeUs(int value) override + { + assert(false); + return false; + }; + bool setGain(int value) override + { + assert(false); + return false; + }; + // signals public: // TODO: image->pixels in separate thread |
