Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
/*****************************************************************************
Encoder.cpp
Copyright (c) 2020 Raphael DINGE
*Tab=3***********************************************************************/
/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "erb/Encoder.h"
namespace erb
{
/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*
==============================================================================
Name : ctor
==============================================================================
*/
Encoder::Encoder (const uint8_t & data_a, const uint8_t & data_b)
: impl_data_a (data_a)
, impl_data_b (data_b)
{
}
/*
==============================================================================
Name : operator int
==============================================================================
*/
Encoder::operator int () const
{
return _val;
}
/*\\\ INTERNAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*
==============================================================================
Name : impl_preprocess
==============================================================================
*/
void Encoder::impl_preprocess ()
{
_state_a = uint8_t (_state_a << 1) | (impl_data_a != 0);
_state_b = uint8_t (_state_b << 1) | (impl_data_b != 0);
if ((_state_a & 0x03) == 0x02 && (_state_b & 0x03) == 0x00)
{
_val = -1;
}
else if ((_state_b & 0x03) == 0x02 && (_state_a & 0x03) == 0x00)
{
_val = 1;
}
else
{
_val = 0;
}
}
/*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
} // namespace erb
/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
839fa7c5fThis file is pinned to the selected release. Download the original to open it in your design tool.