Skip to content

Commit

Permalink
Remove timing thread that crashes and added a wx.timer for outside st…
Browse files Browse the repository at this point in the history
…age movement sensing
  • Loading branch information
iandobbie committed Aug 17, 2023
1 parent 59816df commit fd85aae
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cockpit/gui/macroStage/macroStageXY.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ def __init__(self, *args, **kwargs):
self._OnObjectiveChanged,
)

#many stages have an external control that cockpit knows nothing about
#eg an xy(z) joystick. So setup a wx timer to poll the position
#and update if it changes.
self._positionCache = [0.0 for x in range(len
(cockpit.interfaces.stageMover.getPosition()))]
self._timer = wx.Timer(self)
#poll every 1 s (1000 ms)
self._timer.Start(1000)
self.Bind(wx.EVT_TIMER, self.onTimer)

#code that the wx timer calls to check postion on a regular basisis.
def onTimer(self, evt):
position=cockpit.interfaces.stageMover.getPosition()
for i,pos in enumerate(position):
if pos != self._positionCache[i]:
events.publish(events.STAGE_POSITION, i, pos)
self._positionCache[i] = pos

def OnDestroy(self, evt):
self._timer.Stop()

## Safety limits have changed, which means we need to force a refresh.
# \todo Redrawing everything just to tackle the safety limits is a bit
# excessive.
Expand Down

0 comments on commit fd85aae

Please sign in to comment.