Index: /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c (revision 42) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c (revision 43) @@ -92,24 +92,35 @@ } -void handleGasMeterTick(void) +void handleMeterTick(portSHORT portNum) { unsigned long long currentTime = getEpochTimeWithMs(); /* current epoch time with ms in ms */ - if ( currentTime > (meterItems[METER_INDEX_GAS].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) + + globalValue++; + // LCD_cls(); + //LCD_puts( ( signed portCHAR * ) "xyz" ); + + + if ( currentTime > (meterItems[portNum].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) { /* we have a tick that is not a bounce */ - meterItems[METER_INDEX_GAS].currentValue++; /* one more tick. always increase the counter */ + meterItems[portNum].currentValue++; /* one more tick. always increase the counter */ + /* now check if we should accumulate the ticks for this time period so we leave the new data item available long * enough on the web page to be read by the server */ - if ( currentTime > ((unsigned long long)meterItems[METER_INDEX_GAS].timeBeforeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) ) + if ( currentTime > ((unsigned long long)meterItems[portNum].timeBeforeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) ) { + + + + /* if the last meter tick happened longer than DEBOUNCE_TICK_THRESHOLD_MS ago (i.e. the switch did not just bounce), * we create a new data item */ - meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? (epoch in milliseconds) */ - meterItems[METER_INDEX_GAS].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */ - meterItems[METER_INDEX_GAS].valueBeforeLastTick = meterItems[METER_INDEX_GAS].valueLastTick; /* what value did we have at the tick before the last tick? */ - meterItems[METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue; /* what value did we have at the last tick? now one more! */ + meterItems[portNum].timeBeforeLastTick = meterItems[portNum].timeLastTick; /* when did the tick before the last tick occur? (epoch in milliseconds) */ + meterItems[portNum].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */ + meterItems[portNum].valueBeforeLastTick = meterItems[portNum].valueLastTick; /* what value did we have at the tick before the last tick? */ + meterItems[portNum].valueLastTick = meterItems[portNum].currentValue; /* what value did we have at the last tick? now one more! */ /* at present, valueLastTick and currentValue are the same. This might be different for future versions. */ } @@ -117,6 +128,6 @@ { /* do not create a new data item, but update the current "last" data item */ - meterItems[METER_INDEX_GAS].timeLastTick = currentTime; - meterItems[METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue; + meterItems[portNum].timeLastTick = currentTime; + meterItems[portNum].valueLastTick = meterItems[portNum].currentValue; } }