Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDamerell committed Aug 17, 2024
1 parent e25701f commit 9dee54a
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bambustatetranslater",
"bambuwebcamhelper",
"bblp",
"bedcooldownwatcher",
"bootstraper",
"boundarydonotcross",
"brotli",
Expand All @@ -35,6 +36,7 @@
"companionconfigfile",
"coms",
"continuousprint",
"Cooldown",
"Creality",
"Creality's",
"creds",
Expand Down
6 changes: 6 additions & 0 deletions bambu_octoeverywhere/bambustatetranslater.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ def IsPrintWarmingUp(self):
if state.stg_cur == 1 or state.stg_cur == 2 or state.stg_cur == 7 or state.stg_cur == 9 or state.stg_cur == 11 or state.stg_cur == 14:
return True
return False


# ! Interface Function ! The entire interface must change if the function is changed.
# Returns the current hotend temp and bed temp in celsius if they are available, otherwise None.
def GetTemps(self):
return (None, None)
6 changes: 6 additions & 0 deletions moonraker_octoeverywhere/moonrakerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ def IsPrintWarmingUp(self):
return self.CheckIfPrinterIsWarmingUp_WithPrintStats(result)


# ! Interface Function ! The entire interface must change if the function is changed.
# Returns the current hotend temp and bed temp in celsius if they are available, otherwise None.
def GetTemps(self):
return (None, None)


#
# Helpers
#
Expand Down
Empty file.
97 changes: 97 additions & 0 deletions octoeverywhere/notifications/bedcooldownwatcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import time
import logging
import threading

from ..sentry import Sentry
from ..repeattimer import RepeatTimer

# A simple class to watch for the bed to cooldown and then fires a notification.
class BedCooldownWatcher:

# The amount of time between checks.
c_checkIntervalSec = 2

# The max amount of time we will allow this to keep watching.
c_maxWatcherRuntimeSec = 60 * 20


_Instance = None


@staticmethod
def Init(logger:logging.Logger, notificationHandler, printerStateInterface) -> None:
BedCooldownWatcher._Instance = BedCooldownWatcher(logger, notificationHandler, printerStateInterface)


@staticmethod
def Get() -> 'BedCooldownWatcher':
return BedCooldownWatcher._Instance


def __init__(self, logger:logging.Logger, notificationHandler, printerStateInterface):
self.Logger = logger
self.NotificationHandler = notificationHandler
self.PrinterStateInterface = printerStateInterface
self.Timer = None
self.TimerStartSec = None
self.Lock = threading.Lock()


# Starts the waiter if it's not running.
def Start(self) -> None:
with self.Lock:
# Stop any running timer.
self._stopTimerUnderLock()

self.Logger.info("Bed cooldown watcher starting")
self.TimerStartSec = time.time()

# Start a new timer.
self.Timer = RepeatTimer(self.Logger, BedCooldownWatcher.c_checkIntervalSec, self._timerCallback)
self.Timer.start()


# Stops the timer if it's running.
def Stop(self):
with self.Lock:
self._stopTimerUnderLock()



def _stopTimerUnderLock(self):
if self.Timer is not None:
self.Logger.info("Bed cooldown watcher stopped.")
self.Timer.Stop()
self.Timer = None


def _timerCallback(self):
try:
# Check if we should stop watching.
if time.time() - self.TimerStartSec > BedCooldownWatcher.c_maxWatcherRuntimeSec:
self.Logger.info("Bed cooldown watcher, max runtime reached. Stopping.")
self.Stop()
return

# Try to get the current temps
(_, bedTemp) = self.PrinterStateInterface.GetTemps()
if bedTemp is None:
self.Logger.info("Bed cooldown watcher, no bed temp available. Stopping.")
self.Stop()
return

# When the bed is under ~90F, we will consider it cooled down.
if bedTemp > 33:
# Keep waiting.
self.Logger.debug(f"Bed cooldown watcher, bed temp is {bedTemp}. Waiting...")
return

# The bed is cooled down.
self.Logger.info("Bed cooldown watcher, bed is cooled down.")
self.Stop()

# Fire the notification.
self.NotificationHandler.OnBedCooldownComplete(bedTemp)

except Exception as e:
Sentry.Exception("BedCooldownWatcher exception in timer callback", e)
14 changes: 14 additions & 0 deletions octoeverywhere/notificationshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .printinfo import PrintInfoManager, PrintInfo
from .snapshotresizeparams import SnapshotResizeParams
from .debugprofiler import DebugProfiler, DebugProfilerFeatures
from .notifications.bedcooldownwatcher import BedCooldownWatcher

try:
# On some systems this package will install but the import will fail due to a missing system .so.
Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(self, logger:logging.Logger, printerStateInterface):
self.FirstLayerTimer = None
self.FinalSnapObj:FinalSnap = None
self.Gadget = Gadget(logger, self, self.PrinterStateInterface)
BedCooldownWatcher.Init(logger, self, self.PrinterStateInterface)

# Define all the vars we use locally in the notification handler
self.PrintCookie = ""
Expand All @@ -84,6 +86,9 @@ def __init__(self, logger:logging.Logger, printerStateInterface):
# But we pass none, so we don't delete any print infos that might be on disk we will try to recover when connected to the server.
self._RecoverOrRestForNewPrint(None)

# TODO remove me
BedCooldownWatcher.Get().Start()


# Called to start a new print.
# On class init, this can be called with printCookie=None, but after that we should always have a print cookie.
Expand Down Expand Up @@ -349,6 +354,7 @@ def OnFailed(self, fileName:str, durationSecStr:str = None, reason:str = None):
self._updateCurrentFileName(fileName)
self._updateToKnownDuration(durationSecStr)
self.StopTimers()
BedCooldownWatcher.Get().Start()
self._sendEvent("failed", { "Reason": reason})


Expand All @@ -360,6 +366,7 @@ def OnDone(self, fileName:str = None, durationSecStr:str = None):
self._updateCurrentFileName(fileName)
self._updateToKnownDuration(durationSecStr)
self.StopTimers()
BedCooldownWatcher.Get().Start()
self._sendEvent("done", useFinalSnapSnapshot=True)


Expand Down Expand Up @@ -540,6 +547,13 @@ def OnPrintTimerProgress(self):
self._sendEvent("timerprogress", { "HoursCount": str(self.PingTimerHoursReported) })


# Called by the bed cooldown watcher when the bed is done cooling down.
def OnBedCooldownComplete(self, bedTempCelsius:float):
if self._shouldIgnoreEvent():
return
self._sendEvent("bedcooldowncomplete", { "BedTempC": str(bedTempCelsius) })


#
# Note this values are important!
# The cost of getting the current z offset is decently high, and thus we can't check it too often.
Expand Down
6 changes: 6 additions & 0 deletions octoprint_octoeverywhere/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def IsPrintWarmingUp(self):
return False


# ! Interface Function ! The entire interface must change if the function is changed.
# Returns the current hotend temp and bed temp in celsius if they are available, otherwise None.
def GetTemps(self):
return (None, None)


# A mock of the popup UI interface.
NotificationHandlerInstance = None
class StatusChangeHandlerStub():
Expand Down
6 changes: 6 additions & 0 deletions octoprint_octoeverywhere/printerstateobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ def IsPrintWarmingUp(self):

# We aren't warming up.
return False


# ! Interface Function ! The entire interface must change if the function is changed.
# Returns the current hotend temp and bed temp in celsius if they are available, otherwise None.
def GetTemps(self):
return (None, None)

0 comments on commit 9dee54a

Please sign in to comment.