You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

5 years ago
  1. #include <ControlStates.h>
  2. ControlTextState::ControlTextState(AT24C32 &_at24c32)
  3. {
  4. at24c32 = _at24c32;
  5. }
  6. void ControlTextState::leftPressed(ViewStates &viewState, ControlStates &controlState)
  7. {
  8. uint8_t length = at24c32.read(TEXT_SIZE_ADDRESS);
  9. if (length > 2)
  10. {
  11. length--;
  12. at24c32.write(TEXT_SIZE_ADDRESS, length);
  13. }
  14. };
  15. void ControlTextState::rightPressed(ViewStates &viewState, ControlStates &controlState)
  16. {
  17. uint8_t length = at24c32.read(TEXT_SIZE_ADDRESS);
  18. if (length < 0xFF)
  19. {
  20. length++;
  21. at24c32.write(TEXT_SIZE_ADDRESS, length);
  22. }
  23. };
  24. void ControlTextState::enterPressed(ViewStates &viewState, ControlStates &controlState)
  25. {
  26. controlState = ControlStates::VIEW;
  27. };
  28. void ControlTextState::decrementPressed(ViewStates &viewState, ControlStates &controlState)
  29. {
  30. uint8_t position = at24c32.read(TEXT_SIZE_ADDRESS) - 1;
  31. uint8_t char1 = at24c32.read(TEXT_ADDRESS + position);
  32. if (char1 > 0)
  33. {
  34. char1--;
  35. }
  36. else
  37. {
  38. char1 = 0xFF;
  39. }
  40. at24c32.write(TEXT_ADDRESS + position, char1);
  41. };
  42. void ControlTextState::incrementPressed(ViewStates &viewState, ControlStates &controlState)
  43. {
  44. uint8_t position = at24c32.read(TEXT_SIZE_ADDRESS) - 1;
  45. uint8_t char1 = at24c32.read(TEXT_ADDRESS + position);
  46. if (char1 < 0xFF)
  47. {
  48. char1++;
  49. }
  50. else
  51. {
  52. char1 = 0;
  53. }
  54. at24c32.write(TEXT_ADDRESS + position, char1);
  55. };