Download the file
  1. #include "items.h"
  2. #include "formatter.h"
  3. #include "config_item.h"
  4.  
  5. void Count::read_eeprom() {
  6. uint16_t tmp = (EEPROM.read(eeprom_address) << 8) | EEPROM.read(eeprom_address+1);
  7. if (tmp <= max_value && tmp >= min_value && tmp % step == 0) {
  8. value = tmp;
  9. }
  10. }
  11.  
  12. void Count::write_eeprom() {
  13. EEPROM.write(eeprom_address, value >> 8);
  14. EEPROM.write(eeprom_address+1, value & 0xFF);
  15. }
  16.  
  17. void Count::next() {
  18. //Serial.println("next");
  19. if (is_selected()) {
  20. if (value + step <= max_value)
  21. value += step;
  22. }
  23. }
  24.  
  25. void Count::previous() {
  26. //Serial.println("prev");
  27. if (is_selected()) {
  28. if (value - step >= min_value)
  29. value -= step;
  30. }
  31. }
  32.  
  33. uint16_t Count::get_value() {
  34. //Serial.print("v ");
  35. //Serial.println(value, DEC);
  36. return value;
  37. }
  38.  
  39. char * Count::format_value() {
  40. formatter->zero();
  41. formatter->print(get_value());
  42. formatter->align_right(format_width);
  43. return formatter->get_buffer();
  44. }
  45.  
  46. uint8_t Count::on_deselected() {
  47. write_eeprom();
  48. return 1;
  49. }
  50.  
  51. //////////////////////////////////////////////////
  52.  
  53. void Interval::read_eeprom() {
  54. uint8_t tmp = EEPROM.read(eeprom_address);
  55. if (tmp < nb_values) {
  56. index = tmp;
  57. }
  58. }
  59.  
  60. void Interval::write_eeprom() {
  61. EEPROM.write(eeprom_address, index);
  62. }
  63.  
  64. void Interval::next() {
  65. if (index < nb_values - 1)
  66. index++;
  67. }
  68.  
  69. void Interval::previous() {
  70. if (index > 0)
  71. index--;
  72. }
  73.  
  74. uint16_t Interval::get_value() {
  75. return values[index];
  76. }
  77.  
  78. char * Interval::format_value() {
  79. formatter->zero();
  80. formatter->print(values[index]/1000.0, 1);
  81. formatter->align_right(format_width);
  82. return formatter->get_buffer();
  83. }
  84.  
  85. uint8_t Interval::on_deselected() {
  86. write_eeprom();
  87. return 1;
  88. }
  89.  
  90. //////////////////////////////////////////////////
  91.  
  92. void Option::read_eeprom() {
  93. uint8_t tmp = EEPROM.read(eeprom_address);
  94. if (tmp < nb_values) {
  95. index = tmp;
  96. }
  97. }
  98.  
  99. void Option::write_eeprom() {
  100. EEPROM.write(eeprom_address, index);
  101. }
  102.  
  103. void Option::next() {
  104. if (index < nb_values - 1)
  105. index++;
  106. }
  107.  
  108. void Option::previous() {
  109. if (index > 0)
  110. index--;
  111. }
  112.  
  113. uint16_t Option::get_value() {
  114. return index;
  115. }
  116.  
  117. char * Option::format_value() {
  118. return (char *)labels[index];
  119. }
  120.  
  121. uint8_t Option::on_deselected() {
  122. write_eeprom();
  123. return 1;
  124. }
  125. // vim:ft=arduino
  126.