Revert "Add user configuration of MCP39F501"

This reverts commit c340e2b8bd3f6189b7ec0b5c5038effc15a7dcd5.
This commit is contained in:
Theo Arends 2019-02-04 18:17:50 +01:00
parent c340e2b8bd
commit 48faabc1cf
5 changed files with 113 additions and 142 deletions

View File

@ -2,8 +2,7 @@
* Add SetOption32 until SetOption49 diagnostic information to Status 3 report as replacement for second property value in SetOption property name * Add SetOption32 until SetOption49 diagnostic information to Status 3 report as replacement for second property value in SetOption property name
* Add Resolution property to Status 3 report providing previous SetOption second value property * Add Resolution property to Status 3 report providing previous SetOption second value property
* Fix IR local echo * Fix IR local echo
* Add user configuration of HLW8012 and HJL-01/BL0937 Energy Monitoring as used in Sonoff S31, Pow Ra and many Tuya based devices * Add user configuration of HLW8012 and HJL-01/BL0937 Energy Monitoring
* Add user configuration of MCP39F501 Energy Monitoring as used in Shelly2
* *
* 6.4.1.13 20190130 * 6.4.1.13 20190130
* Add command SetOption36 to control boot loop default restoration (#4645, #5063) * Add command SetOption36 to control boot loop default restoration (#4645, #5063)

View File

@ -159,9 +159,6 @@ enum UserSelectablePins {
GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current
GPIO_HLW_CF, // HLW8012 CF power GPIO_HLW_CF, // HLW8012 CF power
GPIO_HJL_CF, // HJL-01/BL0937 CF power GPIO_HJL_CF, // HJL-01/BL0937 CF power
GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2)
GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2)
GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2)
GPIO_SENSOR_END }; GPIO_SENSOR_END };
// Programmer selectable GPIO functionality offset by user selectable GPIOs // Programmer selectable GPIO functionality offset by user selectable GPIOs
@ -178,6 +175,9 @@ enum ProgramSelectablePins {
GPIO_ROT_B, // Rotary switch B Pin GPIO_ROT_B, // Rotary switch B Pin
GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2)
GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2)
GPIO_MCP39_TX, // MCP39F501 Serial interface (Shelly2)
GPIO_MCP39_RX, // MCP39F501 Serial interface (Shelly2)
GPIO_MCP39_RST, // MCP39F501 Reset (Shelly2)
GPIO_USER, // User configurable GPIO_USER, // User configurable
GPIO_MAX }; GPIO_MAX };
@ -225,8 +225,7 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|" D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|"
D_SENSOR_BUTTON "1i|" D_SENSOR_BUTTON "2i|" D_SENSOR_BUTTON "3i|" D_SENSOR_BUTTON "4i|" D_SENSOR_BUTTON "1i|" D_SENSOR_BUTTON "2i|" D_SENSOR_BUTTON "3i|" D_SENSOR_BUTTON "4i|"
D_SENSOR_BUTTON "1in|" D_SENSOR_BUTTON "2in|" D_SENSOR_BUTTON "3in|" D_SENSOR_BUTTON "4in|" D_SENSOR_BUTTON "1in|" D_SENSOR_BUTTON "2in|" D_SENSOR_BUTTON "3in|" D_SENSOR_BUTTON "4in|"
D_SENSOR_NRG_SEL "|" D_SENSOR_NRG_SEL "i|" D_SENSOR_NRG_CF1 "|" D_SENSOR_HLW_CF "|" D_SENSOR_HJL_CF "|" D_SENSOR_NRG_SEL "|" D_SENSOR_NRG_SEL "i|" D_SENSOR_NRG_CF1 "|" D_SENSOR_HLW_CF "|" D_SENSOR_HJL_CF
D_SENSOR_MCP39F5_TX "|" D_SENSOR_MCP39F5_RX "|" D_SENSOR_MCP39F5_RST
; ;
/********************************************************************************************/ /********************************************************************************************/
@ -472,17 +471,21 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_HX711_SCK, // HX711 Load Cell clock GPIO_HX711_SCK, // HX711 Load Cell clock
GPIO_HX711_DAT, // HX711 Load Cell data GPIO_HX711_DAT, // HX711 Load Cell data
#endif #endif
#if defined(USE_ENERGY_SENSOR) && defined(USE_HLW8012) #ifdef USE_SERIAL_BRIDGE
GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) GPIO_SBR_TX, // Serial Bridge Serial interface
GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) GPIO_SBR_RX, // Serial Bridge Serial interface
GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current
GPIO_HLW_CF, // HLW8012 CF power
GPIO_HJL_CF, // HJL-01/BL0937 CF power
#endif #endif
#if defined(USE_ENERGY_SENSOR) && defined(USE_MCP39F501) #ifdef USE_MHZ19
GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) GPIO_MHZ_TXD, // MH-Z19 Serial interface
GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) GPIO_MHZ_RXD, // MH-Z19 Serial interface
GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) #endif
#ifdef USE_SENSEAIR
GPIO_SAIR_TX, // SenseAir Serial interface
GPIO_SAIR_RX, // SenseAir Serial interface
#endif
#ifdef USE_NOVA_SDS
GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface
GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface
#endif #endif
#if defined(USE_PZEM004T) || defined(USE_PZEM_AC) || defined(USE_PZEM_DC) #if defined(USE_PZEM004T) || defined(USE_PZEM_AC) || defined(USE_PZEM_DC)
GPIO_PZEM0XX_TX, // PZEM0XX Serial interface GPIO_PZEM0XX_TX, // PZEM0XX Serial interface
@ -504,22 +507,6 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_SDM630_TX, // SDM630 Serial interface GPIO_SDM630_TX, // SDM630 Serial interface
GPIO_SDM630_RX, // SDM630 Serial interface GPIO_SDM630_RX, // SDM630 Serial interface
#endif #endif
#ifdef USE_SERIAL_BRIDGE
GPIO_SBR_TX, // Serial Bridge Serial interface
GPIO_SBR_RX, // Serial Bridge Serial interface
#endif
#ifdef USE_MHZ19
GPIO_MHZ_TXD, // MH-Z19 Serial interface
GPIO_MHZ_RXD, // MH-Z19 Serial interface
#endif
#ifdef USE_SENSEAIR
GPIO_SAIR_TX, // SenseAir Serial interface
GPIO_SAIR_RX, // SenseAir Serial interface
#endif
#ifdef USE_NOVA_SDS
GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface
GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface
#endif
#ifdef USE_PMS5003 #ifdef USE_PMS5003
GPIO_PMS5003, // Plantower PMS5003 Serial interface GPIO_PMS5003, // Plantower PMS5003 Serial interface
#endif #endif
@ -546,6 +533,13 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_MAX31855CLK, // MAX31855 Serial interface GPIO_MAX31855CLK, // MAX31855 Serial interface
GPIO_MAX31855DO, // MAX31855 Serial interface GPIO_MAX31855DO, // MAX31855 Serial interface
#endif #endif
#if defined(USE_ENERGY_SENSOR) && defined(USE_HLW8012)
GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage)
GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage)
GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current
GPIO_HLW_CF, // HLW8012 CF power
GPIO_HJL_CF, // HJL-01/BL0937 CF power
#endif
}; };
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = {
@ -1448,9 +1442,9 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
}, },
{ "Shelly 2", // Shelly2 (ESP8266 - 2MB) - https://shelly.cloud/shelly2/ { "Shelly 2", // Shelly2 (ESP8266 - 2MB) - https://shelly.cloud/shelly2/
0, 0,
GPIO_MCP39F5_TX, // GPIO01 MCP39F501 Serial input GPIO_MCP39_TX, // GPIO01 MCP39F501 Serial input
0, 0,
GPIO_MCP39F5_RX, // GPIO03 MCP39F501 Serial output GPIO_MCP39_RX, // GPIO03 MCP39F501 Serial output
GPIO_REL1, // GPIO04 GPIO_REL1, // GPIO04
GPIO_REL2, // GPIO05 GPIO_REL2, // GPIO05
// GPIO06 (SD_CLK Flash) // GPIO06 (SD_CLK Flash)
@ -1462,7 +1456,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
GPIO_SWT1, // GPIO12 GPIO_SWT1, // GPIO12
0, 0,
GPIO_SWT2, // GPIO14 GPIO_SWT2, // GPIO14
GPIO_MCP39F5_RST, // GPIO15 MCP39F501 Reset GPIO_MCP39_RST, // GPIO15 MCP39F501 Reset
0, 0,
GPIO_FLAG_PULLUP // Allow input pull-up control GPIO_FLAG_PULLUP // Allow input pull-up control
}, },

