Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions octoprint_smart_filament_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(self):

self.print_started = False
self.last_movement_time = None
self.last_reset_time = datetime.now()
self.lastE = -1
self.currentE = -1
self.START_DISTANCE_OFFSET = 7
Expand Down Expand Up @@ -57,6 +58,20 @@ def pause_command(self):
def motion_sensor_detection_distance(self):
return int(self._settings.get(["motion_sensor_detection_distance"]))

#Periodic Reset

@property
def motion_sensor_reset_enabled(self):
return int(self._settings.get_boolean(["motion_sensor_reset_enabled"]))

@property
def motion_sensor_reset_remaining_ratio(self):
return int(self._settings.get(["motion_sensor_reset_remaining_ratio"]))

@property
def motion_sensor_reset_interval(self):
return int(self._settings.get(["motion_sensor_reset_interval"]))

#Timeout detection
@property
def motion_sensor_max_not_moving(self):
Expand Down Expand Up @@ -120,6 +135,9 @@ def get_settings_defaults(self):

# Distance detection
motion_sensor_detection_distance = 15, # Recommended detection distance from Marlin would be 7
motion_sensor_reset_enabled = False,
motion_sensor_reset_remaining_ratio = 70,
motion_sensor_reset_interval = 240,

# Timeout detection
motion_sensor_max_not_moving=45, # Maximum time no movement is detected - default continously
Expand Down Expand Up @@ -267,6 +285,19 @@ def calc_distance(self, pE):
)
self._data.remaining_distance = (self._data.remaining_distance - deltaDistance)

if self.motion_sensor_reset_enabled:
try:
remain_ratio = (self._data.remaining_distance / self.motion_sensor_detection_distance)
last_reset_seconds = (datetime.now() - self.last_reset_time).total_seconds()

if remain_ratio < (self.motion_sensor_reset_remaining_ratio / 100) and last_reset_seconds > self.motion_sensor_reset_interval :
self._logger.debug(f"Performing reset below ratio threshold of {self.motion_sensor_reset_remaining_ratio}% after {self.motion_sensor_reset_interval}")
self.last_reset_time = datetime.now()
self._setup_sensor()

except Exception as e:
self._logger.error(f"Error in ratio reset: {e}")

else:
# Only pause the print if its been over 5 seconds since the last movement. Stops pausing when the CPU gets hung up.
if (datetime.now() - self.last_movement_time).total_seconds() > 10:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@
<span class="help-block"><small>GCode commands that are sent to the printer are interpreted. Don't choose this value too small, because it could make the detection too sensitive.</small></span>
</div>
</div>

<!-- Periodic Reset -->
<h6>{{ _('Periodic Reset') }}</h6>
<div class="control-group">
<label class="control-label">{{ _('Enable Periodic Reset:') }}</label>
<div class="controls" data-toggle="tooltip" title="{{ _('Enable or disble periodic reset.') }}">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_reset_enabled"> {{ _('Enable Periodic Reset') }}
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Remaining Filament Threshold') }}</label>
<div class="controls">
<div class="input-append" data-toggle="tooltip" title="{{ _('The threshold below which the periodic reset will kick in.') }}">
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_reset_remaining_ratio">
<span class="add-on">%</span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Reset Interval') }}</label>
<div class="controls">
<div class="input-append" data-toggle="tooltip" title="{{ _('The interval at which the periodic reset is allowed to trigger, in seconds.') }}">
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settingsViewModel.settings.plugins.smartfilamentsensor.motion_sensor_reset_interval">
<span class="add-on">sec</span>
</div>
</div>
</div>
<!-- Connection test -->
<h6>{{_('Connection Test') }}</h6>
<div class="control-group">
Expand Down