Skip to content
Merged
Prev Previous commit
Next Next commit
adding static method to retrieve values
giving register's content e.g.  ConversionTime.get_seconds(ConversionTime.TIME_332_us) will return 0.000332 .

similarly, ConversionTime.get_seconds(obj.voltage_conversion_time) will return the value reading from registry
  • Loading branch information
gpongelli committed Feb 16, 2021
commit 18f7da8e779bf8337738e4729f99e45910b7010f
21 changes: 21 additions & 0 deletions adafruit_ina260.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ class ConversionTime:
TIME_4_156_ms = const(0x6)
TIME_8_244_ms = const(0x7)

@staticmethod
def get_seconds(time_enum):
"""Retrieve the time in seconds giving value read from register"""
conv_dict = {
0: 140e-6,
1: 204e-6,
2: 332e-6,
3: 558e-6,
4: 1.1e-3,
5: 2.116e-3,
6: 4.156e-3,
7: 8.244e-3,
}
return conv_dict[time_enum]


class AveragingCount:
"""Options for ``averaging_count``
Expand Down Expand Up @@ -129,6 +144,12 @@ class AveragingCount:
COUNT_512 = const(0x6)
COUNT_1024 = const(0x7)

@staticmethod
def get_averaging_count(avg_count):
"""Retrieve the number of measurements giving value read from register"""
conv_dict = {0: 1, 1: 4, 2: 16, 3: 64, 4: 128, 5: 256, 6: 512, 7: 1024}
return conv_dict[avg_count]


# pylint: enable=too-few-public-methods

Expand Down