2 Definition of new types for Switch Kontrol
5 #include "avr/pgmspace.h" // Needed for PROGMEM stuff
8 /* declaration of relay postions
10 typedef enum { RELAY_STATE_OPEN, RELAY_STATE_CLOSED } relayState_t;
13 /* declaration of possible state selections for the switch (new enum type)
15 typedef enum { nonstop, studio1, studio2, _NbrSwitchSelections } switchSelection_t;
17 /* explicit conversions from int to switchSelection_t for +, ++, and += operators
18 this makes possible to increment values of type switchSelection_t like this:
19 switchSelection_t selection = studio1; // variable declaration & initialization
20 selection = selection + 1; // => selection is studio2 (one way to do it)
21 selection += 1; // => selection is nonstop (that works, too)
22 selection++; // => selection is studio1 (other way)
23 ++selection; // => selection is studio2 (yet another way)
26 // `+` operator in `selection = selection + i`
27 switchSelection_t operator+(switchSelection_t lhs, int rhs) {
28 return static_cast<switchSelection_t>(
29 (static_cast<int>(lhs) + rhs) % _NbrSwitchSelections
32 // `+` operator in `selection = i + selection`
33 switchSelection_t operator+(int lhs, switchSelection_t rhs) {
34 return static_cast<switchSelection_t>(
35 (lhs + static_cast<int>(rhs)) % _NbrSwitchSelections
38 // `++` operator in `++selection`
39 switchSelection_t &operator++(switchSelection_t &s) {
40 s = static_cast<switchSelection_t>((s + 1) % _NbrSwitchSelections);
43 // `++` operator in `selection++`
44 switchSelection_t operator++(switchSelection_t &s, int) {
45 return static_cast<switchSelection_t>(++s - 1);
47 // `+=` operator in `selection += i`
48 switchSelection_t operator+=(switchSelection_t &lhs, int rhs) {
49 lhs = static_cast<switchSelection_t>(
50 (static_cast<int>(lhs) + rhs) % _NbrSwitchSelections
56 /* store switch state labels as an array in program memory
57 see http://arduino.cc/en/Reference/PROGMEM
59 prog_char label_nonstop[] PROGMEM = "Non-Stop";
60 prog_char label_studio1[] PROGMEM = "Studio 1";
61 prog_char label_studio2[] PROGMEM = "Studio 2";
63 PROGMEM const char *selection_labels[] = {
64 label_nonstop, label_studio1, label_studio2