Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding get_functions #28

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 26 additions & 10 deletions adafruit_emc2101/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def __init__(self, i2c_bus):
raise RuntimeError("No EMC2101 (part={}.{})".format(part, mfg))

self._full_speed_lsb = None # See _calculate_full_speed().
self.initialize()
self.emec2101_initialize()

def initialize(self):
def emec2101_initialize(self):
"""Reset the controller to an initial default configuration"""
self._tach_mode_enable = True
self._enabled_forced_temp = False
Expand All @@ -214,6 +214,15 @@ def devconfig(self):
"""
return self._config

def _get_internal_temperature(self):
"""The temperature as measured by the EMC2101's internal 8-bit
temperature sensor, which validly ranges from 0 to 85 and does not
support fractions (unlike the external readings).

:return: int temperature in Celsius.
"""
return self._int_temp

@property
def devstatus(self):
"""Read device status (alerts) register. See the STATUS_* bit
Expand All @@ -224,16 +233,11 @@ def devstatus(self):

@property
def internal_temperature(self):
"""The temperature as measured by the EMC2101's internal 8-bit
temperature sensor, which validly ranges from 0 to 85 and does not
support fractions (unlike the external readings).
"""internal temperature property"""

:return: int temperature in degrees centigrade.
"""
return self._int_temp

@property
def external_temperature(self):
def _get_external_temperature(self):
"""The temperature measured using the external diode. The value is
read as a fixed-point 11-bit value ranging from -64 to approx 126,
with fractional part of 1/8 degree.
Expand All @@ -259,17 +263,29 @@ def external_temperature(self):
return full_tmp

@property
def fan_speed(self):
def external_temperature(self):
"""External temperature Property"""

return self._get_external_temperature()

def _get_fan_speed(self):
"""The current speed in Revolutions per Minute (RPM).

:return: float fan speed rounded to 2dp.

"""
val = self._tach_read_lsb
val |= self._tach_read_msb << 8
if val < 1:
raise OSError("Connection")
return round(emc2101_regs.FAN_RPM_DIVISOR / val, 2)

@property
def fan_speed(self):
"""fan speed property"""

return self._get_fan_speed()

def _calculate_full_speed(self, pwm_f=None, dac=None):
"""Determine the LSB value for a 100% fan setting"""
if dac is None:
Expand Down
12 changes: 6 additions & 6 deletions adafruit_emc2101/emc2101_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ class EMC2101_EXT(EMC2101): # pylint: disable=too-many-instance-attributes

def __init__(self, i2c_bus):
super().__init__(i2c_bus)
self.initialize()

def initialize(self):
self.emc2101_ext_initialize()

def emc2101_ext_initialize(self):
"""Reset the controller to an initial default configuration."""
self.auto_check_status = False
self._last_status = 0
super().initialize()

def _check_status(self):
if self.auto_check_status:
Expand Down Expand Up @@ -201,7 +201,7 @@ def internal_temperature(self):
:return: int temperature in degrees centigrade.
"""
self._check_status()
return super().internal_temperature
return self._get_internal_temperature()

@property
def external_temperature(self):
Expand All @@ -218,7 +218,7 @@ def external_temperature(self):
(not behaving like a diode).
"""
self._check_status()
return super().external_temperature
return self._get_external_temperature()

@property
def fan_speed(self):
Expand All @@ -227,7 +227,7 @@ def fan_speed(self):
:return: float speed in RPM.
"""
self._check_status()
return super().fan_speed
return self._get_fan_speed()

@property
def dev_temp_critical_limit(self):
Expand Down
1 change: 0 additions & 1 deletion adafruit_emc2101/emc2101_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def initialize(self):
self.lut_enabled = True
# pylint: disable=attribute-defined-outside-init
self._fan_clk_ovr = True
super().initialize()
self._check_status()

def set_pwm_clock(self, use_preset=False, use_slow=False):
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio", "busio"]
autodoc_mock_imports = ["adafruit_register"]


intersphinx_mapping = {
Expand Down