From faa4ddd98fc899cb5209815b2c75d58c4a3edaab Mon Sep 17 00:00:00 2001 From: ml1050 Date: Mon, 23 Jan 2012 23:12:04 +0100 Subject: [PATCH] member functions moved around --- .../sensors/ant/SensorDataProcessor.java | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/SensorDataProcessor.java b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/SensorDataProcessor.java index ba9bab4fa..6bb37c6c0 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/SensorDataProcessor.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/sensors/ant/SensorDataProcessor.java @@ -44,25 +44,6 @@ public class SensorDataProcessor { } } - /** - * Removes old data from the history. - * - * @param now the current system time - * @return true if the remaining history is not empty - */ - protected boolean removeOldHistory(long now) { - HistoryElement h; - while ((h = history.peek()) != null) { - // if the first element of the list is in our desired time range then return - if (now - h.systemTime <= HISTORY_LENGTH_MILLIS && history.size() < HISTORY_MAX_LENGTH) { - return true; - } - // otherwise remove the too old element, and look at the next (newer) one - history.removeFirst(); - } - return false; - } - /** * The latest counter value reported by the sensor */ @@ -92,38 +73,6 @@ public class SensorDataProcessor { history = new LinkedList(); } - /** - * Calculates the instantaneous sensor value to be displayed - * using the history when the sensor only resends the old data - */ - private int getValueFromHistory(long now) { - if (!removeOldHistory(now)) { - // there is nothing in the history, return 0 - return eventsPerMinute = 0; - } - HistoryElement f = history.getFirst(); - HistoryElement l = history.getLast(); - int sensorTimeChange = (l.sensorTime - f.sensorTime) & 0xFFFF; - int counterChange = (counter - f.counter) & 0xFFFF; - - // difference between now and systemTime of the oldest history entry - // for better precision sensor timestamps are considered between - // the first and the last history entry (could be overkill) - int systemTimeChange = (int) (now - l.systemTime - + (sensorTimeChange * ONE_SECOND_MILLIS) / SENSOR_TIME_RESOLUTION); - - // eventsPerMinute is not overwritten by this calculated value - // because it is still needed when a new sensor event arrives - int v = (counterChange * ONE_MINUTE_MILLIS) / systemTimeChange; - Log.d(TAG, "getEventsPerMinute returns (2):" + v); - - // do not return larger number than eventsPerMinute, because the reason - // this function got called is that more time has passed after the last - // sensor counter value change than the current eventsPerMinute - // would be valid - return v < eventsPerMinute ? v : eventsPerMinute; - } - /** * Calculates the instantaneous sensor value to be displayed * @@ -178,4 +127,55 @@ public class SensorDataProcessor { Log.d(TAG, "getEventsPerMinute returns:" + eventsPerMinute); return eventsPerMinute; } + + /** + * Calculates the instantaneous sensor value to be displayed + * using the history when the sensor only resends the old data + */ + private int getValueFromHistory(long now) { + if (!removeOldHistory(now)) { + // there is nothing in the history, return 0 + return eventsPerMinute = 0; + } + HistoryElement f = history.getFirst(); + HistoryElement l = history.getLast(); + int sensorTimeChange = (l.sensorTime - f.sensorTime) & 0xFFFF; + int counterChange = (counter - f.counter) & 0xFFFF; + + // difference between now and systemTime of the oldest history entry + // for better precision sensor timestamps are considered between + // the first and the last history entry (could be overkill) + int systemTimeChange = (int) (now - l.systemTime + + (sensorTimeChange * ONE_SECOND_MILLIS) / SENSOR_TIME_RESOLUTION); + + // eventsPerMinute is not overwritten by this calculated value + // because it is still needed when a new sensor event arrives + int v = (counterChange * ONE_MINUTE_MILLIS) / systemTimeChange; + Log.d(TAG, "getEventsPerMinute returns (2):" + v); + + // do not return larger number than eventsPerMinute, because the reason + // this function got called is that more time has passed after the last + // sensor counter value change than the current eventsPerMinute + // would be valid + return v < eventsPerMinute ? v : eventsPerMinute; + } + + /** + * Removes old data from the history. + * + * @param now the current system time + * @return true if the remaining history is not empty + */ + private boolean removeOldHistory(long now) { + HistoryElement h; + while ((h = history.peek()) != null) { + // if the first element of the list is in our desired time range then return + if (now - h.systemTime <= HISTORY_LENGTH_MILLIS && history.size() < HISTORY_MAX_LENGTH) { + return true; + } + // otherwise remove the too old element, and look at the next (newer) one + history.removeFirst(); + } + return false; + } }