Skip to content

Commit

Permalink
.machine.adc: max_voltage calculated by calibration_v_max+calibration…
Browse files Browse the repository at this point in the history
…_offset
  • Loading branch information
kevinkk525 committed Apr 3, 2020
1 parent 13cea29 commit b904f3f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pysmartnode/components/machine/adc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
component: ADC
constructor_args: {
pin: 0 # ADC pin number or ADC object (even Amux pin object)
# calibration_v_max: 3.3 # optional, v_max for calibration of bad ADC sensors
# calibration_v_max: 3.3 # optional, v_max for calibration of bad ADC sensors. defaults to 3.3V
# calibration_offset: 0 # optional, voltage offset for calibration of bad ADC sensors
# atten: null # optional, attn value to use. Voltages aren't adapted to this config, set the calibration kwargs for it to work
# max_voltage: 3.3 # optional, defaults to 3.3V, can be given to set max voltage of atten value
# max_voltage: null # optional, defaults to calibration_v_max+calibration_offset
}
}
Does not publish anything, just unifies reading of esp8266 ADC, esp32, Amux, Arudino, etc
You can pass any ADC object or pin number to ADC() and it will return a corretly subclassed pyADC object
"""

__version__ = "1.5"
__updated__ = "2020-03-26"
__version__ = "1.6"
__updated__ = "2020-04-03"

import machine
from sys import platform
Expand All @@ -31,11 +31,11 @@ class pyADC:
Just a base class to identify all instances of an ADC object sharing the same API
"""

def __init__(self, *args, calibration_v_max=3.3, calibration_offset=0, max_voltage=3.3,
def __init__(self, *args, calibration_v_max=3.3, calibration_offset=0, max_voltage=None,
**kwargs):
self._cvm = calibration_v_max
self._co = calibration_offset
self._mv = max_voltage
self._mv = max_voltage or calibration_v_max + calibration_offset

def readRaw(self) -> int:
# just loboris fork compatibility although support officialy dropped.
Expand Down Expand Up @@ -80,12 +80,12 @@ def __str__(self):

__repr__ = __str__

@staticmethod
def maxVoltage() -> float:
return 3.3 # esp standard voltage
def maxVoltage(self) -> float:
return self._mv

# The following methods are overwritten by machineADC, the machine.ADC class, by the proper hardware methods
# In other subclasses they have to be implemented
# When using the machineADC class, the following methods are overwritten by machine.ADC,
# the machine methods of the hardware ADC.
# In other subclasses they have to be implemented.

def read(self) -> int:
raise NotImplementedError("Implement your subclass correctly!")
Expand Down

0 comments on commit b904f3f

Please sign in to comment.