Telescope Control Library

Dependents:   PushToGo-F429

GrayAbsEncoder.h

Committer:
caoyuan9642
Date:
2018-08-19
Revision:
0:6cb2eaf8b133

File content as of revision 0:6cb2eaf8b133:

/*
 * 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_ */