View File

@ -864,7 +864,7 @@ void HandleModuleConfiguration(void)
for (uint8_t i = 0; i < sizeof(cmodule); i++) { for (uint8_t i = 0; i < sizeof(cmodule); i++) {
if (GPIO_USER == ValidGPIO(i, cmodule.io[i])) { if (GPIO_USER == ValidGPIO(i, cmodule.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(stemp, 3, PINS_WEMOS +i*2);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("<tr><td style='width:190px'>%s <b>" D_GPIO "%d</b> %s</td><td style='width:176px'><select id='g%d' name='g%d'></select></td></tr>"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("<tr><td style='width:190px'>%s <b>" D_GPIO "%d</b> %s</td><td style='width:160px'><select id='g%d' name='g%d'></select></td></tr>"),
(WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "<font color='red'>ESP8285</font>" :(10==i)? "<font color='red'>ESP8285</font>" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "<font color='red'>ESP8285</font>" :(10==i)? "<font color='red'>ESP8285</font>" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i);
page += mqtt_data; page += mqtt_data;
} }

View File

@ -695,9 +695,6 @@ bool Xdrv03(uint8_t function)
case FUNC_SET_POWER: case FUNC_SET_POWER:
EnergySetPowerSteadyCounter(); EnergySetPowerSteadyCounter();
break; break;
case FUNC_LOOP:
XnrgCall(FUNC_LOOP);
break;
case FUNC_SERIAL: case FUNC_SERIAL:
result = XnrgCall(FUNC_SERIAL); result = XnrgCall(FUNC_SERIAL);
break; break;

View File

@ -63,11 +63,6 @@
#define MCP_FREQUENCY_GAIN_BASE 0x00AE #define MCP_FREQUENCY_GAIN_BASE 0x00AE
#define MCP_FREQUENCY_LEN 4 #define MCP_FREQUENCY_LEN 4
#define MCP_BUFFER_SIZE 60
#include <TasmotaSerial.h>
TasmotaSerial *McpSerial;
typedef struct mcp_cal_registers_type { typedef struct mcp_cal_registers_type {
uint16_t gain_current_rms; uint16_t gain_current_rms;
uint16_t gain_voltage_rms; uint16_t gain_voltage_rms;
@ -91,9 +86,6 @@ typedef struct mcp_cal_registers_type {
uint16_t accumulation_interval; uint16_t accumulation_interval;
} mcp_cal_registers_type; } mcp_cal_registers_type;
char *mcp_buffer = NULL; // Serial receive buffer
int mcp_byte_counter = 0; // Index in serial receive buffer
unsigned long mcp_kWhcounter = 0; unsigned long mcp_kWhcounter = 0;
uint32_t mcp_system_configuration = 0x03000000; uint32_t mcp_system_configuration = 0x03000000;
uint32_t mcp_active_power; uint32_t mcp_active_power;
@ -154,7 +146,7 @@ void McpSend(uint8_t *data)
// AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]); // AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]);
for (uint8_t i = 0; i < data[1]; i++) { for (uint8_t i = 0; i < data[1]; i++) {
McpSerial->write(data[i]); Serial.write(data[i]);
} }
} }
@ -170,7 +162,7 @@ void McpGetAddress(void)
void McpAddressReceive(void) void McpAddressReceive(void)
{ {
// 06 05 004D 58 // 06 05 004D 58
mcp_address = mcp_buffer[3]; mcp_address = serial_in_buffer[3];
} }
/********************************************************************************************/ /********************************************************************************************/
@ -191,26 +183,26 @@ void McpParseCalibration(void)
mcp_cal_registers_type cal_registers; mcp_cal_registers_type cal_registers;
// 06 37 C882 B6AD 0781 9273 06000000 00000000 00000000 0000 D3FF 0300 00000003 9204 120C1300 204E0000 9808 E0AB0000 D9940000 0200 24 // 06 37 C882 B6AD 0781 9273 06000000 00000000 00000000 0000 D3FF 0300 00000003 9204 120C1300 204E0000 9808 E0AB0000 D9940000 0200 24
cal_registers.gain_current_rms = McpExtractInt(mcp_buffer, 2, 2); cal_registers.gain_current_rms = McpExtractInt(serial_in_buffer, 2, 2);
cal_registers.gain_voltage_rms = McpExtractInt(mcp_buffer, 4, 2); cal_registers.gain_voltage_rms = McpExtractInt(serial_in_buffer, 4, 2);
cal_registers.gain_active_power = McpExtractInt(mcp_buffer, 6, 2); cal_registers.gain_active_power = McpExtractInt(serial_in_buffer, 6, 2);
cal_registers.gain_reactive_power = McpExtractInt(mcp_buffer, 8, 2); cal_registers.gain_reactive_power = McpExtractInt(serial_in_buffer, 8, 2);
cal_registers.offset_current_rms = McpExtractInt(mcp_buffer, 10, 4); cal_registers.offset_current_rms = McpExtractInt(serial_in_buffer, 10, 4);
cal_registers.offset_active_power = McpExtractInt(mcp_buffer, 14, 4); cal_registers.offset_active_power = McpExtractInt(serial_in_buffer, 14, 4);
cal_registers.offset_reactive_power = McpExtractInt(mcp_buffer, 18, 4); cal_registers.offset_reactive_power = McpExtractInt(serial_in_buffer, 18, 4);
cal_registers.dc_offset_current = McpExtractInt(mcp_buffer, 22, 2); cal_registers.dc_offset_current = McpExtractInt(serial_in_buffer, 22, 2);
cal_registers.phase_compensation = McpExtractInt(mcp_buffer, 24, 2); cal_registers.phase_compensation = McpExtractInt(serial_in_buffer, 24, 2);
cal_registers.apparent_power_divisor = McpExtractInt(mcp_buffer, 26, 2); cal_registers.apparent_power_divisor = McpExtractInt(serial_in_buffer, 26, 2);
cal_registers.system_configuration = McpExtractInt(mcp_buffer, 28, 4); cal_registers.system_configuration = McpExtractInt(serial_in_buffer, 28, 4);
cal_registers.dio_configuration = McpExtractInt(mcp_buffer, 32, 2); cal_registers.dio_configuration = McpExtractInt(serial_in_buffer, 32, 2);
cal_registers.range = McpExtractInt(mcp_buffer, 34, 4); cal_registers.range = McpExtractInt(serial_in_buffer, 34, 4);
cal_registers.calibration_current = McpExtractInt(mcp_buffer, 38, 4); cal_registers.calibration_current = McpExtractInt(serial_in_buffer, 38, 4);
cal_registers.calibration_voltage = McpExtractInt(mcp_buffer, 42, 2); cal_registers.calibration_voltage = McpExtractInt(serial_in_buffer, 42, 2);
cal_registers.calibration_active_power = McpExtractInt(mcp_buffer, 44, 4); cal_registers.calibration_active_power = McpExtractInt(serial_in_buffer, 44, 4);
cal_registers.calibration_reactive_power = McpExtractInt(mcp_buffer, 48, 4); cal_registers.calibration_reactive_power = McpExtractInt(serial_in_buffer, 48, 4);
cal_registers.accumulation_interval = McpExtractInt(mcp_buffer, 52, 2); cal_registers.accumulation_interval = McpExtractInt(serial_in_buffer, 52, 2);
if (mcp_calibrate & MCP_CALIBRATE_POWER) { if (mcp_calibrate & MCP_CALIBRATE_POWER) {
cal_registers.calibration_active_power = Settings.energy_power_calibration; cal_registers.calibration_active_power = Settings.energy_power_calibration;
@ -381,8 +373,8 @@ void McpGetFrequency(void)
void McpParseFrequency(void) void McpParseFrequency(void)
{ {
// 06 07 C350 8000 A0 // 06 07 C350 8000 A0
uint16_t line_frequency_ref = mcp_buffer[2] * 256 + mcp_buffer[3]; uint16_t line_frequency_ref = serial_in_buffer[2] * 256 + serial_in_buffer[3];
uint16_t gain_line_frequency = mcp_buffer[4] * 256 + mcp_buffer[5]; uint16_t gain_line_frequency = serial_in_buffer[4] * 256 + serial_in_buffer[5];
if (mcp_calibrate & MCP_CALIBRATE_FREQUENCY) { if (mcp_calibrate & MCP_CALIBRATE_FREQUENCY) {
line_frequency_ref = Settings.energy_frequency_calibration; line_frequency_ref = Settings.energy_frequency_calibration;
@ -446,12 +438,12 @@ void McpParseData(void)
// 06 19 CE 18 00 00 F2 08 3A 38 00 00 66 00 00 00 93 38 00 00 36 7F 9A C6 B7 // 06 19 CE 18 00 00 F2 08 3A 38 00 00 66 00 00 00 93 38 00 00 36 7F 9A C6 B7
// Ak Ln Current---- Volt- ActivePower ReActivePow ApparentPow Factr Frequ Ck // Ak Ln Current---- Volt- ActivePower ReActivePow ApparentPow Factr Frequ Ck
mcp_current_rms = McpExtractInt(mcp_buffer, 2, 4); mcp_current_rms = McpExtractInt(serial_in_buffer, 2, 4);
mcp_voltage_rms = McpExtractInt(mcp_buffer, 6, 2); mcp_voltage_rms = McpExtractInt(serial_in_buffer, 6, 2);
mcp_active_power = McpExtractInt(mcp_buffer, 8, 4); mcp_active_power = McpExtractInt(serial_in_buffer, 8, 4);
// mcp_reactive_power = McpExtractInt(mcp_buffer, 12, 4); // mcp_reactive_power = McpExtractInt(serial_in_buffer, 12, 4);
// mcp_power_factor = McpExtractInt(mcp_buffer, 20, 2); // mcp_power_factor = McpExtractInt(serial_in_buffer, 20, 2);
mcp_line_frequency = McpExtractInt(mcp_buffer, 22, 2); mcp_line_frequency = McpExtractInt(serial_in_buffer, 22, 2);
if (energy_power_on) { // Powered on if (energy_power_on) { // Powered on
energy_frequency = (float)mcp_line_frequency / 1000; energy_frequency = (float)mcp_line_frequency / 1000;
@ -472,52 +464,49 @@ void McpParseData(void)
/********************************************************************************************/ /********************************************************************************************/
void McpSerialInput(void) bool McpSerialInput(void)
{ {
if (McpSerial->available()) { serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
unsigned long start = millis(); unsigned long start = millis();
while (millis() - start < 20) { while (millis() - start < 20) {
yield(); yield();
if (McpSerial->available()) { if (Serial.available()) {
mcp_buffer[mcp_byte_counter++] = McpSerial->read(); serial_in_buffer[serial_in_byte_counter++] = Serial.read();
start = millis(); start = millis();
} }
} }
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, (uint8_t*)mcp_buffer, mcp_byte_counter); AddLogSerial(LOG_LEVEL_DEBUG_MORE);
if (1 == mcp_byte_counter) { if (1 == serial_in_byte_counter) {
if (MCP_ERROR_CRC == mcp_buffer[0]) { if (MCP_ERROR_CRC == serial_in_buffer[0]) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: Send " D_CHECKSUM_FAILURE)); // AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: Send " D_CHECKSUM_FAILURE));
mcp_timeout = 0; mcp_timeout = 0;
} }
else if (MCP_ERROR_NAK == mcp_buffer[0]) { else if (MCP_ERROR_NAK == serial_in_buffer[0]) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: NAck")); // AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: NAck"));
mcp_timeout = 0; mcp_timeout = 0;
} }
} }
else if (MCP_ACK_FRAME == mcp_buffer[0]) { else if (MCP_ACK_FRAME == serial_in_buffer[0]) {
if (mcp_byte_counter == mcp_buffer[1]) { if (serial_in_byte_counter == serial_in_buffer[1]) {
if (McpChecksum((uint8_t *)mcp_buffer) != mcp_buffer[mcp_byte_counter -1]) { if (McpChecksum((uint8_t *)serial_in_buffer) != serial_in_buffer[serial_in_byte_counter -1]) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: " D_CHECKSUM_FAILURE)); AddLog_P(LOG_LEVEL_DEBUG, PSTR("MCP: " D_CHECKSUM_FAILURE));
} else { } else {
if (5 == mcp_buffer[1]) { McpAddressReceive(); } if (5 == serial_in_buffer[1]) { McpAddressReceive(); }
if (25 == mcp_buffer[1]) { McpParseData(); } if (25 == serial_in_buffer[1]) { McpParseData(); }
if (MCP_CALIBRATION_LEN + 3 == mcp_buffer[1]) { McpParseCalibration(); } if (MCP_CALIBRATION_LEN + 3 == serial_in_buffer[1]) { McpParseCalibration(); }
if (MCP_FREQUENCY_LEN + 3 == mcp_buffer[1]) { McpParseFrequency(); } if (MCP_FREQUENCY_LEN + 3 == serial_in_buffer[1]) { McpParseFrequency(); }
} }
} }
mcp_timeout = 0; mcp_timeout = 0;
} }
else if (MCP_SINGLE_WIRE == mcp_buffer[0]) { else if (MCP_SINGLE_WIRE == serial_in_buffer[0]) {
mcp_timeout = 0; mcp_timeout = 0;
} }
return 1;
mcp_byte_counter = 0;
McpSerial->flush();
}
} }
/********************************************************************************************/ /********************************************************************************************/
@ -554,35 +543,27 @@ void McpEverySecond(void)
void McpSnsInit(void) void McpSnsInit(void)
{ {
// Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions SetSeriallog(LOG_LEVEL_NONE); // Free serial interface from logging interference
McpSerial = new TasmotaSerial(pin[GPIO_MCP39F5_RX], pin[GPIO_MCP39F5_TX], 1); if (pin[GPIO_MCP39_RST] < 99) {
if (McpSerial->begin(4800)) { digitalWrite(pin[GPIO_MCP39_RST], 1); // MCP enable
if (McpSerial->hardwareSerial()) { ClaimSerial(); }
if (pin[GPIO_MCP39F5_RST] < 99) {
digitalWrite(pin[GPIO_MCP39F5_RST], 1); // MCP enable
}
} else {
energy_flg = ENERGY_NONE;
} }
} }
void McpDrvInit(void) void McpDrvInit(void)
{ {
if (!energy_flg) { if (!energy_flg) {
if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) { if ((pin[GPIO_MCP39_RX] < 99) && (pin[GPIO_MCP39_TX] < 99)) {
mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE)); if (pin[GPIO_MCP39_RST] < 99) {
if (mcp_buffer != NULL) { pinMode(pin[GPIO_MCP39_RST], OUTPUT);
if (pin[GPIO_MCP39F5_RST] < 99) { digitalWrite(pin[GPIO_MCP39_RST], 0); // MCP disable - Reset Delta Sigma ADC's
pinMode(pin[GPIO_MCP39F5_RST], OUTPUT);
digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's
} }
baudrate = 4800;
mcp_calibrate = 0; mcp_calibrate = 0;
mcp_timeout = 2; // Initial wait mcp_timeout = 2; // Initial wait
mcp_init = 2; // Initial setup steps mcp_init = 2; // Initial setup steps
energy_flg = XNRG_04; energy_flg = XNRG_04;
} }
} }
}
} }
bool McpCommand(void) bool McpCommand(void)
@ -651,15 +632,15 @@ int Xnrg04(uint8_t function)
case FUNC_INIT: case FUNC_INIT:
McpSnsInit(); McpSnsInit();
break; break;
case FUNC_LOOP:
McpSerialInput();
break;
case FUNC_EVERY_SECOND: case FUNC_EVERY_SECOND:
McpEverySecond(); McpEverySecond();
break; break;
case FUNC_COMMAND: case FUNC_COMMAND:
result = McpCommand(); result = McpCommand();
break; break;
case FUNC_SERIAL:
result = McpSerialInput();
break;
} }
} }
return result; return result;