1.1 --- a/Hardware/Sensor.cs Tue Jul 17 16:10:59 2012 +0000
1.2 +++ b/Hardware/Sensor.cs Tue Jul 17 16:12:07 2012 +0000
1.3 @@ -4,7 +4,7 @@
1.4 License, v. 2.0. If a copy of the MPL was not distributed with this
1.5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
1.6
1.7 - Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
1.8 + Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
1.9
1.10 */
1.11
1.12 @@ -76,14 +76,19 @@
1.13 private void SetSensorValuesToSettings() {
1.14 using (MemoryStream m = new MemoryStream()) {
1.15 using (GZipStream c = new GZipStream(m, CompressionMode.Compress))
1.16 - using (BinaryWriter writer = new BinaryWriter(c)) {
1.17 + using (BufferedStream b = new BufferedStream(c, 65536))
1.18 + using (BinaryWriter writer = new BinaryWriter(b)) {
1.19 + long t = 0;
1.20 foreach (SensorValue sensorValue in values) {
1.21 - writer.Write(sensorValue.Time.ToBinary());
1.22 + long v = sensorValue.Time.ToBinary();
1.23 + writer.Write(v - t);
1.24 + t = v;
1.25 writer.Write(sensorValue.Value);
1.26 }
1.27 + writer.Flush();
1.28 }
1.29 settings.SetValue(new Identifier(Identifier, "values").ToString(),
1.30 - Convert.ToBase64String(m.ToArray()));
1.31 + Convert.ToBase64String(m.ToArray()));
1.32 }
1.33 }
1.34
1.35 @@ -98,8 +103,10 @@
1.36 using (GZipStream c = new GZipStream(m, CompressionMode.Decompress))
1.37 using (BinaryReader reader = new BinaryReader(c)) {
1.38 try {
1.39 + long t = 0;
1.40 while (true) {
1.41 - DateTime time = DateTime.FromBinary(reader.ReadInt64());
1.42 + t += reader.ReadInt64();
1.43 + DateTime time = DateTime.FromBinary(t);
1.44 float value = reader.ReadSingle();
1.45 AppendValue(value, time);
1.46 }