1111 SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313 @section HISTORY
14+ v34 - Added Generic Analog Sensor Support
1415 v33 - Changes for Digital Sensor Switch Support
1516 v32 - Added MQTT Support!
1617 v29 - First Public Release
@@ -41,8 +42,13 @@ Ads1x15::Ads1x15 (long id, String category, String shortName, String name, Strin
4142 if (!init48)
4243 {
4344 init48 = true ;
44- ads1x15_48 = new Adafruit_ADS1015 (0x48 );
45- ads1x15_48->setGain (GAIN_ONE);
45+
46+ if (type == " ADS1115" )
47+ ads1x15_48 = new Adafruit_ADS1115 (0x48 );
48+ else
49+ ads1x15_48 = new Adafruit_ADS1015 (0x48 );
50+
51+ ads1x15_48->setGain (GAIN_TWOTHIRDS);
4652 ads1x15_48->begin ();
4753 }
4854 ads1x15 = ads1x15_48;
@@ -51,8 +57,13 @@ Ads1x15::Ads1x15 (long id, String category, String shortName, String name, Strin
5157 if (!init49)
5258 {
5359 init49 = true ;
54- ads1x15_49 = new Adafruit_ADS1015 (0x49 );
55- ads1x15_49->setGain (GAIN_ONE);
60+
61+ if (type == " ADS1115" )
62+ ads1x15_48 = new Adafruit_ADS1115 (0x49 );
63+ else
64+ ads1x15_49 = new Adafruit_ADS1015 (0x49 );
65+
66+ ads1x15_49->setGain (GAIN_TWOTHIRDS);
5667 ads1x15_49->begin ();
5768 }
5869 ads1x15 = ads1x15_49;
@@ -62,8 +73,13 @@ Ads1x15::Ads1x15 (long id, String category, String shortName, String name, Strin
6273 if (!init4A)
6374 {
6475 init4A = true ;
65- ads1x15_4A = new Adafruit_ADS1015 (0x4A );
66- ads1x15_4A->setGain (GAIN_ONE);
76+
77+ if (type == " ADS1115" )
78+ ads1x15_48 = new Adafruit_ADS1115 (0x4A );
79+ else
80+ ads1x15_4A = new Adafruit_ADS1015 (0x4A );
81+
82+ ads1x15_4A->setGain (GAIN_TWOTHIRDS);
6783 ads1x15_4A->begin ();
6884 }
6985 ads1x15 = ads1x15_4A;
@@ -72,8 +88,13 @@ Ads1x15::Ads1x15 (long id, String category, String shortName, String name, Strin
7288 if (!init4B)
7389 {
7490 init4B = true ;
75- ads1x15_4B = new Adafruit_ADS1015 (0x4B );
76- ads1x15_4B->setGain (GAIN_ONE);
91+
92+ if (type == " ADS1115" )
93+ ads1x15_48 = new Adafruit_ADS1115 (0x4B );
94+ else
95+ ads1x15_4B = new Adafruit_ADS1015 (0x4B );
96+
97+ ads1x15_4B->setGain (GAIN_TWOTHIRDS);
7798 ads1x15_4B->begin ();
7899 }
79100 ads1x15 = ads1x15_4B;
@@ -93,7 +114,7 @@ Data* Ads1x15::read(bool shouldPostData)
93114 for (int i = 0 ; i < numberOfSamples; i++)
94115 {
95116 adcMax = adcMax + (float ) ads1x15->readADC_SingleEnded (0 );
96-
117+
97118 if (_channel == 1 )
98119 adc = adc + (float ) ads1x15->readADC_SingleEnded (1 );
99120 if (_channel == 2 )
@@ -108,9 +129,8 @@ Data* Ads1x15::read(bool shouldPostData)
108129 if (adc >= adcMax-20 )
109130 adc = adcMax;
110131
111- if (_preResistor!=0 && _postResistor!=0 )
132+ if (( _preResistor!=0 && _postResistor!=0 ) || (_preResistor== 0 && _postResistor== 0 ) )
112133 {
113- adc = adc/adcMax*1024 ;
114134 shouldPostData = smartSensorCheck (adc, _smartValueThreshold, shouldPostData);
115135 return _calculation->calculate (this , adc, shouldPostData);
116136 }
0 commit comments