Download the file
  1. #ifndef ITEMS_H
  2. #define ITEMS_H
  3.  
  4. #include "formatter.h"
  5. #include "config_item.h"
  6. #include "screen.h"
  7.  
  8. class Count: public ConfigItem, public ConfigScreen {
  9. public:
  10. Count(uint16_t min_value, uint16_t max_value, uint16_t step,
  11. uint16_t default_value, const char * title, const char * unit,
  12. uint8_t format_width, Formatter * formatter):
  13. ConfigItem(2), // allocate 2 bytes in eeprom
  14. ConfigScreen(title, unit, format_width),
  15. min_value(min_value),
  16. max_value(max_value),
  17. step(step),
  18. value(default_value),
  19. formatter(formatter) { read_eeprom(); }
  20.  
  21. void next();
  22. void previous();
  23. uint8_t on_clockwise() { next(); refresh(); return 1; }
  24. uint8_t on_counter_clockwise() { previous(); refresh(); return 1; }
  25. uint16_t get_value();
  26. char * format_value();
  27.  
  28. protected:
  29. uint8_t on_deselected();
  30.  
  31. private:
  32. void read_eeprom();
  33. void write_eeprom();
  34.  
  35. uint16_t min_value;
  36. uint16_t max_value;
  37. uint16_t step;
  38. uint16_t value;
  39. Formatter * formatter;
  40. };
  41.  
  42. class Interval: public ConfigItem, public ConfigScreen {
  43. public:
  44. Interval(uint16_t * values, uint8_t nb_values, uint8_t default_index,
  45. const char * title, const char * unit, uint8_t format_width,
  46. Formatter * formatter):
  47. ConfigItem(1), // allocate 1 byte in eeprom
  48. ConfigScreen(title, unit, format_width),
  49. values(values),
  50. nb_values(nb_values),
  51. index(default_index),
  52. formatter(formatter) { read_eeprom(); }
  53.  
  54. void next();
  55. void previous();
  56. uint8_t on_clockwise() { next(); refresh(); return 1; }
  57. uint8_t on_counter_clockwise() { previous(); refresh(); return 1; }
  58. uint16_t get_value();
  59. char * format_value();
  60.  
  61. protected:
  62. uint8_t on_deselected();
  63.  
  64. private:
  65. void read_eeprom();
  66. void write_eeprom();
  67.  
  68. uint16_t * values;
  69. uint8_t nb_values;
  70. uint8_t offset;
  71. uint8_t index;
  72. Formatter * formatter;
  73. };
  74.  
  75. class Option: public ConfigItem, public ConfigScreen {
  76. public:
  77. Option(const char ** labels, uint8_t nb_values, uint8_t default_index, const char * title, uint8_t format_width):
  78. ConfigItem(1), // allocate 1 byte in eeprom
  79. ConfigScreen(title, "", format_width),
  80. labels(labels),
  81. nb_values(nb_values),
  82. index(default_index)
  83. { read_eeprom(); }
  84.  
  85. void next();
  86. void previous();
  87. uint8_t on_clockwise() { next(); refresh(); return 1; }
  88. uint8_t on_counter_clockwise() { previous(); refresh(); return 1; }
  89. uint16_t get_value();
  90. char * format_value();
  91.  
  92. protected:
  93. uint8_t on_deselected();
  94.  
  95. private:
  96. void read_eeprom();
  97. void write_eeprom();
  98.  
  99. const char ** labels;
  100. uint8_t nb_values;
  101. uint8_t offset;
  102. uint8_t index;
  103. };
  104. #endif
  105. // vim:ft=arduino
  106.