From ab85adce3d21f7b91119523e189fbe5113487e6f Mon Sep 17 00:00:00 2001
From: Stephen Crane <jscrane@gmail.com>
Date: Thu, 14 Feb 2019 18:02:26 +0000
Subject: [PATCH] implement rewind properly

---
 serial_filer.cpp | 9 ++++-----
 serial_filer.h   | 5 ++++-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/serial_filer.cpp b/serial_filer.cpp
index 8cca66e..fb57da3 100644
--- a/serial_filer.cpp
+++ b/serial_filer.cpp
@@ -12,15 +12,14 @@ bool serial_filer::start(const char *) {
 const unsigned speeds[] = {
 	115200, 57600, 19200, 9600, 4800, 2400
 };
-static unsigned currsp;
 
 const char *serial_filer::advance() {
 	static char buf[16];
-	unsigned s = speeds[currsp];
+	unsigned s = speeds[_currsp];
 	Serial.begin(s);
-	currsp++;
-	if (currsp == sizeof(speeds)/sizeof(speeds[0]))
-		currsp = 0;
+	_currsp++;
+	if (_currsp == sizeof(speeds)/sizeof(speeds[0]))
+		_currsp = 0;
 	return itoa(s, buf, 10);
 }
 
diff --git a/serial_filer.h b/serial_filer.h
index 1db421a..94b3a50 100644
--- a/serial_filer.h
+++ b/serial_filer.h
@@ -6,7 +6,7 @@
 class serial_filer: public filer {
 public:
 	const char *advance();
-	const char *rewind() { return advance(); }
+	const char *rewind() { _currsp = 0; return advance(); }
 
 	const char *checkpoint();
 	void restore(const char *);
@@ -17,5 +17,8 @@ public:
 	uint8_t read();
 	bool more();
 	void write(uint8_t);
+
+private:
+	unsigned _currsp;
 };
 #endif