Telescope Control Library

Dependents:   PushToGo-F429

Revision:
0:6cb2eaf8b133
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GrayAbsEncoder.h	Sun Aug 19 05:21:20 2018 +0000
@@ -0,0 +1,44 @@
+/*
+ * GrayAbsEncoder.h
+ *
+ *  Created on: 2018Äê2ÔÂ7ÈÕ
+ *      Author: caoyuan9642
+ */
+
+#ifndef GRAYABSENCODER_H_
+
+#define GRAYABSENCODER_H_
+
+#include <AbsEncoder.h>
+
+template<uint8_t N>
+class GrayAbsEncoder: public AbsEncoder<(1 << N)>
+{
+public:
+	GrayAbsEncoder()
+	{
+	}
+	virtual ~GrayAbsEncoder()
+	{
+	}
+
+	virtual uint32_t readPosGray() = 0;
+	virtual uint32_t readPos()
+	{
+		/*Convert Gray code to Binary code*/
+		uint32_t grayPos = readPosGray();
+		uint32_t binPos = grayPos;
+		for (grayPos >>= 1; grayPos; grayPos >>= 1)
+			binPos ^= grayPos;
+		return binPos;
+	}
+
+	uint8_t getBits() const
+	{
+		return N;
+	}
+};
+
+#endif /* GRAYABSENCODER_H_ */
+
+