From e90b28d8ccb9eedc19c23ebeb0129308a74e2865 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Tue, 16 Jun 2026 17:03:26 +0200 Subject: fix: add workaround for turning all printheads on/off --- src/Xpl2Client.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 3 deletions(-) (limited to 'src/Xpl2Client.h') diff --git a/src/Xpl2Client.h b/src/Xpl2Client.h index 49fbec5..cce2a47 100644 --- a/src/Xpl2Client.h +++ b/src/Xpl2Client.h @@ -9,8 +9,10 @@ #include "Xpl2Protocol.h" #include +#include #include #include +#include #include #include @@ -53,24 +55,64 @@ public: Q_INVOKABLE void connectToProxy (); /** Disconnect from the proxy. */ Q_INVOKABLE void disconnectFromProxy (); - /** Get the just connected Jetting Controller ID and Software Version. */ + /** + * Get the just connected Jetting Controller ID and Software Version. + * + * @deprecated Unreliable on real controllers: the printhead-count field is + * wrong (reports the heads before the first ID gap, not the true count). See + * docs/DISCREPANCIES.md (D3). Enumerate printheads via getPhVersion() and + * the jettingAvailable* helpers instead. Calling this emits errorOccurred(). + */ Q_INVOKABLE void getJcVersion (); /** Query the specified printhead's version info. */ Q_INVOKABLE void getPhVersion (int printheadId); /* -- CN_ Control commands ----------------------------------------- */ - /** Switch jetting on for all printheads. */ + /** + * Switch jetting on for all printheads (CN_JETTING_ALL_ON). + * + * @deprecated Broken on real controllers: only drives the printheads before + * the first gap in the ID sequence, even though it replies success. See + * docs/DISCREPANCIES.md (D6). Use jettingAvailableOn() instead. Calling this + * emits errorOccurred(). + */ Q_INVOKABLE void jettingAllOn (); /** Switch jetting on for all printheads with a per-nozzle mask (180 chars). */ Q_INVOKABLE void jettingOn (const QString &jettingMask); - /** Switch jetting off for all printheads. */ + /** + * Switch jetting off for all printheads (CN_JETTING_OFF). + * + * @deprecated Mirrors the jettingAllOn() defect on real controllers (only + * affects the heads before the first ID gap). See docs/DISCREPANCIES.md + * (D6). Use jettingAvailableOff() instead. Calling this emits + * errorOccurred(). + */ Q_INVOKABLE void jettingOff (); /** Switch jetting on for one printhead with a per-nozzle mask (12 chars). */ Q_INVOKABLE void phJettingOn (int printheadId, const QString &jettingMask); /** Switch jetting off for one printhead. */ Q_INVOKABLE void phJettingOff (int printheadId); + + /** + * Switch jetting ON for every *available* printhead — the working + * replacement for the broken jettingAllOn(). + * + * Probes every printhead's version (getPhVersion for IDs 1..15), then sends + * a per-head CN_PH_JETTING_ON (all-nozzles mask) to each printhead that + * reports a valid, non-zero version. Handles non-contiguous printhead IDs + * correctly (see docs/DISCREPANCIES.md, D2/D6). Asynchronous: emits + * jettingAvailableComplete() once the per-head commands have been sent. A + * second call while a scan is in progress is ignored. + */ + Q_INVOKABLE void jettingAvailableOn (); + /** + * Switch jetting OFF for every available printhead — the working replacement + * for the broken jettingOff(). Counterpart to jettingAvailableOn(); same + * probe-then-per-head behaviour with CN_PH_JETTING_OFF. + */ + Q_INVOKABLE void jettingAvailableOff (); /** Switch the JC identification LED on. */ Q_INVOKABLE void jcIdLedOn (); /** Switch the JC identification LED off. */ @@ -203,6 +245,11 @@ signals: void jettingOffResult (int controllerId, bool success); void phJettingOnResult (int controllerId, int printheadId, bool success); void phJettingOffResult (int controllerId, int printheadId, bool success); + /** Emitted when jettingAvailableOn()/Off() has finished probing versions and + * has sent the per-head jetting commands. @p printheadIds are the available + * heads that were jetted (sorted ascending). */ + void jettingAvailableComplete (bool turnedOn, + const QList &printheadIds); void jcIdLedOnResult (int controllerId, bool success); void jcIdLedOffResult (int controllerId, bool success); void phIdLedOnResult (int controllerId, int printheadId, bool success); @@ -298,6 +345,7 @@ private slots: void onSocketMessageReady (); void onSocketError (QAbstractSocket::SocketError error); void retryConnection (); + void onJettingScanTimeout (); private: void setupSocket (QTcpSocket &socket); @@ -343,6 +391,25 @@ private: void updateConnectedState (); QString logTag (const QTcpSocket *socket) const; + /* Working "jet all available" workaround for the broken CN_JETTING_ALL_ON / + CN_JETTING_OFF (see docs/DISCREPANCIES.md, D6): probe all printhead + versions, then jet every head that reports a valid version. */ + void startJettingScan (bool turnOn); + void finishJettingScan (); + static bool phVersionIsAvailable (const QString &mcuFirmwareVersion, + const QString &fpgaFirmwareVersion, + const QString &fpgaHardwareVersion, + const QString &bootloaderVersion); + + /* Highest printhead ID to probe (protocol allows up to 15: a 180-char + jetting mask is 12 chars x 15 heads). */ + static constexpr int MaxProbedPrintheadId = 15; + /* Give up waiting for version replies after this long and jet whatever + responded. */ + static constexpr int JettingScanTimeoutMs = 2000; + /* 12-char all-nozzles-on mask for one printhead. */ + static constexpr char AllNozzlesOnMask[] = "FFFFFFFFFFFF"; + QString m_host = QStringLiteral ("127.0.0.1"); quint16 m_commandPort = 9210; QTcpSocket m_commandSocket; @@ -355,4 +422,10 @@ private: QString m_firmwareVersion; QString m_hardwareVersion; int m_printheadCount = 0; + + QTimer m_jettingScanTimer; + bool m_jettingScanActive = false; + bool m_jettingScanTurnOn = false; + QSet m_jettingScanPending; + QList m_jettingScanAvailable; }; -- cgit v1.3.1