summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/calibration.cpp11
-rw-r--r--src/calibration.h3
-rw-r--r--src/camera/veyeimx287m.cpp50
-rw-r--r--src/camera/veyeimx287m.h1
-rw-r--r--src/constants.h4
-rw-r--r--src/dumps.cpp46
-rw-r--r--src/image.cpp10
-rw-r--r--src/main.cpp176
-rw-r--r--src/pixels.cpp64
-rw-r--r--src/pixels.h12
-rw-r--r--src/printerclient.cpp9
-rw-r--r--src/printerclient.h2
-rw-r--r--src/protocols/httpserver.cpp12
-rw-r--r--src/typedefs.h3
14 files changed, 279 insertions, 124 deletions
diff --git a/src/calibration.cpp b/src/calibration.cpp
index 41e6270..3462565 100644
--- a/src/calibration.cpp
+++ b/src/calibration.cpp
@@ -1,5 +1,7 @@
#include "calibration.h"
+#include "fuck_intel.h"
+
#include <execution>
#include <iostream>
@@ -140,7 +142,7 @@ void interpolate(
qWarning() << "delta" << delta;
qWarning() << "c[left/i/right]" << c[left] << c[i] << c[right];
- exit(EXIT_FAILURE);
+ // exit(EXIT_FAILURE);
}
}
@@ -173,7 +175,8 @@ QImage calibrationTableToImage(
const auto& column = calibrationTable->at(colIdx);
for (size_t rowIdx = 0; rowIdx < column.size(); ++rowIdx) {
- bool hasValue = !qFuzzyIsNull(column.at(rowIdx));
+ const auto &v = column.at(rowIdx);
+ bool hasValue = !qFuzzyIsNull(v);
notNull += int(hasValue);
@@ -204,14 +207,14 @@ QList<Pixels> filter(
Pixels sum = *it;
size_t count{1};
- qDebug() << "\t" << __func__ << "enc pos:" << it->counters.encoderPosition;
+ // qDebug() << "\t" << __func__ << "enc pos:" << it->counters.encoderPosition;
++it;
while (it != rawProfiles.constEnd()
&& it->counters.encoderPosition == sum.counters.encoderPosition) {
sum += *it;
++count;
- qDebug() << "\t\t" << __func__ << "enc pos:" << it->counters.encoderPosition;
+ // qDebug() << "\t\t" << __func__ << "enc pos:" << it->counters.encoderPosition;
++it;
}
diff --git a/src/calibration.h b/src/calibration.h
index 4876c17..113cad9 100644
--- a/src/calibration.h
+++ b/src/calibration.h
@@ -23,6 +23,9 @@ void dumpCalibrationPixels(const std::vector<std::shared_ptr<Pixels> > &calibrat
bool dump(const CalibrationTablePtr &table, const QString &filename);
// TODO: implement median filter
+/*!
+ * \brief filter - N pixels at pos -> 1 avg pixels at pos
+ */
QList<Pixels> filter(const QList<Pixels> &rawProfiles);
bool calibrateX(const QList<Pixels> &rawProfiles, CalibrationTablePtr table);
diff --git a/src/camera/veyeimx287m.cpp b/src/camera/veyeimx287m.cpp
index 0bb0724..4556112 100644
--- a/src/camera/veyeimx287m.cpp
+++ b/src/camera/veyeimx287m.cpp
@@ -242,8 +242,8 @@ VeyeIMX287m::~VeyeIMX287m()
void VeyeIMX287m::onMoveFinished()
{
- qDebug() << "================================================";
- qDebug() << __func__;
+ // qDebug() << "================================================";
+ // qDebug() << __func__;
m_isMoving = false;
}
@@ -700,9 +700,11 @@ void VeyeIMX287m::calcPixelsLoop(std::stop_token stopToken)
if (m_calibrationPixels[pixels->counters.encoderPosition].size() < neededCount) {
m_calibrationPixels[pixels->counters.encoderPosition].push_back(pixels);
- qDebug() << "\tenc:" << pixels->counters.encoderPosition << "in pos:"
- << m_calibrationPixels[pixels->counters.encoderPosition].size()
- % neededCount;
+ // qDebug() << "\tenc:" << pixels->counters.encoderPosition << "in pos:"
+ // << m_calibrationPixels[pixels->counters.encoderPosition].size()
+ // % neededCount;
+
+ pixels->debugPrintIfInvalid();
} else {
// if (m_stand->posMm() < m_zRangeMm) {
if (m_stand->posMm() < debugZRange) {
@@ -712,7 +714,11 @@ void VeyeIMX287m::calcPixelsLoop(std::stop_token stopToken)
<< "\tcurrPos:" << m_stand->posMm() << "zRange:" << m_zRangeMm
<< m_zRangeMm / ::discretesInRage
<< "\tpos steps:" << pixels->counters.encoderPosition
- << "\tcollected:" << m_calibrationPixels.size();
+ << "\tcollected:" << m_calibrationPixels.size() << '/'
+ << (m_calibrationPixels.contains(pixels->counters.encoderPosition)
+ ? m_calibrationPixels.at(pixels->counters.encoderPosition)
+ .size()
+ : 0);
m_isMoving = true;
emit moveMm(m_zRangeMm / ::discretesInRage);
@@ -754,21 +760,23 @@ bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex)
// TODO: move this shit to some beautiful place
if (elapsedTime > 1000. && processedCounter != 0) {
- fprintf(stderr,
- "fps: %d\tdropped: %lu sec: %ld "
- "dq: %lu get: %lu rot: %lu pix: %lu sum: %lu corr: "
- "%lu val: %lu\n",
- counter,
- dropped_count,
- curr.tv_sec % 1000,
- dq_elapsed_ns / 1000 / processedCounter,
- get_elapsed_ns / 1000 / processedCounter,
- rot_elapsed_ns / 1000 / processedCounter,
- pix_elapsed_ns / 1000 / processedCounter,
- sum_elapsed_ns / 1000 / processedCounter,
- corr_elapsed_ns / 1000 / processedCounter,
- // max_elapsed_ns / 1000 / processedCounter,
- value_elapsed_ns / 1000 / processedCounter);
+ if (false) {
+ fprintf(stderr,
+ "fps: %d\tdropped: %lu sec: %ld "
+ "dq: %lu get: %lu rot: %lu pix: %lu sum: %lu corr: "
+ "%lu val: %lu\n",
+ counter,
+ dropped_count,
+ curr.tv_sec % 1000,
+ dq_elapsed_ns / 1000 / processedCounter,
+ get_elapsed_ns / 1000 / processedCounter,
+ rot_elapsed_ns / 1000 / processedCounter,
+ pix_elapsed_ns / 1000 / processedCounter,
+ sum_elapsed_ns / 1000 / processedCounter,
+ corr_elapsed_ns / 1000 / processedCounter,
+ // max_elapsed_ns / 1000 / processedCounter,
+ value_elapsed_ns / 1000 / processedCounter);
+ }
dq_elapsed_ns = 0;
get_elapsed_ns = 0;
diff --git a/src/camera/veyeimx287m.h b/src/camera/veyeimx287m.h
index d084788..326a43a 100644
--- a/src/camera/veyeimx287m.h
+++ b/src/camera/veyeimx287m.h
@@ -174,6 +174,7 @@ private:
bool m_isCalibrating{false};
bool m_ignoreFrames{false};
// std::vector<std::shared_ptr<Pixels>> m_calibrationPixels;
+ // FIXME: std::multimap/unordered_multimap
std::unordered_map<decltype(Counters::encoderPosition), std::vector<std::shared_ptr<Pixels>>>
m_calibrationPixels;
std::shared_ptr<IStand> m_stand;
diff --git a/src/constants.h b/src/constants.h
index b950ede..635243e 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -22,7 +22,9 @@ constexpr size_t radxa_raw_img_size = radxa_raw_img_stride * img_height;
constexpr uint32_t patternSize = 16;
-constexpr float hardcodedZRangeMm{175.f};
+// constexpr float hardcodedZRangeMm{175.f};
+// constexpr float hardcodedZRangeMm{200};
+constexpr float hardcodedZRangeMm{50.f};
constexpr size_t calibrationTableHeight{0x4000}; // 16384
namespace {
diff --git a/src/dumps.cpp b/src/dumps.cpp
index 0a85c1b..3e138b3 100644
--- a/src/dumps.cpp
+++ b/src/dumps.cpp
@@ -8,13 +8,16 @@
#include <QJsonDocument>
#include <QJsonObject>
+#include "fuck_intel.h"
+
+#include <execution>
#include <iostream>
QList<Pixels> openDump(
const QString &dumpPath)
{
QString dirToRead{dumpPath};
- qDebug() << "trying to open dump path:" << dirToRead;
+ qDebug() << __func__ << "trying to open dump path:" << dirToRead;
if (dirToRead.isEmpty()) {
qDebug() << "dumpPath not specified. looking into" << dumpsRoot;
@@ -44,34 +47,44 @@ QList<Pixels> openDump(
const auto sort = QDir::Name;
auto filenames = dumpDir.entryList(nameFilters, filter, sort);
+ qDebug() << __func__ << "dump path" << dumpPath << "has" << filenames.size() << "files";
if (filenames.isEmpty()) {
qDebug() << "no filenames found in" << dumpDir.path();
return {};
}
- qDebug() << "create results array" << filenames.size();
+ if (false) {
+ filenames = filenames.first(10000);
+ }
+
+ std::sort(filenames.begin(), filenames.end(), [](const auto &a, const auto &b) {
+ const auto mca = a.split('_').at(3).toInt();
+ const auto mcb = b.split('_').at(3).toInt();
+ return mca < mcb;
+ });
+
+ qDebug() << __func__ << "create results array" << filenames.size();
auto resultOptionals = QScopedPointer(
new QList<std::optional<Pixels>>(filenames.size()));
- qDebug() << "created results array";
+ qDebug() << __func__ << "created results array";
QElapsedTimer t;
t.start();
- qDebug() << "open real files";
- std::cout << "here" << std::endl;
+ qDebug() << __func__ << "open real files";
+ // std::cout << "here" << std::endl;
- std::transform(
- std::execution::par_unseq,
- filenames.begin(),
- filenames.end(),
- resultOptionals->begin(),
- [dirToRead](const auto &filename) {
- // std::cout << '.';
- // auto rawProfile = openRawProfile(dirToRead + "/" + filename);
- auto rawProfile = Pixels::load(dirToRead + "/" + filename);
+ std::transform(/*std::execution::par_unseq,*/
+ filenames.begin(),
+ filenames.end(),
+ resultOptionals->begin(),
+ [dirToRead](const auto &filename) {
+ // std::cout << '.';
+ // auto rawProfile = openRawProfile(dirToRead + "/" + filename);
+ auto rawProfile = Pixels::load(dirToRead + '/' + filename);
- return rawProfile;
- });
+ return rawProfile;
+ });
filenames.clear();
filenames.squeeze();
@@ -79,6 +92,7 @@ QList<Pixels> openDump(
qDebug() << Q_FUNC_INFO << "open raw profiles: elapsed (ms)" << t.elapsed();
// std::cout << std::endl;
+ // FIXME: no effect
std::remove_if(std::execution::par,
resultOptionals->begin(),
resultOptionals->end(),
diff --git a/src/image.cpp b/src/image.cpp
index b840b3d..636ec78 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -206,6 +206,16 @@ std::shared_ptr<Pixels> Image::sharedPixels()
result->counters = counters;
std::transform(rotated_cw.cbegin(), rotated_cw.cend(), result->pixels.begin(), process_column);
+
+ static bool found{false};
+
+ for (const auto &p : result->pixels) {
+ if (p > 400) {
+ std::cout << "AAAAAAAAAAAAAAAAAAAAA too big pixel values: " << p << std::endl;
+ found = true;
+ }
+ }
+
pix_elapsed_ns += t.nsecsElapsed();
return result;
diff --git a/src/main.cpp b/src/main.cpp
index c717c7e..24e2bf4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,5 @@
// cpp and linux
-#include <chrono>
#include <csignal>
-#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <linux/videodev2.h>
@@ -29,17 +27,11 @@
#include "calibration.h"
#include "camera/veyeimx287m.h"
#include "dumps.h"
-#include "imagealgos.h"
#include "printerclient.h"
#include "profile.h"
#include "protocols/httpserver.h"
#include "scanner.h"
-//
-#include "rapidjson/document.h"
-#include "rapidjson/stringbuffer.h"
-#include "rapidjson/writer.h"
-
extern uint8_t pgm_image[64 + img_width * img_height * sizeof(uint8_t)];
extern size_t pgm_image_size;
extern std::mutex pgm_image_mtx;
@@ -56,7 +48,7 @@ ScanningModeFlags scanningModeFlags{ScanningModeFlags::None};
QElapsedTimer calibrationTimer;
-extern volatile int32_t positionSteps;
+// extern volatile int32_t positionSteps;
requested_params_t requested_params;
@@ -69,9 +61,7 @@ QMutex calibrationPixelsMutex;
using namespace std::chrono_literals;
auto printPixels = [](const auto &pixels) {
- for (size_t i = (img_width - 10) / 2;
- i < img_width - ((img_width - 10) / 2);
- ++i) {
+ for (size_t i = (img_width - 10) / 2; i < img_width - ((img_width - 10) / 2); ++i) {
std::cout << pixels[i] << " ";
}
std::cout << std::endl;
@@ -137,8 +127,30 @@ int main(int argc, char *argv[])
// }
// qDebug() << p.counters.encoderPosition << p.counters.encoderPosition;
// return EXIT_SUCCESS;
+ auto stand = std::make_shared<Esp32Stand>(QHostAddress{"192.168.18.248"}, 80, 1600);
+
+ if (false) {
+ if (false) {
+ // const QString tmpFN{"/home/radxa/dumps/binz/raw_profile_meas_100009_enc_35416"};
+ // const QString tmpFN{"/home/radxa/dumps/binz/raw_profile_meas_754290_enc_276336"};
+ // const QString tmpFN{"/tmp/raw_pixels"};
+ const QString tmpFN{"/home/radxa/dumps/binz/raw_profile_meas_509718_enc_185763"};
+ const auto tmpRP = Pixels::load(tmpFN);
+
+ if (!tmpRP) {
+ qCritical() << "cannot open raw profiles file:" << tmpFN;
+ exit(EXIT_FAILURE);
+ }
+
+ const auto rp = *tmpRP;
+ qDebug() << "tmp enc pos:" << rp.counters.encoderPosition;
+
+ for (const auto &p : rp.pixels) {
+ qDebug() << '\t' << p;
+ }
- if (true) {
+ exit(EXIT_FAILURE);
+ }
// open binary calibration table
if (false) {
initializers << QtConcurrent::run([&]() {
@@ -183,6 +195,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ // for (const auto &rp : rawProfiles) {
+ // if (rp.debugPrintIfInvalid()) {
+ // exit(EXIT_FAILURE);
+ // }
+ // }
+
+ exit(EXIT_FAILURE);
+
std::sort(rawProfiles.begin(), rawProfiles.end(), [](const auto &a, const auto &b) {
return a.counters.encoderPosition < b.counters.encoderPosition;
});
@@ -190,24 +210,31 @@ int main(int argc, char *argv[])
qDebug() << "filtered z-profiles count is" << filteredRawProfiles.count();
if (!calibrateZ(std::move(filteredRawProfiles),
- requested_params.stepsPerMm,
+ // requested_params.stepsPerMm,
+ stand->stepsPerMm(),
scanner->calibrationTableZ())) {
qCritical() << "Z calibration failed, exiting";
exit(EXIT_FAILURE);
}
// DEBUG
- interpolate(scanner->calibrationTableZ());
+ // interpolate(scanner->calibrationTableZ());
- if (!dump(scanner->calibrationTableZ(),
- QStringLiteral("/home/%1/dumps/binz.calibration_table").arg(user))) {
+ const auto dumpZPath = QStringLiteral("/home/%1/dumps/binz.calibration_table")
+ .arg(user);
+ if (!dump(scanner->calibrationTableZ(), dumpZPath)) {
qApp->exit(EXIT_FAILURE);
}
+ qDebug() << __func__ << "calibration table z dump finished";
+
+ calibrationTableToImage(scanner->calibrationTableZ()).save(dumpZPath + ".png");
+ qDebug() << __func__ << "calibration table z image dump finished";
}
qDebug() << "--------------------------------------------------------";
- if (false) {
+ if (true) {
+ qDebug() << "open dump x";
auto rawProfiles = openDump(QStringLiteral("/home/%1/dumps/binx").arg(user));
qDebug() << "raw x-profiles count is" << rawProfiles.size();
@@ -219,12 +246,20 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ qDebug() << __func__ << "try to interpolate";
interpolate(scanner->calibrationTableX());
+ qDebug() << __func__ << "interpolated";
- if (!dump(scanner->calibrationTableX(),
- QStringLiteral("/home/%1/dumps/binx.calibration_table").arg(user))) {
+ const auto dumpXPath = QStringLiteral("/home/%1/dumps/binx.calibration_table")
+ .arg(user);
+
+ if (!dump(scanner->calibrationTableX(), dumpXPath)) {
+ qCritical() << "cannot dump calibration table x, exit with failure";
qApp->exit(EXIT_FAILURE);
}
+ qDebug() << __func__ << "calibration table x dump finished";
+ calibrationTableToImage(scanner->calibrationTableZ()).save(dumpXPath + ".png");
+ qDebug() << __func__ << "calibration table x image dump finished";
}
}
// exit(EXIT_SUCCESS);
@@ -233,8 +268,6 @@ int main(int argc, char *argv[])
scanner->startAllProtocols();
httpServer->start();
- auto stand = std::make_shared<Esp32Stand>(QHostAddress{"192.168.18.248"}, 80, 1600);
-
QHttpServer qHttpServer;
qHttpServer.route("/v1/profile", [&]() -> QHttpServerResponse {
@@ -253,74 +286,75 @@ int main(int argc, char *argv[])
return QHttpServerResponse(QJsonDocument(json).toJson());
});
- qHttpServer
- .route("/v1/commands/resetEncoder",
- [&](const QHttpServerRequest &request) -> QHttpServerResponse {
- std::cout << "http: resetEncoder" << std::endl;
- if (request.method() != QHttpServerRequest::Method::Post) {
- return QHttpServerResponse::StatusCode::NotFound;
- }
-
- qDebug() << "reset encoder";
+ qHttpServer.route("/v1/commands/resetEncoder",
+ [&](const QHttpServerRequest &request) -> QHttpServerResponse {
+ std::cout << "http: resetEncoder" << std::endl;
+ if (request.method() != QHttpServerRequest::Method::Post) {
+ return QHttpServerResponse::StatusCode::NotFound;
+ }
- positionSteps = 0;
+ qDebug() << "reset encoder";
- return QHttpServerResponse::StatusCode::Ok;
- });
+ // positionSteps = 0;
+ stand->resetPosSteps();
- qHttpServer
- .route("/v1/commands/startCalibration",
- [&](const QHttpServerRequest &request) -> QHttpServerResponse {
- std::cout << "http: startCalibration" << std::endl;
- if (request.method() != QHttpServerRequest::Method::Post) {
- return QHttpServerResponse::StatusCode::NotFound;
- }
+ return QHttpServerResponse::StatusCode::Ok;
+ });
- qDebug() << "start calibration";
+ qHttpServer.route("/v1/commands/startCalibration",
+ [&](const QHttpServerRequest &request) -> QHttpServerResponse {
+ std::cout << "http: startCalibration" << std::endl;
+ if (request.method() != QHttpServerRequest::Method::Post) {
+ return QHttpServerResponse::StatusCode::NotFound;
+ }
- // TODO: use flags
- scanningModeFlags = ScanningModeFlags::Calibration;
- calibrationTimer.start();
- QObject::connect(camera.get(), &ICamera::moveMm, stand.get(), &IStand::moveMm);
- QObject::connect(stand.get(),
- &IStand::moveFinished,
- camera.get(),
- &ICamera::onMoveFinished);
+ qDebug() << "start calibration";
+ // TODO: use flags
+ scanningModeFlags = ScanningModeFlags::Calibration;
+ calibrationTimer.start();
+ QObject::connect(camera.get(),
+ &ICamera::moveMm,
+ stand.get(),
+ &IStand::moveMm);
+ QObject::connect(stand.get(),
+ &IStand::moveFinished,
+ camera.get(),
+ &ICamera::onMoveFinished);
- //camera->startCalibration(stand, 200);
- camera->startCalibration(stand, 200);
+ //camera->startCalibration(stand, 200);
+ // camera->startCalibration(stand, 200);
+ camera->startCalibration(stand, ::debugZRange);
- return QHttpServerResponse::StatusCode::Ok;
- });
+ return QHttpServerResponse::StatusCode::Ok;
+ });
- qHttpServer
- .route("/v1/commands/gCode",
- [&](const QHttpServerRequest &request) -> QHttpServerResponse {
- std::cout << "http: gCode" << std::endl;
- if (request.method() != QHttpServerRequest::Method::Post) {
- return QHttpServerResponse::StatusCode::NotFound;
- }
+ qHttpServer.route("/v1/commands/gCode",
+ [&](const QHttpServerRequest &request) -> QHttpServerResponse {
+ std::cout << "http: gCode" << std::endl;
+ if (request.method() != QHttpServerRequest::Method::Post) {
+ return QHttpServerResponse::StatusCode::NotFound;
+ }
- const auto command = request.body();
+ const auto command = request.body();
- qDebug() << "send gCode:" << command;
+ qDebug() << "send gCode:" << command;
- // WARNING: tmp logic
- auto distanceMm = command.split(' ').at(1);
- distanceMm.remove(0, 1);
+ // WARNING: tmp logic
+ auto distanceMm = command.split(' ').at(1);
+ distanceMm.remove(0, 1);
- // printerClient.sendCommand(command);
- stand->moveMm(distanceMm.toInt());
+ // printerClient.sendCommand(command);
+ stand->moveMm(distanceMm.toInt());
- return QHttpServerResponse::StatusCode::Ok;
- });
+ return QHttpServerResponse::StatusCode::Ok;
+ });
qDebug() << "listen: " << qHttpServer.listen(QHostAddress::Any, 8081);
////////////////////////////////////////////////////////////////////////////
std::clog << std::flush;
std::cerr << std::flush;
- std::cout << "ok for now" << std::endl << std::flush;
+ std::cout << __func__ << ": ok for now" << std::endl << std::flush;
auto result = app.exec();
diff --git a/src/pixels.cpp b/src/pixels.cpp
index e6d359c..5b7b226 100644
--- a/src/pixels.cpp
+++ b/src/pixels.cpp
@@ -1,5 +1,7 @@
#include "pixels.h"
+#include "fuck_intel.h"
+
#include <execution>
#include <filesystem>
#include <fstream>
@@ -38,13 +40,21 @@ std::optional<Pixels> Pixels::load(
if (!std::filesystem::exists(filepath)) {
std::cerr << "no such file: " << filepath << std::endl;
- return {};
+ return std::nullopt;
+ }
+
+ const auto fileSize = std::filesystem::file_size(filepath);
+
+ if (fileSize != sizeof(Pixels)) {
+ std::cerr << "wrong file size: " << filepath << std::endl;
+ std::cerr << "sizeof(Pixels): " << sizeof(Pixels) << std::endl;
+ return std::nullopt;
}
std::ifstream ifs(filepath, std::ios::in | std::ios::binary);
if (!ifs)
- return {};
+ return std::nullopt;
Pixels result;
ifs.read(reinterpret_cast<char*>(&result), sizeof(Pixels));
@@ -53,9 +63,11 @@ std::optional<Pixels> Pixels::load(
if (!ifs) {
std::cerr << "cannot read " << filepath << std::endl;
- return {};
+ return std::nullopt;
}
+ result.debugPrintIfInvalid();
+
return result;
}
@@ -87,6 +99,8 @@ bool Pixels::save(
return false;
}
+ debugPrintIfInvalid();
+
std::cout << "saved pixels at enc pos " << counters.encoderPosition << std::endl;
return true;
@@ -104,7 +118,51 @@ Pixels::operator bool() const
return result;
}
+bool Pixels::debugPrintIfInvalid() const
+{
+ const bool valid{std::find_if(std::execution::par_unseq,
+ pixels.cbegin(),
+ pixels.cend(),
+ [](const auto &p) { return p > 280; })
+ == pixels.cend()};
+
+ if (!valid) {
+ qCritical() << Q_FUNC_INFO << "got invalid profile:" << *this;
+ }
+
+ return valid;
+}
+
// std::lock_guard<std::mutex> Pixels::lock()
// {
// return std::move(std::lock_guard{m_mtx});
// }
+
+QDebug &operator<<(QDebug &debug, const Pixels &pixels)
+{
+ QDebugStateSaver saver{debug};
+ const auto &c = pixels.counters;
+ const auto &px = pixels.pixels;
+
+ QList<double> numbers;
+
+ for (size_t i{0}; i < 4 && i < px.size(); ++i) {
+ numbers << px.at(i);
+ }
+
+ for (size_t i{(px.size() - 4) / 2}; i < px.size() / 2 + 2 && i < px.size(); ++i) {
+ numbers << px.at(i);
+ }
+
+ for (size_t i{px.size() - 4 - 1}; i < px.size(); ++i) {
+ numbers << px.at(i);
+ }
+
+ debug.nospace().noquote() << QStringLiteral("Pixels { ts: %1 mc: %2 ep: %3 [ %4 ] }")
+ .arg(QString::number(c.timestampUs),
+ QString::number(c.measurementCounter),
+ QString::number(c.encoderPosition))
+ << qSetRealNumberPrecision(4) << numbers;
+
+ return debug;
+}
diff --git a/src/pixels.h b/src/pixels.h
index 06a8654..07f1c8f 100644
--- a/src/pixels.h
+++ b/src/pixels.h
@@ -1,10 +1,8 @@
#pragma once
#include <array>
-#include <mutex>
-
-#include "fuck_intel.h"
+#include <QDebug>
#include <QString>
#include "constants.h"
@@ -52,4 +50,12 @@ struct Pixels
// private:
// std::mutex m_mtx;
+
+ /*!
+ * \brief debugPrintIfInvalid - print profile if invalid
+ * \return `true` if valid, `false` otherwise
+ */
+ bool debugPrintIfInvalid() const;
};
+
+QDebug &operator<<(QDebug &debug, const Pixels &pixels); \ No newline at end of file
diff --git a/src/printerclient.cpp b/src/printerclient.cpp
index c19e2a8..946df72 100644
--- a/src/printerclient.cpp
+++ b/src/printerclient.cpp
@@ -114,6 +114,11 @@ double Esp32Stand::posMm()
return m_posSteps / double(m_stepsPerMm);
}
+uint32_t Esp32Stand::stepsPerMm() const
+{
+ return m_stepsPerMm;
+}
+
bool Esp32Stand::moveMm(const double mm)
{
return moveSteps(mm * m_stepsPerMm);
@@ -121,7 +126,7 @@ bool Esp32Stand::moveMm(const double mm)
bool Esp32Stand::moveSteps(const int steps)
{
- qDebug() << __func__ << "move" << steps << "steps";
+ // qDebug() << __func__ << "move" << steps << "steps";
// QElapsedTimer t;
// t.start();
@@ -142,7 +147,7 @@ bool Esp32Stand::moveSteps(const int steps)
// qDebug() << "here";
connect(reply, &QNetworkReply::finished, this, [reply, &mtx]() {
- qDebug() << reply->readAll();
+ // qDebug() << reply->readAll();
mtx.unlock();
});
// qDebug() << "here2";
diff --git a/src/printerclient.h b/src/printerclient.h
index 232dad8..90ca3e0 100644
--- a/src/printerclient.h
+++ b/src/printerclient.h
@@ -21,6 +21,7 @@ public:
virtual bool resetPosSteps() = 0;
virtual int posSteps() = 0;
virtual double posMm() = 0;
+ virtual uint32_t stepsPerMm() const = 0;
/*!
* \warning be careful when rounding mm to steps
*/
@@ -39,6 +40,7 @@ public:
bool resetPosSteps() override;
int posSteps() override;
double posMm() override;
+ uint32_t stepsPerMm() const override;
bool moveMm(const double mm) override;
bool moveSteps(const int steps) override;
diff --git a/src/protocols/httpserver.cpp b/src/protocols/httpserver.cpp
index 219bd76..e5772da 100644
--- a/src/protocols/httpserver.cpp
+++ b/src/protocols/httpserver.cpp
@@ -45,7 +45,7 @@ bool HttpServer::start()
// TODO: route automatically
const auto pixelsPath = apiPrefix + "/pixels";
const auto profilesPath = apiPrefix + "/profile";
- qDebug().noquote() << Q_FUNC_INFO << ": pixelsPath: " << pixelsPath;
+ // qDebug().noquote() << Q_FUNC_INFO << ": pixelsPath: " << pixelsPath;
// TODO: get rid of lamdas, there should be a better way
m_server->route(pixelsPath, [this]() { return GET_pixels(); });
@@ -73,7 +73,7 @@ bool HttpServer::start()
const auto result = m_server->listen(m_address, m_port);
- qDebug().noquote() << Q_FUNC_INFO << ": listen: " << result;
+ // qDebug().noquote() << Q_FUNC_INFO << ": listen: " << result;
if (!result) {
m_server.reset();
@@ -134,6 +134,14 @@ QHttpServerResponse HttpServer::GET_pixels()
// FIXME: inc m_camera->processedCounter
// FIXME: not thread-safe, don't use this static shared_ptr at all
const auto pixels = image->sharedPixels();
+ if (false) {
+ const QString dstFN{"/tmp/raw_pixels"};
+
+ qDebug() << "save raw pixels to" << dstFN;
+ if (!pixels->save(dstFN)) {
+ qCritical() << "cannot save pixels to" << dstFN;
+ }
+ }
// const auto lines = pixelsToLines(::pixels);
const auto lines = pixelsToLines(*pixels);
diff --git a/src/typedefs.h b/src/typedefs.h
index 7ed8411..ec7d231 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -2,6 +2,7 @@
#include <libcamera/pixel_format.h>
+// TODO: implement qDebug operator<<
struct Counters
{
uint32_t timestampUs{0};
@@ -13,7 +14,7 @@ struct requested_params_t
{
int32_t exposureTime{1000};
int32_t laserLevel{3000};
- uint32_t stepsPerMm{200};
+ // uint32_t stepsPerMm{200};
};
enum ScanningModeFlags : uint8_t { None = 0, Calibration };