求助:ESP8266 ESPEasy MQ-135插件
我在github上下载了一个mq135的code,准备刷入8266,但是在编译验证时提示错误,哪位大神能给我看看这个有哪里不对啊,多谢
代码如下:
//#######################################################################################################
//#################################### Plugin 026: ADS1115 MQ135 airquality I2C 0x48)###############################################
//#######################################################################################################
MyMessage *msgAir026;
#define PLUGIN_026
#define PLUGIN_ID_026 26
#define PLUGIN_NAME_026 "Analog input - ADS1115 Air"
#define PLUGIN_VALUENAME1_026 "Analog"
boolean Plugin_026_init = false;
static uint16_t readRegister026(uint8_t i2cAddress, uint8_t reg) {
Wire.beginTransmission(i2cAddress);
Wire.write((0x00));
Wire.endTransmission();
Wire.requestFrom(i2cAddress, (uint8_t)2);
return ((Wire.read() << 8) | Wire.read());
}
boolean Plugin_026(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte portValue = 0;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_026;
Device.Type = DEVICE_TYPE_I2C;
Device.VType = SENSOR_TYPE_SINGLE;
Device.Ports = 4;
Device.PullUpOption = false;
Device.InverseLogicOption = false;
Device.FormulaOption = true;
Device.ValueCount = 1;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_026);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames, PSTR(PLUGIN_VALUENAME1_026));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
#define ADS1115_GAIN_OPTION 6
byte choice = Settings.TaskDevicePluginConfig;
String options;
uint optionValues;
optionValues = (0x00);
options = F("2/3x gain 6.144V 0.1875mV");
optionValues = (0x02);
options = F("1x gain 4.096V 0.125mV");
optionValues = (0x04);
options = F("2x gain 2.048V 0.0625mV");
optionValues = (0x06);
options = F("4x gain 1.024V 0.03125mV");
optionValues = (0x08);
options = F("8x gain 0.512V 0.015625mV");
optionValues = (0x0A);
options = F("16x gain 0.256V 0.0078125V");
string += F("<TR><TD>Gain:<TD><select name='plugin_026_gain'>");
for (byte x = 0; x < ADS1115_GAIN_OPTION; x++)
{
string += F("<option value='");
string += optionValues;
string += "'";
if (choice == optionValues)
string += F(" selected");
string += ">";
string += options;
string += F("</option>");
}
string += F("</select>");
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
String plugin1 = WebServer.arg("plugin_026_gain");
Settings.TaskDevicePluginConfig = plugin1.toInt();
Plugin_026_init = false; // Force device setup next time
success = true;
break;
}
case PLUGIN_INIT:
{
present(event->BaseVarIndex, S_AIR_QUALITY);
Serial.print("Present ADS1115 MQ135: ");
Serial.println(event->BaseVarIndex);
msgAir026 = new MyMessage(event->BaseVarIndex, V_LEVEL);
success = true;
break;
}
case PLUGIN_READ:
{
if (!Plugin_026_init)
{
Plugin_026_init = true;
}
uint8_t m_gain = Settings.TaskDevicePluginConfig;
noInterrupts();
int value;
value = 0;
byte unit = (Settings.TaskDevicePort - 1) / 4;
byte port = Settings.TaskDevicePort - (unit * 4);
uint8_t address = 0x48 + unit;
// get the current pin value
uint16_t config = (0x0003) |// Disable the comparator (default val)
(0x0000) |// Non-latching (default val)
(0x0000) |// Alert/Rdy active low (default val)
(0x0000) |// Traditional comparator (default val)
(0x0080) |// 1600 samples per second (default)
(0x0100) ; // Single-shot mode (default)
// m_Gain = (0x0000);// 2/3x gain +/- 6.144V1 bit = 3mV 0.1875mV (default)
// m_Gain = (0x0200); // 1x gain +/- 4.096V1 bit = 2mV 0.125mV
// m_Gain = (0x0400); // 2x gain +/- 2.048V1 bit = 1mV 0.0625mV
// m_Gain = (0x0600); // 4x gain +/- 1.024V1 bit = 0.5mV 0.03125mV
// m_Gain = (0x0800); // 8x gain +/- 0.512V1 bit = 0.25mV 0.015625mV
// m_Gain = (0x0A00); // 16x gain+/- 0.256V1 bit = 0.125mV0.0078125mV
// config |= m_gain;
// config |= (0x0000);
switch (m_gain)
{
case (0x00):
config |= (0x0000);
break;
case (0x02):
config |= (0x0200);
break;
case (0x04):
config |= (0x0400);
break;
case (0x06):
config |= (0x0600);
break;
case (0x08):
config |= (0x0800);
break;
case (0x0A):
config |= (0x0A00);
break;
}
switch (port)
{
case (0):
config |= (0x4000);
break;
case (1):
config |= (0x5000);
break;
case (2):
config |= (0x6000);
break;
case (3):
config |= (0x7000);
break;
}
config |= (0x8000);
Wire.beginTransmission(address);
Wire.write((uint8_t)(0x01));
Wire.write((uint8_t)(config>>8));
Wire.write((uint8_t)(config & 0xFF));
Wire.endTransmission();
delay(8);
UserVar = (float) readRegister026((address), (0x00)) ;
String log = F("ADS1115: Analog value: ");
log += UserVar;
send(msgAir026->set(UserVar, 1));
addLog(LOG_LEVEL_INFO,log);
success = true;
interrupts();
break;
}
}
return success;
}
页:
[1]