44
55__version__ = '0.0.1'
66
7+ MICS6814_I2C_ADDR = 0x19
8+
9+ MICS6814_LED_R = 3 # P1.2
10+ MICS6814_LED_G = 7 # P1.1
11+ MICS6814_LED_B = 2 # P1.0
12+
13+ MICS6814_VREF = 14 # P1.4 AIN0 - 3v3
14+ MICS6814_RED = 12 # P0.5 AIN4 - Reducing
15+ MICS6814_NH3 = 11 # P0.6 AIN3 - NH3
16+ MICS6814_OX = 13 # P0.7 AIN2 - Oxidizing
17+
18+ MICS6814_HEATER_EN = 1 # P1.5 Heater Enable
19+
720
821class Mics6814Reading (object ):
922 __slots__ = 'oxidising' , 'reducing' , 'nh3' , 'adc'
@@ -32,7 +45,7 @@ def __repr__(self):
3245
3346
3447class MICS6814 ():
35- def __init__ (self , i2c_addr = io . I2C_ADDR , interrupt_timeout = 1.0 , interrupt_pin = None , gpio = None ):
48+ def __init__ (self , i2c_addr = MICS6814_I2C_ADDR , interrupt_timeout = 1.0 , interrupt_pin = None , gpio = None ):
3649 self ._ioe = io .IOE (i2c_addr , interrupt_timeout , interrupt_pin , gpio )
3750
3851 self ._chip_id = self ._ioe .get_chip_id ()
@@ -43,17 +56,17 @@ def __init__(self, i2c_addr=io.I2C_ADDR, interrupt_timeout=1.0, interrupt_pin=No
4356 self ._ioe .set_pwm_control (divider = 1 )
4457
4558 self .set_brightness (1.0 )
46- self ._ioe .set_mode (3 , io .PWM ) # P1.2 LED Red
47- self ._ioe .set_mode (7 , io .PWM ) # P1.1 LED Green
48- self ._ioe .set_mode (2 , io .PWM ) # P1.0 LED Blue
59+ self ._ioe .set_mode (MICS6814_LED_R , io .PWM ) # P1.2 LED Red
60+ self ._ioe .set_mode (MICS6814_LED_G , io .PWM ) # P1.1 LED Green
61+ self ._ioe .set_mode (MICS6814_LED_B , io .PWM ) # P1.0 LED Blue
4962
50- self ._ioe .set_mode (9 , io .ADC ) # P0 .4 AIN5 - 2v8
51- self ._ioe .set_mode (12 , io .ADC ) # P0.5 AIN4 - Red
52- self ._ioe .set_mode (11 , io .ADC ) # P0.6 AIN3 - NH3
53- self ._ioe .set_mode (13 , io .ADC ) # P0.7 AIN2 - OX
63+ self ._ioe .set_mode (MICS6814_VREF , io .ADC ) # P1 .4 AIN5 - 2v8
64+ self ._ioe .set_mode (MICS6814_RED , io .ADC ) # P0.5 AIN4 - Red
65+ self ._ioe .set_mode (MICS6814_NH3 , io .ADC ) # P0.6 AIN3 - NH3
66+ self ._ioe .set_mode (MICS6814_OX , io .ADC ) # P0.7 AIN2 - OX
5467
55- self ._ioe .set_mode (1 , io .OUT ) # P1.5 Heater Enable
56- self ._ioe .output (1 , io .LOW )
68+ self ._ioe .set_mode (MICS6814_HEATER_EN , io .OUT ) # P1.5 Heater Enable
69+ self ._ioe .output (MICS6814_HEATER_EN , io .LOW )
5770
5871 def set_brightness (self , brightness ):
5972 """Set the LED brightness.
@@ -82,24 +95,24 @@ def set_heater(self, value):
8295
8396 def disable_heater (self ):
8497 """Disable the gas heater."""
85- self ._ioe .output (1 , io .HIGH )
86- self ._ioe .set_mode (1 , io .IN )
98+ self ._ioe .output (MICS6814_HEATER_EN , io .HIGH )
99+ self ._ioe .set_mode (MICS6814_HEATER_EN , io .IN )
87100
88101 def get_raw_ref (self ):
89102 """Return raw reference ADC reading."""
90- return self ._ioe .input (9 )
103+ return self ._ioe .input (MICS6814_VREF )
91104
92105 def get_raw_red (self ):
93106 """Return raw Reducing Gasses reading."""
94- return self ._ioe .input (12 )
107+ return self ._ioe .input (MICS6814_RED )
95108
96109 def get_raw_nh3 (self ):
97110 """Return raw NH3 ADC reading."""
98- return self ._ioe .input (11 )
111+ return self ._ioe .input (MICS6814_NH3 )
99112
100113 def get_raw_oxd (self ):
101114 """Return raw Oxidizing Gasses ADC reading."""
102- return self ._ioe .input (13 )
115+ return self ._ioe .input (MICS6814_OX )
103116
104117 def set_led (self , r , g , b ):
105118 """Set onboard LED to RGB value.
@@ -112,9 +125,9 @@ def set_led(self, r, g, b):
112125 r = self .pwm_period - (r * self .pwm_period / 255.0 * self .brightness )
113126 g = self .pwm_period - (g * self .pwm_period / 255.0 * self .brightness )
114127 b = self .pwm_period - (b * self .pwm_period / 255.0 * self .brightness )
115- self ._ioe .output (3 , int (r ))
116- self ._ioe .output (7 , int (g ))
117- self ._ioe .output (2 , int (b ))
128+ self ._ioe .output (MICS6814_LED_R , int (r ))
129+ self ._ioe .output (MICS6814_LED_G , int (g ))
130+ self ._ioe .output (MICS6814_LED_B , int (b ))
118131
119132 def read_all (self ):
120133 """Return gas resistance for oxidising, reducing and NH3"""
0 commit comments