wordclock/libraries/States/ControlTextState..cpp
2019-02-13 19:27:22 +01:00

62 lines
1.3 KiB
C++

#include <ControlStates.h>
ControlTextState::ControlTextState(AT24C32 &_at24c32)
{
at24c32 = _at24c32;
}
void ControlTextState::leftPressed(ViewStates &viewState, ControlStates &controlState)
{
uint8_t length = at24c32.read(TEXT_SIZE_ADDRESS);
if (length > 2)
{
length--;
at24c32.write(TEXT_SIZE_ADDRESS, length);
}
};
void ControlTextState::rightPressed(ViewStates &viewState, ControlStates &controlState)
{
uint8_t length = at24c32.read(TEXT_SIZE_ADDRESS);
if (length < 0xFF)
{
length++;
at24c32.write(TEXT_SIZE_ADDRESS, length);
}
};
void ControlTextState::enterPressed(ViewStates &viewState, ControlStates &controlState)
{
controlState = ControlStates::VIEW;
};
void ControlTextState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
{
uint8_t position = at24c32.read(TEXT_SIZE_ADDRESS) - 1;
uint8_t char1 = at24c32.read(TEXT_ADDRESS + position);
if (char1 > 0)
{
char1--;
}
else
{
char1 = 0xFF;
}
at24c32.write(TEXT_ADDRESS + position, char1);
};
void ControlTextState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
{
uint8_t position = at24c32.read(TEXT_SIZE_ADDRESS) - 1;
uint8_t char1 = at24c32.read(TEXT_ADDRESS + position);
if (char1 < 0xFF)
{
char1++;
}
else
{
char1 = 0;
}
at24c32.write(TEXT_ADDRESS + position, char1);
};