63 | | meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? */ |
---|
64 | | meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ |
---|
65 | | meterItems[METER_INDEX_GAS].valueLastTick = 0; /* what value did we have at the last tick? */ |
---|
66 | | meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1; /* what value did we have at the tick before the last tick? */ |
---|
| 63 | unsigned long long currentTime = getEpochTimeWithMs(); /* current epoch time with ms in ms */ |
---|
| 64 | if ( currentTime > (meterItems[METER_INDEX_GAS].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) |
---|
| 65 | { |
---|
| 66 | /* we have a tick that is not a bounce */ |
---|
| 67 | meterItems[METER_INDEX_GAS].currentValue++; /* one more tick. always increase the counter */ |
---|
| 68 | |
---|
| 69 | /* now check if we should accumulate the ticks for this time period so we leave the new data item available long |
---|
| 70 | * enough on the web page to be read by the server |
---|
| 71 | */ |
---|
| 72 | if ( currentTime > ((unsigned long long)meterItems[METER_INDEX_GAS].timeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) ) |
---|
| 73 | { |
---|
| 74 | /* if the last meter tick happened longer than DEBOUNCE_TICK_THRESHOLD_MS ago (i.e. the switch did not just bounce) */ |
---|
| 75 | meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? (epoch in milliseconds) */ |
---|
| 76 | meterItems[METER_INDEX_GAS].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */ |
---|
| 77 | meterItems[METER_INDEX_GAS].valueBeforeLastTick = meterItems[METER_INDEX_GAS].valueLastTick; /* what value did we have at the tick before the last tick? */ |
---|
| 78 | meterItems[METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue; /* what value did we have at the last tick? now one more! */ |
---|
| 79 | /* at present, valueLastTick and currentValue are the same. This might be different for future versions. */ |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | ; /* nothing to do, curentValue was increased already above */ |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | ; /* we bounced, ignore this tick */ |
---|
| 89 | } |
---|