Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'ABL-Support-Dev' into ABL-Support
Browse files Browse the repository at this point in the history
  • Loading branch information
maocypher committed Oct 30, 2020
2 parents cc0a4d4 + 682b6f2 commit d7f5569
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
60 changes: 36 additions & 24 deletions octoprint_smart_filament_sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
from __future__ import absolute_import

import octoprint.plugin
from octoprint.events import Events
import RPi.GPIO as GPIO
Expand All @@ -16,8 +15,7 @@ class SmartFilamentSensor(octoprint.plugin.StartupPlugin,
octoprint.plugin.SettingsPlugin):

def initialize(self):
self._logger.info(
"Running RPi.GPIO version '{0}'".format(GPIO.VERSION))
self._logger.info("Running RPi.GPIO version '{0}'".format(GPIO.VERSION))
if GPIO.VERSION < "0.6": # Need at least 0.6 for edge detection
raise Exception("RPi.GPIO must be greater than 0.6")
GPIO.setwarnings(False) # Disable GPIO warnings
Expand Down Expand Up @@ -88,8 +86,7 @@ def _setup_sensor(self):
GPIO.add_event_detect(self.motion_sensor_pin, GPIO.BOTH, callback=self.reset_distance)

if self.motion_sensor_enabled == False:
self._logger.info(
"Motion sensor is deactivated")
self._logger.info("Motion sensor is deactivated")
self.motion_sensor_filament_moving = True
self.motion_sensor = None

Expand Down Expand Up @@ -123,23 +120,38 @@ def get_template_configs(self):

# Sensor methods
def motion_sensor_start(self):
if self.motion_sensor_enabled and self.motion_sensor == None:
if self.motion_sensor == None:
self._logger.debug("Sensor enabled: " + str(self.motion_sensor_enabled))
if (self.mode == 0):
self._logger.debug("GPIO mode: Board Mode")
else:
self._logger.debug("GPIO mode: BCM Mode")
self._logger.debug("GPIO pin: " + str(self.motion_sensor_pin))
if(self.detection_method == 0):
self._logger.debug("Detection Mode: Timeout detection")
self._logger.debug("Timeout: " + str(self.motion_sensor_max_not_moving))
elif (self.detection_method == 1):
self._logger.debug("Detection Mode: Distance detection")
self._logger.debug("Distance: " + str(self.motion_sensor_detection_distance))
self._logger.debug("Sampling time: " + str(self.motion_sensor_sampling_time))

# Distance detection
if (self.detection_method == 1):
samplingTime = self.motion_sensor_sampling_time/1000
self.motion_sensor = FilamentMotionSensorDistanceDetection(1, "MotionSensorDistanceDetectionThread", self._printer, samplingTime)
self.remaining_distance = self.motion_sensor_detection_distance
self.motion_sensor.start()
self._logger.info("Motion sensor started: Distance detection")
if self.motion_sensor_enabled:

# Timeout detection
elif (self.detection_method == 0):
self.motion_sensor = FilamentMotionSensorTimeoutDetection(1, "MotionSensorTimeoutDetectionThread", self.motion_sensor_pin, self.motion_sensor_max_not_moving, self._logger, pCallback=self.printer_change_filament)
self.motion_sensor.start()
self._logger.info("Motion sensor started: Timeout detection")
# Distance detection
if (self.detection_method == 1):
samplingTime = self.motion_sensor_sampling_time/1000
self.motion_sensor = FilamentMotionSensorDistanceDetection(1, "MotionSensorDistanceDetectionThread", self._printer, samplingTime)
self.remaining_distance = self.motion_sensor_detection_distance
self.motion_sensor.start()
self._logger.info("Motion sensor started: Distance detection")

# Timeout detection
elif (self.detection_method == 0):
self.motion_sensor = FilamentMotionSensorTimeoutDetection(1, "MotionSensorTimeoutDetectionThread", self.motion_sensor_pin, self.motion_sensor_max_not_moving, self._logger, pCallback=self.printer_change_filament)
self.motion_sensor.start()
self._logger.info("Motion sensor started: Timeout detection")

self.send_code = False
self.send_code = False

def motion_sensor_stop(self):
if(self.motion_sensor != None):
Expand All @@ -150,13 +162,13 @@ def motion_sensor_stop(self):
# Sensor callbacks
def printer_change_filament (self):
if(not self.send_code):
#self._logger.debug("Motion sensor detected no movement")
self._logger.debug("Motion sensor detected no movement")
#self._printer.pause_print()
self._printer.commands("M600")
self.send_code = True

def reset_distance (self, pPin):
#self._logger.debug("Motion sensor detected movement")
self._logger.debug("Motion sensor detected movement")
if(self.remaining_distance < self.motion_sensor_detection_distance):
self.remaining_distance = self.motion_sensor_detection_distance

Expand Down Expand Up @@ -199,8 +211,8 @@ def on_event(self, event, payload):
self.lastE = self.currentE
self.currentE = payload.get('e')

#self._logger.debug("Remaining Distance: " + str(self.remaining_distance))
#self._logger.info("LastE: " + str(self.lastE) + "; CurrentE: " + str(self.currentE))
self._logger.debug("Remaining Distance: " + str(self.remaining_distance))
self._logger.debug("LastE: " + str(self.lastE) + "; CurrentE: " + str(self.currentE))
if(self.remaining_distance > 0):
# Calculate the remaining distance from detection distance
# currentE - lastE is the delta distance
Expand Down Expand Up @@ -235,7 +247,7 @@ def get_update_information(self):


__plugin_name__ = "Smart Filament Sensor"
__plugin_version__ = "1.1.0"
__plugin_version__ = "1.1.1"
__plugin_pythoncompat__ = ">=2.7,<4"

def __plugin_load__():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def run(self):
# The new state of the GPIO pin is read and determinated.
# It is checked if motion is detected and printed to the console.
def motion(self, pPin):
self.lastMotion = time.time()
self.lastMotion = time.time()
self._logger.debug("Motion detected at " + str(self.lastMotion))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
plugin_name = "Octoprint-Smart-Filament-Sensor"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.1.0"
plugin_version = "1.1.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit d7f5569

Please sign in to comment.