Quote:
Originally Posted by orbobigge
No, we found this within an old keyboard, made by Cherry Switch. The trackball uses 2 encoders, one for the X, and one for the Y. With an oscilloscope we found two outputs on each encoder. The first output is a clock pulse based on the encoder wheel rotation. The second output is high for clockwise, and low for counterclockwise rotation.
We are trying to use the Counter::SetExternalDirection method. According to the source codes comments:
/**
* Set external direction mode on this counter.
* Counts are sourced on the Up counter input.
* The Down counter input represents the direction to count.
*/
When setting the counter for k1X, the Get() method returns a 0 or a 1. The GetDirection() method return true or false, according to the direction of rotation. We cannot get the Get() method to count more than 0 or 1. Any help appreciated.
|
Now understanding your issue more, I wonder if you could make a class inheriting from DigitalSource and "fake" the 2nd digital input of a quadrature encoder. Since you know the actual situation you're in and you know the format a quadrature encounter is expecting the 1s and 0s to flow, you can fake it:
-If input A is 1 and input B is forward, then return 0
-If input A is 0 and input B is forward, then return 1
-If input A is 1 and input B is backwards, then return 0
-If input A is 0 and input B is backwards, then return 1
Something like
Code:
class FakeQuadrature : public DigitalSource
{
public:
// construct/pass in things, override other DigitalSource virtual functions...
bool Get()
{
bool count = trackBallCount.Get();
bool dir = trackBallDirection.Get();
if(count && dir) return 0;
else if(count && !dir) return 1;
else if(!count && dir) return 1;
else if(!count && !dir) return 0;
return 0;
}
private:
DigitalInput trackBallCount;
DigitalInput trackBallDirection;
};
Then once you've got that built, send it in as the 2nd DigitalInput to the Encoder class's constructor.