Merge pull request #9709 from gemu2015/sml_update

sml update
This commit is contained in:
Theo Arends 2020-11-02 13:50:50 +01:00 committed by GitHub
commit 8dfb4ec6ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 42 deletions

View File

@ -107,9 +107,21 @@ struct METER_DESC {
#define COMBO3b 12
#define WGS_COMBO 13
#define EBZD_G 14
#define SML_NO_OP 15
// select this meter
#define METER EHZ161_1
// SML_NO_OP ignores hardcoded interface
#define METER SML_NO_OP
//#define METER EHZ161_1
#if METER==SML_NO_OP
#undef METERS_USED
#define METERS_USED 0
struct METER_DESC const meter_desc[1]={
[0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}};
const uint8_t meter[]=
"1,1-0:1.8.0*255(@1," D_TPWRIN ",kWh," DJ_TPWRIN ",4|";
#endif
#if METER==EHZ161_0
@ -1662,6 +1674,7 @@ void SML_Show(boolean json) {
//char b_mqtt_data[MESSZ];
//b_mqtt_data[0]=0;
if (!meters_used) return;
int8_t lastmind=((*mp)&7)-1;
if (lastmind<0 || lastmind>=meters_used) lastmind=0;
@ -1794,7 +1807,7 @@ void SML_Show(boolean json) {
}
/*
#ifdef USE_DOMOTICZ
if (json && !TasmotaGlobal.tele_period) {
char str[16];
@ -1806,7 +1819,7 @@ void SML_Show(boolean json) {
DomoticzSensor(DZ_CURRENT, str); // Current
}
#endif // USE_DOMOTICZ
*/
}
struct SML_COUNTER {
@ -1826,39 +1839,32 @@ struct SML_COUNTER {
#endif
} sml_counters[MAX_COUNTERS];
void ICACHE_RAM_ATTR SML_CounterUpd(uint8_t index) {
uint8_t sml_counter_pinstate;
uint8_t level=digitalRead(meter_desc_p[sml_counters[index].sml_cnt_old_state].srcpin);
if (!level) {
// falling edge
uint32_t ltime=millis()-sml_counters[index].sml_counter_ltime;
sml_counters[index].sml_counter_ltime=millis();
if (ltime>sml_counters[index].sml_debounce) {
RtcSettings.pulse_counter[index]++;
sml_counters[index].sml_cnt_updated=1;
//InjektCounterValue(sml_counters[index].sml_cnt_old_state,RtcSettings.pulse_counter[index]);
}
} else {
// rising edge
sml_counters[index].sml_counter_ltime=millis();
uint8_t sml_cnt_index[MAX_COUNTERS] = { 0, 1, 2, 3 };
void ICACHE_RAM_ATTR SML_CounterIsr(void *arg) {
uint32_t index = *static_cast<uint8_t*>(arg);
uint32_t time = micros();
uint32_t debounce_time;
if (digitalRead(meter_desc_p[sml_counters[index].sml_cnt_old_state].srcpin) == bitRead(sml_counter_pinstate, index)) {
return;
}
debounce_time = time - sml_counters[index].sml_counter_ltime;
if (debounce_time <= sml_counters[index].sml_debounce * 1000) return;
if bitRead(sml_counter_pinstate, index) {
// falling edge
RtcSettings.pulse_counter[index]++;
sml_counters[index].sml_cnt_updated=1;
}
sml_counters[index].sml_counter_ltime = time;
sml_counter_pinstate ^= (1<<index);
}
void ICACHE_RAM_ATTR SML_CounterUpd1(void) {
SML_CounterUpd(0);
}
void ICACHE_RAM_ATTR SML_CounterUpd2(void) {
SML_CounterUpd(1);
}
void ICACHE_RAM_ATTR SML_CounterUpd3(void) {
SML_CounterUpd(2);
}
void ICACHE_RAM_ATTR SML_CounterUpd4(void) {
SML_CounterUpd(3);
}
#ifdef USE_SCRIPT
struct METER_DESC script_meter_desc[MAX_METERS];
@ -1916,14 +1922,6 @@ uint32_t SML_getscriptsize(char *lp) {
#endif
bool Gpio_used(uint8_t gpiopin) {
/*
for (uint16_t i=0;i<GPIO_SENSOR_END;i++) {
// if (pin_gpio[i]==gpiopin) {
if (Pin(i)==gpiopin) {
return true;
}
}
*/
if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) {
return true;
}
@ -2131,7 +2129,6 @@ next_line:
init10:
typedef void (*function)();
function counter_callbacks[] = {SML_CounterUpd1,SML_CounterUpd2,SML_CounterUpd3,SML_CounterUpd4};
uint8_t cindex=0;
// preloud counters
for (byte i = 0; i < MAX_COUNTERS; i++) {
@ -2158,7 +2155,7 @@ init10:
// check for irq mode
if (meter_desc_p[meters].params<=0) {
// init irq mode
attachInterrupt(meter_desc_p[meters].srcpin, counter_callbacks[cindex], CHANGE);
attachInterruptArg(meter_desc_p[meters].srcpin, SML_CounterIsr,&sml_cnt_index[cindex], CHANGE);
sml_counters[cindex].sml_cnt_old_state=meters;
sml_counters[cindex].sml_debounce=-meter_desc_p[meters].params;
}