Changeset 43
- Timestamp:
- 02/01/10 22:24:48 (15 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c
r42 r43 92 92 } 93 93 94 void handle GasMeterTick(void)94 void handleMeterTick(portSHORT portNum) 95 95 { 96 96 unsigned long long currentTime = getEpochTimeWithMs(); /* current epoch time with ms in ms */ 97 if ( currentTime > (meterItems[METER_INDEX_GAS].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) 97 98 globalValue++; 99 // LCD_cls(); 100 //LCD_puts( ( signed portCHAR * ) "xyz" ); 101 102 103 if ( currentTime > (meterItems[portNum].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) 98 104 { 99 105 /* we have a tick that is not a bounce */ 100 meterItems[METER_INDEX_GAS].currentValue++; /* one more tick. always increase the counter */ 106 meterItems[portNum].currentValue++; /* one more tick. always increase the counter */ 107 101 108 102 109 /* now check if we should accumulate the ticks for this time period so we leave the new data item available long 103 110 * enough on the web page to be read by the server 104 111 */ 105 if ( currentTime > ((unsigned long long)meterItems[ METER_INDEX_GAS].timeBeforeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) )112 if ( currentTime > ((unsigned long long)meterItems[portNum].timeBeforeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) ) 106 113 { 114 115 116 117 107 118 /* if the last meter tick happened longer than DEBOUNCE_TICK_THRESHOLD_MS ago (i.e. the switch did not just bounce), 108 119 * we create a new data item 109 120 */ 110 meterItems[ METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? (epoch in milliseconds) */111 meterItems[ METER_INDEX_GAS].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */112 meterItems[ METER_INDEX_GAS].valueBeforeLastTick = meterItems[METER_INDEX_GAS].valueLastTick; /* what value did we have at the tick before the last tick? */113 meterItems[ METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue; /* what value did we have at the last tick? now one more! */121 meterItems[portNum].timeBeforeLastTick = meterItems[portNum].timeLastTick; /* when did the tick before the last tick occur? (epoch in milliseconds) */ 122 meterItems[portNum].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */ 123 meterItems[portNum].valueBeforeLastTick = meterItems[portNum].valueLastTick; /* what value did we have at the tick before the last tick? */ 124 meterItems[portNum].valueLastTick = meterItems[portNum].currentValue; /* what value did we have at the last tick? now one more! */ 114 125 /* at present, valueLastTick and currentValue are the same. This might be different for future versions. */ 115 126 } … … 117 128 { 118 129 /* do not create a new data item, but update the current "last" data item */ 119 meterItems[ METER_INDEX_GAS].timeLastTick = currentTime;120 meterItems[ METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue;130 meterItems[portNum].timeLastTick = currentTime; 131 meterItems[portNum].valueLastTick = meterItems[portNum].currentValue; 121 132 } 122 133 }