kopia lustrzana https://github.com/micropython/micropython-lib
micropython: Adding pre-coomit config file.
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>pull/644/head
rodzic
af939e65fa
commit
a71c421943
|
@ -18,14 +18,16 @@ _PASCO2_ERROR = -1
|
|||
addr = 0
|
||||
mask = 1
|
||||
|
||||
|
||||
class PASCO2:
|
||||
"""IFX - XENSIV PAS CO2 sensor driver"""
|
||||
|
||||
# RegAddr, Mask, <Later extend with register access type, bit position etc.>
|
||||
regMap = {
|
||||
'REG_SENS_STS_BITF_SENS_RDY' : [_PASCO2_REG_SENS_STS, 0x80], # Sensor status bit
|
||||
'REG_MEAS_CFG_BITF_OP_MODE' : [_PASCO2_REG_MEAS_CFG, 0x03], # Operation Mode type bit
|
||||
'REG_MEAS_STS_BITF_DATA_RDY' : [_PASCO2_REG_MEAS_STS, 0x10], # Data ready status bit
|
||||
'REG_CO2PPM_H_BITF_CO2_PPM_H': [_PASCO2_REG_CO2PPM_H, 0xFF], # Stored CO2 value bit
|
||||
"REG_SENS_STS_BITF_SENS_RDY": [_PASCO2_REG_SENS_STS, 0x80], # Sensor status bit
|
||||
"REG_MEAS_CFG_BITF_OP_MODE": [_PASCO2_REG_MEAS_CFG, 0x03], # Operation Mode type bit
|
||||
"REG_MEAS_STS_BITF_DATA_RDY": [_PASCO2_REG_MEAS_STS, 0x10], # Data ready status bit
|
||||
"REG_CO2PPM_H_BITF_CO2_PPM_H": [_PASCO2_REG_CO2PPM_H, 0xFF], # Stored CO2 value bit
|
||||
}
|
||||
|
||||
def __init__(self, bus, measInterval=10, sensorAddr=0x28):
|
||||
|
@ -46,8 +48,8 @@ class PASCO2:
|
|||
|
||||
def _is_sensor_ready(self):
|
||||
"""Helper function to check the sensor status"""
|
||||
reg = self.regMap['REG_SENS_STS_BITF_SENS_RDY']
|
||||
return (self._read_reg(reg[addr])[0] & reg[mask])
|
||||
reg = self.regMap["REG_SENS_STS_BITF_SENS_RDY"]
|
||||
return self._read_reg(reg[addr])[0] & reg[mask]
|
||||
|
||||
def _soft_reset(self):
|
||||
"""Helper function to perform soft reset of the sensor"""
|
||||
|
@ -58,10 +60,12 @@ class PASCO2:
|
|||
1. Idle
|
||||
2. Continuous
|
||||
"""
|
||||
if mode == 'idle': modeVal = 0x00
|
||||
if mode == 'continuous': modeVal = 0x02
|
||||
if mode == "idle":
|
||||
modeVal = 0x00
|
||||
if mode == "continuous":
|
||||
modeVal = 0x02
|
||||
|
||||
reg = self.regMap['REG_MEAS_CFG_BITF_OP_MODE']
|
||||
reg = self.regMap["REG_MEAS_CFG_BITF_OP_MODE"]
|
||||
readData = self._read_reg(reg[addr])[0]
|
||||
writeData = bytes([(readData & ~(reg[mask])) | modeVal])
|
||||
self._write_reg(_PASCO2_REG_MEAS_CFG, writeData)
|
||||
|
@ -84,10 +88,10 @@ class PASCO2:
|
|||
self._write_reg(_PASCO2_REG_MEAS_RATE_H, buf)
|
||||
|
||||
# reset operation mode to idle mode
|
||||
self._set_mode('idle')
|
||||
self._set_mode("idle")
|
||||
|
||||
# start continuous mode
|
||||
self._set_mode('continuous')
|
||||
self._set_mode("continuous")
|
||||
|
||||
return _PASCO2_SUCCESS
|
||||
|
||||
|
@ -99,13 +103,13 @@ class PASCO2:
|
|||
while True:
|
||||
try:
|
||||
# get meas status
|
||||
reg = self.regMap['REG_MEAS_STS_BITF_DATA_RDY']
|
||||
reg = self.regMap["REG_MEAS_STS_BITF_DATA_RDY"]
|
||||
readStatus = self._read_reg(reg[addr])
|
||||
data_ready = readStatus[0] & reg[mask]
|
||||
|
||||
if data_ready:
|
||||
# get CO2 value
|
||||
reg = self.regMap['REG_CO2PPM_H_BITF_CO2_PPM_H']
|
||||
reg = self.regMap["REG_CO2PPM_H_BITF_CO2_PPM_H"]
|
||||
readVal = self._read_reg(reg[addr], 2)
|
||||
co2_value = (readVal[0] << 8) | readVal[1]
|
||||
return co2_value
|
||||
|
|
Ładowanie…
Reference in New Issue