Index: /webserver/example/EnergyMeters/Source/EnergyMeters/Meters.c =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/Meters.c (revision 22) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/Meters.c (revision 30) @@ -120,6 +120,7 @@ meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ meterItems[METER_INDEX_GAS].timeBeforeLastTick = getEpochTimeWithMs(); /* when did the tick before last tick occur? epoch (seconds) */ - meterItems[METER_INDEX_GAS].valueLastTick = 0; /* what value did we have at the last tick? */ - meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1; /* what value did we have at the tick before the last tick? */ + meterItems[METER_INDEX_GAS].valueLastTick = 1; /* what value did we have at the last tick? */ + meterItems[METER_INDEX_GAS].currentValue = 1; /* same: start value of the meter */ + meterItems[METER_INDEX_GAS].valueBeforeLastTick = 0; /* what value did we have at the tick before the last tick? */ } Index: /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c (revision 22) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c (revision 30) @@ -61,8 +61,31 @@ void handleGasMeterTick(void) { - meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? */ - meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ - meterItems[METER_INDEX_GAS].valueLastTick = 0; /* what value did we have at the last tick? */ - meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1; /* what value did we have at the tick before the last tick? */ + unsigned long long currentTime = getEpochTimeWithMs(); /* current epoch time with ms in ms */ + if ( currentTime > (meterItems[METER_INDEX_GAS].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 */ + + /* 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].timeLastTick + ((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) */ + 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! */ + /* at present, valueLastTick and currentValue are the same. This might be different for future versions. */ + } + else + { + ; /* nothing to do, curentValue was increased already above */ + } + } + else + { + ; /* we bounced, ignore this tick */ + } } Index: /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 22) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 30) @@ -7,4 +7,6 @@ #define METER_INDEX_GAS 0 /* index of the gas meter data */ +#define DEBOUNCE_TICK_THRESHOLD_MS 50 /* when two ticks are less than this time period apart, the second tick is ignored (debouncing) */ +#define ACCUMULATE_TICK_THRESHOLD_SEC 30 /* how long (seconds) should the ticks be accumulated before a new data item is created? */ typedef struct @@ -15,4 +17,5 @@ portLONG valueLastTick; /* what value did we have at the last tick? */ portLONG valueBeforeLastTick; /* what value did we have at the tick before the last tick? */ + portLONG currentValue; /* the value of the meter. gets incremented by the ISR */ } meterItem; Index: /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/EnergyMeters.hzs =================================================================== --- /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/EnergyMeters.hzs (revision 28) +++ /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/EnergyMeters.hzs (revision 30) @@ -19,5 +19,8 @@ + + + @@ -38,5 +41,8 @@ - + + + + @@ -44,5 +50,5 @@ - + @@ -54,5 +60,10 @@ - + + + + + +