Skip to content
Browse files

Missing code for --delete

Also:
* --shift option to adjust for incorrectly set time zone on a watch
* in certain cases watch remains in Connected mode, e.g. does not show Charging. This needs to be fixed as current fix in code may not always work.
  • Loading branch information...
1 parent 6807915 commit fc0d7e239b1f5072e790f9f2ec20b4bb51640b61 @mlt committed
Showing with 23 additions and 5 deletions.
  1. +1 −0 linux/schwinn810
  2. +14 −5 src/core/device.py
  3. +8 −0 src/download.py
View
1 linux/schwinn810
@@ -18,5 +18,6 @@ mkdir -p -m 2775 "$DIR/$YEAR"
--port $PORT \
--progress gtk \
--read-settings \
+ --delete \
--dir "$DIR/$YEAR" && \
[ "$NOTIFY" ] && notify-send -u low -c transfer.complete "Schwinn 810 GPS watch" "Data extracted"
View
19 src/core/device.py
@@ -22,11 +22,12 @@ class Device:
def __init__(self, device=None, debug=False):
self.device = device
self._debug = debug
- self.dump = False
+ self.dump = False # are we reading previously backed up dump?
self.connected = False
- self.port = None
- self.reader = None
- self.backup = None
+ self.port = None # device handle
+ self.reader = None # device specific data chunk parser
+ self.backup = None # backup file handle
+ self.shift = None # fix for incorrect TZ set on watch
if self.device:
self.open()
@@ -94,6 +95,10 @@ def _read_tracks(self, writer, count):
_log.info("There are %d laps in %s" % (track['Laps'], track['Track']))
# _log.debug("Testing", extra = track)
+ if self.shift:
+ track['Start'] += self.shift
+ if 'End' in track:
+ track['End'] += self.shift
writer.add_track(track)
for j in range(track['Laps']):
@@ -132,6 +137,8 @@ def read(self, writer, progress=None):
point['Time'] = datetime.combine(summary['Start'].date(), point['Time'])
if summary['Start'] > point['Time']:
point['Time'] += timedelta(days=1)
+ if self.shift:
+ point['Time'] += self.shift
writer.add_point(point)
writer.commit()
@@ -151,8 +158,9 @@ def read_settings(self, writer):
def clear(self):
if not self.dump and self._debug:
self.port.write(DELETE)
+ self.reader.read_end()
else:
- _log.info("Debug is required for deletion for now")
+ _log.warn("Debug is required for deletion for now")
def close(self):
if self._debug:
@@ -160,6 +168,7 @@ def close(self):
if not self.dump:
self.port.write(DISCONNECT)
+ self.port.read(1)
self.port.close()
if __name__ == '__main__':
View
8 src/download.py
@@ -4,6 +4,7 @@
from core.writer_csv import Writer
# from extra.writer_sqlite import SQLiteWriter
from core.progress_text import TextProgress
+from datetime import timedelta
import argparse, os, sys
import logging
@@ -35,6 +36,7 @@ def main():
help='Progress indicator')
parser.add_argument('--read-settings', action='store_true',
help='Retrieve settings from watch')
+ parser.add_argument('--shift', type=float, help='Time adjustments in hours to apply if wrong TZ was set')
# parser.add_argument('--add-year', dest='add_year', action='store_true',
# help='Creates subfolder in dir named after the current year')
# parser.add_argument('--add-id', dest='add_id', action='store_true',
@@ -63,9 +65,15 @@ def main():
p = QtProgress()
except ImportError:
_log.error('Failed to create QT backend')
+ if args.shift:
+ d.shift = timedelta(hours=args.shift)
+ _log.info("Applying {:f} hours shift".format(args.shift))
d.read(w, p)
if args.read_settings:
+ _log.info("Reading settings")
d.read_settings(w)
+ if args.delete:
+ d.clear()
d.close()
except SerialException as e:
_log.fatal("Port can't be opened :(")

0 comments on commit fc0d7e2

Please sign in to comment.
Something went wrong with that request. Please try again.