]> git.0d.be Git - PanikSwitch.git/blob - PanikSwitch.h
update to use local copy of library
[PanikSwitch.git] / PanikSwitch.h
1 /*
2     Definition of new types for Switch Kontrol
3 */
4
5 #include "avr/pgmspace.h"  // Needed for PROGMEM stuff
6
7
8 /* declaration of relay postions
9 */
10 typedef enum { RELAY_STATE_OPEN, RELAY_STATE_CLOSED } relayState_t;
11
12
13 /* declaration of possible state selections for the switch (new enum type)
14 */
15 typedef enum { nonstop, studio1, studio2, _NbrSwitchSelections } switchSelection_t;
16
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)
24    etc.
25 */
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
30     );
31 }
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
36     );
37 }
38 // `++` operator in `++selection`
39 switchSelection_t &operator++(switchSelection_t &s) {
40   s = static_cast<switchSelection_t>((s + 1) % _NbrSwitchSelections);
41   return s;
42 }
43 // `++` operator in `selection++`
44 switchSelection_t operator++(switchSelection_t &s, int) {
45   return static_cast<switchSelection_t>(++s - 1);
46 }
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
51     );
52   return lhs;
53 }
54
55
56 /* store switch state labels as an array in program memory
57    see http://arduino.cc/en/Reference/PROGMEM
58 */
59 prog_char label_nonstop[] PROGMEM = "Non-Stop";
60 prog_char label_studio1[] PROGMEM = "Studio 1";
61 prog_char label_studio2[] PROGMEM = "Studio 2";
62
63 PROGMEM const char *selection_labels[] = {
64   label_nonstop, label_studio1, label_studio2
65 };
66