summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2026-03-06 20:40:29 +0100
committerNikita Kostovsky <nikita@kostovsky.me>2026-03-06 20:40:29 +0100
commit05f0938a65c4f8c330791097680e1e094260bb60 (patch)
treed11e48c96eed6de03c51b793081310d96dee8618 /src/main.cpp
parent051cb23a807a6914e2cda7e3b08d69ed29f347dd (diff)
refactoring
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp95
1 files changed, 59 insertions, 36 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 208004f..2d86dac 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -68,11 +68,6 @@ QMutex calibrationPixelsMutex;
using namespace std::chrono_literals;
-namespace {
-CalibrationTablePtr calibrationTableZ;
-CalibrationTablePtr calibrationTableX;
-} // namespace
-
auto printPixels = [](const auto &pixels) {
for (size_t i = (img_width - 10) / 2;
i < img_width - ((img_width - 10) / 2);
@@ -99,30 +94,44 @@ int main(int argc, char *argv[])
QList<QFuture<void>> initializers;
qDebug() << "size of raw profile" << sizeof(Pixels);
- if (false) {
+
+ // Pixels p;
+ // p.counters.encoderPosition = 123;
+ // if (!p.save("/tmp/tmp.pixels")) {
+ // return EXIT_FAILURE;
+ // }
+
+ // Pixels p1;
+ // if (!p1.load("/tmp/tmp.pixels")) {
+ // return EXIT_FAILURE;
+ // }
+ // qDebug() << p.counters.encoderPosition << p.counters.encoderPosition;
+ // return EXIT_SUCCESS;
+
+ if (true) {
// open binary calibration table
- if (true) {
+ if (false) {
initializers << QtConcurrent::run([&]() {
- if (!openCalibrationTable(
- "/home/user/dumps/binz.calibration_table",
- // "/tmp/binz.calibration_table",
- ::calibrationTableZ)) {
+ if (!openCalibrationTable(QStringLiteral("/home/%1/dumps/binz.calibration_table")
+ .arg(user),
+ // "/tmp/binz.calibration_table",
+ ::calibrationTableZ)) {
exit(EXIT_FAILURE);
}
});
initializers << QtConcurrent::run([&]() {
- if (!openCalibrationTable(
- "/home/user/dumps/binx.calibration_table",
- // "/tmp/binx.calibration_table",
- ::calibrationTableX)) {
+ if (!openCalibrationTable(QStringLiteral("/home/%1/dumps/binx.calibration_table")
+ .arg(user),
+ // "/tmp/binx.calibration_table",
+ ::calibrationTableX)) {
exit(EXIT_FAILURE);
}
});
}
if (false) {
- auto rawProfiles = openDump("/home/user/dumps/binx");
+ auto rawProfiles = openDump(QStringLiteral("/home/%1/dumps/binx").arg(user));
qDebug() << "raw x-profiles count is" << rawProfiles.size();
// qDebug() << "height" << calibrationColumnHeight;
@@ -136,22 +145,29 @@ int main(int argc, char *argv[])
}
// load binary calibration dumps and calibrate
- if (false) {
+ if (true) {
if (true) {
- auto rawProfiles = openDump("/home/user/dumps/binz");
+ auto rawProfiles = openDump(QStringLiteral("/home/%1/dumps/binz").arg(user));
qDebug() << "raw z-profiles count is" << rawProfiles.size();
+ if (rawProfiles.empty()) {
+ return EXIT_FAILURE;
+ }
+
auto filteredRawProfiles = filter(std::move(rawProfiles));
qDebug() << "filtered z-profiles count is"
<< filteredRawProfiles.count();
::calibrationTableZ = calibrateZ(std::move(filteredRawProfiles),
requested_params.stepsPerMm);
+ // DEBUG
+ ::calibrationTableX = CalibrationTablePtr{new CalibrationTable{{0}}};
+ memset(::calibrationTableX.get(), 0, sizeof(CalibrationTable));
interpolate(::calibrationTableZ);
if (!dump(::calibrationTableZ,
- "/home/user/dumps/binz.calibration_table")) {
+ QStringLiteral("/home/%1/dumps/binz.calibration_table").arg(user))) {
qApp->exit(EXIT_FAILURE);
}
}
@@ -159,8 +175,8 @@ int main(int argc, char *argv[])
qDebug()
<< "--------------------------------------------------------";
- if (true) {
- auto rawProfiles = openDump("/home/user/dumps/binx");
+ if (false) {
+ auto rawProfiles = openDump(QStringLiteral("/home/%1/dumps/binx").arg(user));
qDebug() << "raw x-profiles count is" << rawProfiles.size();
auto filteredRawProfiles = filter(std::move(rawProfiles));
@@ -172,13 +188,15 @@ int main(int argc, char *argv[])
interpolate(::calibrationTableX);
if (!dump(::calibrationTableX,
- "/home/user/dumps/binx.calibration_table")) {
+ QStringLiteral("/home/%1/dumps/binx.calibration_table").arg(user))) {
qApp->exit(EXIT_FAILURE);
}
}
}
}
+ // exit(EXIT_SUCCESS);
+
QElapsedTimer t;
t.start();
@@ -205,32 +223,29 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- auto httpServer = std::make_shared<HttpServer>(camera);
-
- const auto scanner
- = std::make_shared<Scanner>(camera,
- std::vector<std::shared_ptr<IProtocol>>{
- httpServer});
+ // TODO: refactor: scanner and http server depend on each other
+ const auto scanner = std::make_shared<Scanner>(camera);
+ auto httpServer = std::make_shared<HttpServer>(scanner);
scanner->startAllProtocols();
+ httpServer->start();
- Esp32Stand stand{QHostAddress{"192.168.18.248"}, 80, 1600};
+ auto stand = std::make_shared<Esp32Stand>(QHostAddress{"192.168.18.248"}, 80, 1600);
QHttpServer qHttpServer;
qHttpServer.route("/v1/profile", [&]() -> QHttpServerResponse {
// std::cout << "http: profile" << std::endl;
- return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ // return QHttpServerResponse::StatusCode::ServiceUnavailable;
std::lock_guard<std::mutex> lg(pgm_image_mtx);
- if (!::calibrationTableZ || !::calibrationTableX)
- return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ // if (!::calibrationTableZ || !::calibrationTableX)
+ // return QHttpServerResponse::StatusCode::ServiceUnavailable;
- const Profile profile(::pixels,
- ::calibrationTableZ,
- ::calibrationTableX);
+ const Profile profile{::pixels, ::calibrationTableZ, ::calibrationTableX};
const QJsonObject json{{"profile", QJsonObject(profile)}};
+ // qDebug() << "profile:" << QJsonDocument(json).toJson();
return QHttpServerResponse(QJsonDocument(json).toJson());
});
@@ -263,6 +278,14 @@ int main(int argc, char *argv[])
// 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);
return QHttpServerResponse::StatusCode::Ok;
});
@@ -284,7 +307,7 @@ int main(int argc, char *argv[])
distanceMm.remove(0, 1);
// printerClient.sendCommand(command);
- stand.moveMm(distanceMm.toInt());
+ stand->moveMm(distanceMm.toInt());
return QHttpServerResponse::StatusCode::Ok;
});