128 lines
3.0 KiB
C++
128 lines
3.0 KiB
C++
#include <ControlStates.h>
|
|
|
|
ControlColorState::ControlColorState(AT24C32 &_at24c32)
|
|
{
|
|
at24c32 = _at24c32;
|
|
}
|
|
|
|
void ControlColorState::leftPressed(ViewStates &viewState, ControlStates &controlState)
|
|
{
|
|
switch (controlState)
|
|
{
|
|
case ControlStates::COLOR_R:
|
|
controlState = ControlStates::COLOR_B;
|
|
break;
|
|
case ControlStates::COLOR_G:
|
|
controlState = ControlStates::COLOR_R;
|
|
break;
|
|
case ControlStates::COLOR_B:
|
|
controlState = ControlStates::COLOR_G;
|
|
break;
|
|
}
|
|
};
|
|
|
|
void ControlColorState::rightPressed(ViewStates &viewState, ControlStates &controlState)
|
|
{
|
|
switch (controlState)
|
|
{
|
|
case ControlStates::COLOR_R:
|
|
controlState = ControlStates::COLOR_G;
|
|
break;
|
|
case ControlStates::COLOR_G:
|
|
controlState = ControlStates::COLOR_B;
|
|
break;
|
|
case ControlStates::COLOR_B:
|
|
controlState = ControlStates::COLOR_R;
|
|
break;
|
|
}
|
|
};
|
|
|
|
void ControlColorState::enterPressed(ViewStates &viewState, ControlStates &controlState)
|
|
{
|
|
controlState = ControlStates::VIEW;
|
|
};
|
|
|
|
void ControlColorState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
|
|
{
|
|
switch (controlState)
|
|
{
|
|
case ControlStates::COLOR_R:
|
|
decrementColorR();
|
|
break;
|
|
case ControlStates::COLOR_G:
|
|
decrementColorG();
|
|
break;
|
|
case ControlStates::COLOR_B:
|
|
decrementColorB();
|
|
break;
|
|
}
|
|
};
|
|
|
|
void ControlColorState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
|
|
{
|
|
switch (controlState)
|
|
{
|
|
case ControlStates::COLOR_R:
|
|
incrementColorR();
|
|
break;
|
|
case ControlStates::COLOR_G:
|
|
incrementColorG();
|
|
break;
|
|
case ControlStates::COLOR_B:
|
|
incrementColorB();
|
|
break;
|
|
}
|
|
};
|
|
|
|
void ControlColorState::decrementColorR()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t red = (color >> 5);
|
|
red = (red - 1) % 8;
|
|
color = (red << 5) + (color & 0x1F);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
}
|
|
void ControlColorState::incrementColorR()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t red = (color >> 5);
|
|
red = (red + 1) % 8;
|
|
color = (red << 5) + (color & 0x1F);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
}
|
|
|
|
void ControlColorState::decrementColorG()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t green = (color >> 2) & 0x07;
|
|
green = (green - 1) % 8;
|
|
color = (green << 2) + (color & 0xE3);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
}
|
|
|
|
void ControlColorState::incrementColorG()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t green = (color >> 2) & 0x07;
|
|
green = (green + 1) % 8;
|
|
color = (green << 2) + (color & 0xE3);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
}
|
|
|
|
void ControlColorState::decrementColorB()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t blue = color & 0x03;
|
|
blue = (blue - 1) % 4;
|
|
color = blue + (color & 0xFC);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
}
|
|
|
|
void ControlColorState::incrementColorB()
|
|
{
|
|
uint8_t color = at24c32.read(COLOR_ADDRESS);
|
|
uint8_t blue = color & 0x03;
|
|
blue = (blue + 1) % 4;
|
|
color = blue + (color & 0xFC);
|
|
at24c32.write(COLOR_ADDRESS, color);
|
|
} |