wordclock/libraries/States/ControlTimeState.cpp

82 lines
1.9 KiB
C++
Raw Normal View History

2019-02-13 19:27:22 +01:00
#include <ControlStates.h>
ControlTimeState::ControlTimeState(DS3231 &_ds3231, AT24C32 &_at24c32)
{
ds3231 = _ds3231;
at24c32 = _at24c32;
}
void ControlTimeState::leftPressed(ViewStates &viewState, ControlStates &controlState)
{
switch (controlState)
{
case ControlStates::TIME_HOURS:
controlState = ControlStates::TIME_MODE;
break;
case ControlStates::TIME_MINUTES:
controlState = ControlStates::TIME_HOURS;
break;
case ControlStates::TIME_MODE:
controlState = ControlStates::TIME_MINUTES;
break;
}
};
void ControlTimeState::rightPressed(ViewStates &viewState, ControlStates &controlState)
{
switch (controlState)
{
case ControlStates::TIME_HOURS:
controlState = ControlStates::TIME_MINUTES;
break;
case ControlStates::TIME_MINUTES:
controlState = ControlStates::TIME_MODE;
break;
case ControlStates::TIME_MODE:
controlState = ControlStates::TIME_HOURS;
break;
}
};
void ControlTimeState::enterPressed(ViewStates &viewState, ControlStates &controlState)
{
controlState = ControlStates::VIEW;
};
void ControlTimeState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
{
switch (controlState)
{
case ControlStates::TIME_HOURS:
ds3231.decrementHours();
break;
case ControlStates::TIME_MINUTES:
ds3231.decrementMinutes();
break;
case ControlStates::TIME_MODE:
uint8_t mode = at24c32.read(TIME_MODE_ADDRESS);
mode = (mode - 1) % 3;
at24c32.write(TIME_MODE_ADDRESS, mode);
break;
}
};
void ControlTimeState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
{
switch (controlState)
{
case ControlStates::TIME_HOURS:
ds3231.incrementHours();
break;
case ControlStates::TIME_MINUTES:
ds3231.incrementMinutes();
break;
case ControlStates::TIME_MODE:
uint8_t mode = at24c32.read(TIME_MODE_ADDRESS);
mode = (mode + 1) % 3;
at24c32.write(TIME_MODE_ADDRESS, mode);
break;
}
};