can't push chnages :(

Fork of FBRDash by Michael Allan

Committer:
tomontoast
Date:
Sun Oct 14 21:09:49 2012 +0000
Revision:
5:177520d43c87
Parent:
1:b3907b8d9f65
14/10/12

Who changed what in which revision?

UserRevisionLine numberNew contents of line
intrinseca 1:b3907b8d9f65 1 #ifndef FBRDASH_MENU_H
intrinseca 1:b3907b8d9f65 2 #define FBRDASH_MENU_H
intrinseca 1:b3907b8d9f65 3
intrinseca 1:b3907b8d9f65 4 #include "TextLCD.h"
intrinseca 1:b3907b8d9f65 5 #include "PinDetect.h"
intrinseca 1:b3907b8d9f65 6 #include <string>
intrinseca 1:b3907b8d9f65 7
intrinseca 1:b3907b8d9f65 8 class MenuEntryBase
intrinseca 1:b3907b8d9f65 9 {
intrinseca 1:b3907b8d9f65 10 public:
intrinseca 1:b3907b8d9f65 11 bool editable;
intrinseca 1:b3907b8d9f65 12
intrinseca 1:b3907b8d9f65 13 string label;
intrinseca 1:b3907b8d9f65 14 string format;
intrinseca 1:b3907b8d9f65 15
intrinseca 1:b3907b8d9f65 16 virtual void increment() = 0;
intrinseca 1:b3907b8d9f65 17 virtual void decrement() = 0;
intrinseca 1:b3907b8d9f65 18 virtual string getFormatted() = 0;
intrinseca 1:b3907b8d9f65 19 };
intrinseca 1:b3907b8d9f65 20
intrinseca 1:b3907b8d9f65 21 template <typename T>
intrinseca 1:b3907b8d9f65 22 class MenuEntry : public MenuEntryBase
intrinseca 1:b3907b8d9f65 23 {
intrinseca 1:b3907b8d9f65 24 public:
intrinseca 1:b3907b8d9f65 25 T* value;
intrinseca 1:b3907b8d9f65 26 T step;
intrinseca 1:b3907b8d9f65 27
intrinseca 1:b3907b8d9f65 28 virtual void increment()
intrinseca 1:b3907b8d9f65 29 {
intrinseca 1:b3907b8d9f65 30 *value += step;
intrinseca 1:b3907b8d9f65 31 }
intrinseca 1:b3907b8d9f65 32
intrinseca 1:b3907b8d9f65 33 virtual void decrement()
intrinseca 1:b3907b8d9f65 34 {
intrinseca 1:b3907b8d9f65 35 *value -= step;
intrinseca 1:b3907b8d9f65 36 }
intrinseca 1:b3907b8d9f65 37
intrinseca 1:b3907b8d9f65 38 virtual string getFormatted()
intrinseca 1:b3907b8d9f65 39 {
intrinseca 1:b3907b8d9f65 40 char buffer[16];
intrinseca 1:b3907b8d9f65 41 sprintf(buffer, format.c_str(), *value);
intrinseca 1:b3907b8d9f65 42 return buffer;
intrinseca 1:b3907b8d9f65 43 }
intrinseca 1:b3907b8d9f65 44 };
intrinseca 1:b3907b8d9f65 45
intrinseca 1:b3907b8d9f65 46 class Menu
intrinseca 1:b3907b8d9f65 47 {
intrinseca 1:b3907b8d9f65 48 public:
intrinseca 1:b3907b8d9f65 49 bool display;
intrinseca 1:b3907b8d9f65 50 bool edit;
intrinseca 1:b3907b8d9f65 51
intrinseca 1:b3907b8d9f65 52 Menu(TextLCD* _screen, PinName ok, PinName left, PinName right);
intrinseca 1:b3907b8d9f65 53
intrinseca 1:b3907b8d9f65 54 template <typename T>
intrinseca 1:b3907b8d9f65 55 void addItem(string label, string format, T* value);
intrinseca 1:b3907b8d9f65 56
intrinseca 1:b3907b8d9f65 57 template <typename T>
intrinseca 1:b3907b8d9f65 58 void addEditableItem(string label, string format, T* value, T step);
intrinseca 1:b3907b8d9f65 59
intrinseca 1:b3907b8d9f65 60 void refresh();
intrinseca 1:b3907b8d9f65 61
intrinseca 1:b3907b8d9f65 62 void enter();
intrinseca 1:b3907b8d9f65 63 void done();
intrinseca 1:b3907b8d9f65 64 void left();
intrinseca 1:b3907b8d9f65 65 void right();
intrinseca 1:b3907b8d9f65 66
intrinseca 1:b3907b8d9f65 67 private:
intrinseca 1:b3907b8d9f65 68 MenuEntryBase* entries[20];
intrinseca 1:b3907b8d9f65 69 int entryCount;
intrinseca 1:b3907b8d9f65 70
intrinseca 1:b3907b8d9f65 71 PinDetect* btnOK;
intrinseca 1:b3907b8d9f65 72 PinDetect* btnLeft;
intrinseca 1:b3907b8d9f65 73 PinDetect* btnRight;
intrinseca 1:b3907b8d9f65 74
intrinseca 1:b3907b8d9f65 75 TextLCD* screen;
intrinseca 1:b3907b8d9f65 76
intrinseca 1:b3907b8d9f65 77 int position;
intrinseca 1:b3907b8d9f65 78 bool ignoreNextEnter;
intrinseca 1:b3907b8d9f65 79
intrinseca 1:b3907b8d9f65 80 Timeout leftHeldTimeout;
intrinseca 1:b3907b8d9f65 81 Timeout rightHeldTimeout;
intrinseca 1:b3907b8d9f65 82
intrinseca 1:b3907b8d9f65 83 void leftHeld();
intrinseca 1:b3907b8d9f65 84 void cancelLeftHeld();
intrinseca 1:b3907b8d9f65 85 void rightHeld();
intrinseca 1:b3907b8d9f65 86 void cancelRightHeld();
intrinseca 1:b3907b8d9f65 87
intrinseca 1:b3907b8d9f65 88 static const float holdRepeatTime = 0.15; //should be multiple of screen refresh rate or wierdness will ensue
intrinseca 1:b3907b8d9f65 89 static const char leftArrow = 0x7F;
intrinseca 1:b3907b8d9f65 90 static const char rightArrow = 0x7E;
intrinseca 1:b3907b8d9f65 91 };
intrinseca 1:b3907b8d9f65 92
intrinseca 1:b3907b8d9f65 93 template <typename T>
intrinseca 1:b3907b8d9f65 94 void Menu::addItem(string label, string format, T* value)
intrinseca 1:b3907b8d9f65 95 {
intrinseca 1:b3907b8d9f65 96 MenuEntry<T>* newEntry = new MenuEntry<T>();
intrinseca 1:b3907b8d9f65 97
intrinseca 1:b3907b8d9f65 98 newEntry->value = value;
intrinseca 1:b3907b8d9f65 99 newEntry->editable = false;
intrinseca 1:b3907b8d9f65 100
intrinseca 1:b3907b8d9f65 101 newEntry->label = label;
intrinseca 1:b3907b8d9f65 102 newEntry->format = format;
intrinseca 1:b3907b8d9f65 103
intrinseca 1:b3907b8d9f65 104 entries[entryCount] = newEntry;
intrinseca 1:b3907b8d9f65 105 entryCount++;
intrinseca 1:b3907b8d9f65 106 }
intrinseca 1:b3907b8d9f65 107
intrinseca 1:b3907b8d9f65 108 template <typename T>
intrinseca 1:b3907b8d9f65 109 void Menu::addEditableItem(string label, string format, T* value, T step)
intrinseca 1:b3907b8d9f65 110 {
intrinseca 1:b3907b8d9f65 111 MenuEntry<T> newEntry;
intrinseca 1:b3907b8d9f65 112
intrinseca 1:b3907b8d9f65 113 newEntry.value = value;
intrinseca 1:b3907b8d9f65 114 newEntry.editable = true;
intrinseca 1:b3907b8d9f65 115 newEntry.step = step;
intrinseca 1:b3907b8d9f65 116
intrinseca 1:b3907b8d9f65 117 newEntry.label = label;
intrinseca 1:b3907b8d9f65 118 newEntry.format = format;
intrinseca 1:b3907b8d9f65 119
intrinseca 1:b3907b8d9f65 120 entries[entryCount] = newEntry;
intrinseca 1:b3907b8d9f65 121 entryCount++;
intrinseca 1:b3907b8d9f65 122 }
intrinseca 1:b3907b8d9f65 123
intrinseca 1:b3907b8d9f65 124 #endif