Skip to content

Issue #411 - Adding pause button compatibility in imager service#930

Closed
babo989 wants to merge 2 commits intomainfrom
Feature-Pause
Closed

Issue #411 - Adding pause button compatibility in imager service#930
babo989 wants to merge 2 commits intomainfrom
Feature-Pause

Conversation

@babo989
Copy link
Copy Markdown
Collaborator

@babo989 babo989 commented Mar 31, 2026

Acquisition Pause/Resume Feature

Branch (Python): Feature-Pause
Dashboard Branch (Node-RED): Feature-Pause
Date: 2026-03-30


Summary

Adds the ability to pause and resume an active acquisition. Pause takes effect between frames — it will not interrupt a pump mid-flow or a capture mid-save, keeping the acquisition state clean and resumable.


Python Changes

controller/imager/stopflow.py — Core pause logic

New state: Added _paused threading.Event to Routine.__init__().

Modified run_step() — Added a blocking loop at the top of each step (after completion/interruption checks, before the pump runs):

# Block while paused, checking for interruption every second
while self._paused.is_set():
    if self._interrupted.wait(timeout=1.0):
        loguru.logger.info("Image acquisition was interrupted while paused!")
        return None

This means:

  • Pause only takes effect between frames (after the current frame completes)
  • While paused, the routine checks for stop/interrupt every 1 second
  • Stopping while paused works immediately (within 1s)

New methods:

def pause(self) -> None:
    """Pause the routine between steps."""
    self._paused.set()

def resume(self) -> None:
    """Resume the routine after being paused."""
    self._paused.clear()

New property:

@property
def paused(self) -> bool:
    """Check whether the routine is currently paused."""
    return self._paused.is_set()

controller/imager/main.py — MQTT integration

Imager._handle_new_message() — Added two new action handlers:

elif action == "pause" and self._active_routine is not None:
    self._active_routine.pause()
elif action == "resume" and self._active_routine is not None:
    self._active_routine.resume()

ImageAcquisitionRoutine — Added pause() and resume() methods that delegate to the routine and publish MQTT status:

def pause(self) -> None:
    self._routine.pause()
    self._mqtt_client.publish("status/imager", '{"status":"Paused"}')

def resume(self) -> None:
    self._routine.resume()
    self._mqtt_client.publish("status/imager", '{"status":"Resumed"}')

Node-RED Changes

All changes are in flows.json on the Acquisition tab (71ede8b7dd88d90e).

UI Template (body node — 79bccc0355eb5d87)

New data property:

  • acq_paused: false

New button (below Start/Stop, visible only during acquisition):

<v-row v-if="acq_status === 'on'" class="align-center pa-0">
  <v-col cols="12" class="pa-0">
    <v-btn block :color="acq_paused ? 'green' : 'orange'" variant="outlined"
      class="mt-2" style="height: 48px" @click="handlePauseToggle">
      {{ acq_paused ? 'Resume Acquisition' : 'Pause Acquisition' }}
    </v-btn>
  </v-col>
</v-row>

New method:

handlePauseToggle() {
  this.acq_paused = !this.acq_paused;
  if (typeof this.send !== "function") return;
  this.send({
    topic: "pause_control",
    payload: { action: this.acq_paused ? "pause" : "resume" }
  });
  this.acq_status_message = this.acq_paused ? "Paused" : "Resumed";
},

Updated computed properties:

  • formattedStatus: "Paused" → "Acquisition paused. You may adjust settings.", "Resumed" → "Acquisition resumed."
  • statusColor: "Paused" → orange, "Resumed" → green

Updated status watcher:

  • Sets acq_paused = true on "paused" status, false on "resumed"
  • Resets acq_paused = false when acquisition ends (done/stopped/error)

New Flow Nodes

Node ID Type Purpose
pause? a1b2c3d4e5f60001 switch Routes pause_control topic separately from normal acq messages
pause/resume a1b2c3d4e5f60002 function Sets msg.topic = "imager/image" for MQTT publish

Message Routing

body → pageleave filter → pageview filter → pause? switch
  ├─ topic="pause_control" → pause/resume func → MQTT out (imager/image)
  └─ else → acq_status switch → (stop / start paths, unchanged)

MQTT API

New Actions

Topic Payload Effect
imager/image {"action": "pause"} Pauses acquisition between frames
imager/image {"action": "resume"} Resumes paused acquisition

New Status Messages

Topic Payload When
status/imager {"status": "Paused"} After pause takes effect
status/imager {"status": "Resumed"} After resume

Behavior

  • Pause button appears only when acquisition is running (acq_status === 'on')
  • Button toggles between orange "Pause Acquisition" and green "Resume Acquisition"
  • Pause takes effect after the current frame completes (pump + stabilize + capture)
  • Stopping while paused works — the interrupt check runs every 1 second
  • When acquisition ends (done/stopped/error), pause state resets automatically
  • No changes to existing start/stop flow, MQTT topics, or pump/camera control

@sonnyp
Copy link
Copy Markdown
Collaborator

sonnyp commented Apr 1, 2026

This was already merged in #929

@sonnyp sonnyp closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants