The codebase to run the *spark d-fuser controller www.sparkav.co.uk/dvimixer

Dependencies:   SPK-TVOne DMX DmxArtNet NetServicesMin OSC PinDetect mRotaryEncoder iniparser mbed spk_oled_ssd1305 filter

Committer:
tobyspark
Date:
Tue Oct 16 13:35:11 2012 +0000
Revision:
21:f9d63cb7cedb
Parent:
8:d46cc49f0f37
Child:
23:909928cafb95
Reading TVOne on startup, robustness fix to SPKMenu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 8:d46cc49f0f37 1 // *SPARK D-FUSER
tobyspark 8:d46cc49f0f37 2 // A project by Toby Harris
tobyspark 8:d46cc49f0f37 3 // Copyright *spark audio-visual 2012
tobyspark 8:d46cc49f0f37 4 //
tobyspark 8:d46cc49f0f37 5 // SPK_UTILS provides utility classes for the main SPK-DVIMXR codebase, most significantly the menu system.
tobyspark 8:d46cc49f0f37 6
tobyspark 0:87aab40d5806 7 #include <string>
tobyspark 0:87aab40d5806 8 #include <vector>
tobyspark 0:87aab40d5806 9
tobyspark 0:87aab40d5806 10 class SPKIndexInRange {
tobyspark 0:87aab40d5806 11 public:
tobyspark 0:87aab40d5806 12 void operator = (int newIndex) {
tobyspark 0:87aab40d5806 13 set(newIndex);
tobyspark 0:87aab40d5806 14 }
tobyspark 0:87aab40d5806 15
tobyspark 0:87aab40d5806 16 void operator ++ (int) {
tobyspark 0:87aab40d5806 17 if (idx == max) idx = wrap ? min : max;
tobyspark 0:87aab40d5806 18 else idx++;
tobyspark 0:87aab40d5806 19 }
tobyspark 0:87aab40d5806 20
tobyspark 0:87aab40d5806 21 void operator -- (int) {
tobyspark 0:87aab40d5806 22 if (idx == min) idx = wrap ? max : min;
tobyspark 0:87aab40d5806 23 else idx--;
tobyspark 0:87aab40d5806 24 }
tobyspark 0:87aab40d5806 25
tobyspark 0:87aab40d5806 26 void set (int newIndex) {
tobyspark 0:87aab40d5806 27 if (newIndex > max) idx = max;
tobyspark 0:87aab40d5806 28 else if (newIndex < min) idx = min;
tobyspark 0:87aab40d5806 29 else idx = newIndex;
tobyspark 0:87aab40d5806 30 }
tobyspark 0:87aab40d5806 31
tobyspark 0:87aab40d5806 32 void set (int newMin, int newMax, int newIndex = 0, bool newWrap = false) {
tobyspark 0:87aab40d5806 33 min = newMin;
tobyspark 0:87aab40d5806 34 max = newMax;
tobyspark 0:87aab40d5806 35 wrap = newWrap;
tobyspark 0:87aab40d5806 36 set(newIndex);
tobyspark 0:87aab40d5806 37 }
tobyspark 0:87aab40d5806 38
tobyspark 0:87aab40d5806 39 void setMax(int newMax) {
tobyspark 0:87aab40d5806 40 max = newMax;
tobyspark 0:87aab40d5806 41 }
tobyspark 0:87aab40d5806 42
tobyspark 0:87aab40d5806 43 SPKIndexInRange () {
tobyspark 0:87aab40d5806 44 min = 0;
tobyspark 0:87aab40d5806 45 max = 1;
tobyspark 0:87aab40d5806 46 wrap = true;
tobyspark 0:87aab40d5806 47 idx = 0;
tobyspark 0:87aab40d5806 48 }
tobyspark 0:87aab40d5806 49
tobyspark 0:87aab40d5806 50 SPKIndexInRange (int newMin, int newMax, int newIndex = 0, bool newWrap = false) {
tobyspark 0:87aab40d5806 51 set(newMin, newMax, newIndex, newWrap);
tobyspark 0:87aab40d5806 52 }
tobyspark 0:87aab40d5806 53
tobyspark 0:87aab40d5806 54 int index() {
tobyspark 0:87aab40d5806 55 return idx;
tobyspark 0:87aab40d5806 56 }
tobyspark 0:87aab40d5806 57
tobyspark 0:87aab40d5806 58 private:
tobyspark 0:87aab40d5806 59 int idx;
tobyspark 0:87aab40d5806 60 int min, max;
tobyspark 0:87aab40d5806 61 bool wrap;
tobyspark 0:87aab40d5806 62 };
tobyspark 0:87aab40d5806 63
tobyspark 0:87aab40d5806 64 class SPKMenu {
tobyspark 0:87aab40d5806 65 public:
tobyspark 0:87aab40d5806 66 SPKMenu() {
tobyspark 0:87aab40d5806 67 selected.set(0, 0, 0, true);
tobyspark 0:87aab40d5806 68 }
tobyspark 0:87aab40d5806 69
tobyspark 21:f9d63cb7cedb 70 enum menuType { menuOfMenus, payload };
tobyspark 21:f9d63cb7cedb 71
tobyspark 21:f9d63cb7cedb 72 virtual menuType type(void) = 0;
tobyspark 0:87aab40d5806 73
tobyspark 0:87aab40d5806 74 std::string title;
tobyspark 0:87aab40d5806 75
tobyspark 5:f8b285ca41ba 76 // not carried into subclass... whats the c++ way of doing this?
tobyspark 5:f8b285ca41ba 77 SPKMenu& operator = (const int &newIndex) {
tobyspark 0:87aab40d5806 78 selected = newIndex;
tobyspark 5:f8b285ca41ba 79 return *this;
tobyspark 0:87aab40d5806 80 }
tobyspark 0:87aab40d5806 81
tobyspark 0:87aab40d5806 82 void operator ++ () {
tobyspark 0:87aab40d5806 83 selected++;
tobyspark 0:87aab40d5806 84 }
tobyspark 0:87aab40d5806 85
tobyspark 0:87aab40d5806 86 void operator -- () {
tobyspark 0:87aab40d5806 87 selected--;
tobyspark 0:87aab40d5806 88 }
tobyspark 0:87aab40d5806 89
tobyspark 0:87aab40d5806 90 void addMenuItem (std::string menuText) {
tobyspark 0:87aab40d5806 91 text.push_back(menuText);
tobyspark 0:87aab40d5806 92 selected.setMax(text.size()-1);
tobyspark 0:87aab40d5806 93 }
tobyspark 0:87aab40d5806 94
tobyspark 0:87aab40d5806 95 int selectedIndex() {
tobyspark 0:87aab40d5806 96 return selected.index();
tobyspark 0:87aab40d5806 97 }
tobyspark 0:87aab40d5806 98
tobyspark 0:87aab40d5806 99 std::string selectedString() {
tobyspark 0:87aab40d5806 100 return text[selected.index()];
tobyspark 0:87aab40d5806 101 }
tobyspark 0:87aab40d5806 102
tobyspark 0:87aab40d5806 103 protected:
tobyspark 0:87aab40d5806 104 SPKIndexInRange selected;
tobyspark 0:87aab40d5806 105 std::vector<std::string> text;
tobyspark 0:87aab40d5806 106 };
tobyspark 0:87aab40d5806 107
tobyspark 0:87aab40d5806 108 class SPKMenuOfMenus: public SPKMenu {
tobyspark 0:87aab40d5806 109 public:
tobyspark 0:87aab40d5806 110 SPKMenuOfMenus() : SPKMenu() {}
tobyspark 0:87aab40d5806 111
tobyspark 21:f9d63cb7cedb 112 virtual menuType type() {
tobyspark 0:87aab40d5806 113 return menuOfMenus;
tobyspark 0:87aab40d5806 114 }
tobyspark 0:87aab40d5806 115
tobyspark 0:87aab40d5806 116 void addMenuItem(SPKMenu* menu) {
tobyspark 0:87aab40d5806 117 SPKMenu::addMenuItem(menu->title);
tobyspark 0:87aab40d5806 118 payload.push_back(menu);
tobyspark 0:87aab40d5806 119 }
tobyspark 0:87aab40d5806 120
tobyspark 0:87aab40d5806 121 SPKMenu* selectedMenu() {
tobyspark 0:87aab40d5806 122 return payload[selected.index()];
tobyspark 0:87aab40d5806 123 }
tobyspark 0:87aab40d5806 124
tobyspark 0:87aab40d5806 125 private:
tobyspark 0:87aab40d5806 126 vector<SPKMenu*> payload;
tobyspark 0:87aab40d5806 127 };
tobyspark 0:87aab40d5806 128
tobyspark 0:87aab40d5806 129 class SPKMenuPayload: public SPKMenu {
tobyspark 0:87aab40d5806 130 public:
tobyspark 0:87aab40d5806 131 SPKMenuPayload() : SPKMenu() {
tobyspark 0:87aab40d5806 132 text.push_back("Cancel");
tobyspark 0:87aab40d5806 133 payload1.push_back(0);
tobyspark 0:87aab40d5806 134 payload2.push_back(0);
tobyspark 0:87aab40d5806 135 }
tobyspark 0:87aab40d5806 136
tobyspark 21:f9d63cb7cedb 137 virtual menuType type() {
tobyspark 0:87aab40d5806 138 return payload;
tobyspark 0:87aab40d5806 139 }
tobyspark 0:87aab40d5806 140
tobyspark 0:87aab40d5806 141 void addMenuItem(std::string menuText, int32_t menuPayload1, int32_t menuPayload2) {
tobyspark 0:87aab40d5806 142 SPKMenu::addMenuItem(menuText);
tobyspark 0:87aab40d5806 143 payload1.push_back(menuPayload1);
tobyspark 0:87aab40d5806 144 payload2.push_back(menuPayload2);
tobyspark 0:87aab40d5806 145 }
tobyspark 0:87aab40d5806 146
tobyspark 0:87aab40d5806 147 int32_t selectedPayload1() {
tobyspark 0:87aab40d5806 148 return payload1[selected.index()];
tobyspark 0:87aab40d5806 149 }
tobyspark 0:87aab40d5806 150
tobyspark 0:87aab40d5806 151 int32_t selectedPayload2() {
tobyspark 0:87aab40d5806 152 return payload2[selected.index()];
tobyspark 0:87aab40d5806 153 }
tobyspark 5:f8b285ca41ba 154
tobyspark 5:f8b285ca41ba 155 SPKMenuPayload& operator = (const int &newIndex) {
tobyspark 5:f8b285ca41ba 156 selected = newIndex;
tobyspark 5:f8b285ca41ba 157 return *this;
tobyspark 5:f8b285ca41ba 158 }
tobyspark 5:f8b285ca41ba 159
tobyspark 5:f8b285ca41ba 160
tobyspark 0:87aab40d5806 161 private:
tobyspark 0:87aab40d5806 162 vector<int32_t> payload1;
tobyspark 0:87aab40d5806 163 vector<int32_t> payload2;
tobyspark 0:87aab40d5806 164 };
tobyspark 0:87aab40d5806 165
tobyspark 0:87aab40d5806 166 class SPKSign {
tobyspark 0:87aab40d5806 167 public:
tobyspark 0:87aab40d5806 168 SPKSign(PinName signWrite, PinName signError) {
tobyspark 0:87aab40d5806 169 writeDO = new DigitalOut(signWrite);
tobyspark 0:87aab40d5806 170 errorDO = new DigitalOut(signError);
tobyspark 0:87aab40d5806 171 }
tobyspark 0:87aab40d5806 172
tobyspark 0:87aab40d5806 173 ~SPKSign() {
tobyspark 0:87aab40d5806 174 delete writeDO;
tobyspark 0:87aab40d5806 175 delete errorDO;
tobyspark 0:87aab40d5806 176 }
tobyspark 0:87aab40d5806 177
tobyspark 0:87aab40d5806 178 void serialWrite() {
tobyspark 0:87aab40d5806 179 signWriteTimeout.detach();
tobyspark 0:87aab40d5806 180 signWriteTimeout.attach(this, &SPKSign::writeOff, 0.25);
tobyspark 0:87aab40d5806 181 *writeDO = 1;
tobyspark 0:87aab40d5806 182 }
tobyspark 0:87aab40d5806 183
tobyspark 0:87aab40d5806 184 void serialError() {
tobyspark 0:87aab40d5806 185 signErrorTimeout.detach();
tobyspark 0:87aab40d5806 186 signErrorTimeout.attach(this, &SPKSign::errorOff, 0.25);
tobyspark 0:87aab40d5806 187 *errorDO = 1;
tobyspark 0:87aab40d5806 188 }
tobyspark 0:87aab40d5806 189
tobyspark 0:87aab40d5806 190 private:
tobyspark 0:87aab40d5806 191 void writeOff() {
tobyspark 0:87aab40d5806 192 *writeDO = 0;
tobyspark 0:87aab40d5806 193 }
tobyspark 0:87aab40d5806 194
tobyspark 0:87aab40d5806 195 void errorOff() {
tobyspark 0:87aab40d5806 196 *errorDO = 0;
tobyspark 0:87aab40d5806 197 }
tobyspark 0:87aab40d5806 198
tobyspark 0:87aab40d5806 199 DigitalOut *writeDO;
tobyspark 0:87aab40d5806 200 DigitalOut *errorDO;
tobyspark 0:87aab40d5806 201 Timeout signWriteTimeout;
tobyspark 0:87aab40d5806 202 Timeout signErrorTimeout;
tobyspark 0:87aab40d5806 203 };
tobyspark 0:87aab40d5806 204
tobyspark 0:87aab40d5806 205
tobyspark 0:87aab40d5806 206