Telescope Control Library

Dependents:   PushToGo-F429

Revision:
0:6cb2eaf8b133
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialGrayAbsEncoder.h	Sun Aug 19 05:21:20 2018 +0000
@@ -0,0 +1,39 @@
+/*
+ * OmronE6CPDriver.h
+ *
+ *  Created on: 2018Äê2ÔÂ7ÈÕ
+ *      Author: caoyuan9642
+ */
+
+#ifndef TELESCOPE_DRIVER_SERIALGRAYABSENCODER_H_
+#define TELESCOPE_DRIVER_SERIALGRAYABSENCODER_H_
+
+#include <GrayAbsEncoder.h>
+#include <SerialDigitalInput.h>
+#include "mbed.h"
+
+template<uint8_t N>
+class SerialGrayAbsEncoder: public GrayAbsEncoder<N>, SerialDigitalInput<N>
+{
+public:
+	SerialGrayAbsEncoder(PinName clk, PinName load, PinName data,
+	bool polarity = false) :
+			GrayAbsEncoder<N>(), SerialDigitalInput<N>(clk, load, data), polarity(
+					polarity)
+	{
+	}
+	virtual ~SerialGrayAbsEncoder()
+	{
+	}
+
+	bool polarity; /*If polarity=false, the input will be bit-negated before converted to raw Binary*/
+	uint32_t readPosGray()
+	{
+		uint32_t data = SerialDigitalInput<N>::read();
+		return polarity ? (((1 << N) - 1) ^ data) : data;
+	}
+};
+
+#endif /* TELESCOPE_DRIVER_SERIALGRAYABSENCODER_H_ */
+
+