-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path_tmc_ec_pin.py
More file actions
47 lines (37 loc) · 1.42 KB
/
_tmc_ec_pin.py
File metadata and controls
47 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Enable Control base module."""
from ._tmc_ec import TmcEnableControl
from ..tmc_gpio import Gpio, GpioMode
from .. import tmc_gpio
from ..tmc_logger import TmcLogger, Loglevel
class TmcEnableControlPin(TmcEnableControl):
"""Enable Control base class."""
@property
def pin_en(self):
"""pin_en property."""
return self._pin_en
def __init__(self, pin_en: int):
"""constructor."""
super().__init__()
self._pin_en = pin_en
def init(self, tmc_logger: TmcLogger):
"""Init: called by the Tmc class."""
super().init(tmc_logger)
self._tmc_logger.log(f"EN Pin: {self._pin_en}", Loglevel.DEBUG)
tmc_gpio.tmc_gpio.gpio_setup(self._pin_en, GpioMode.OUT, initial=Gpio.HIGH)
def __del__(self):
"""Destructor."""
self.deinit()
def deinit(self):
"""Destructor."""
super().deinit()
if hasattr(self, "_pin_en"):
tmc_gpio.tmc_gpio.gpio_cleanup(self._pin_en)
del self._pin_en
def set_motor_enabled(self, en):
"""Enables or disables the motor current output.
Args:
en (bool): whether the motor current output should be enabled
"""
if hasattr(self, "_pin_en"):
tmc_gpio.tmc_gpio.gpio_output(self._pin_en, not en)
self._tmc_logger.log(f"Motor output active: {en}", Loglevel.INFO)