#include "MenuItem.h" #include "Arduino.h" // **** class and method definitions **** MenuItem::MenuItem() { } // **** overall MenuItem **** MenuItem::MenuItem(const char* name) { MenuItem::name = name; MenuItem::parent = NULL; MenuItem::next = NULL; } // links to the defined 'parent' menu item MenuItem* MenuItem::goBack() { return MenuItem::parent; } // links to the defined 'next' menu item MenuItem* MenuItem::goDown() { return MenuItem::next; } // no default behaviour MenuItem* MenuItem::goRight() { return NULL; } // left empty for the default menu item as it doesn't apply here void MenuItem::selectLeft() { } void MenuItem::selectRight() { } bool MenuItem::select() { // returns wether it makes sense to 'select' this item return false; } // spits out the name and nothing else String MenuItem::display() { return MenuItem::name; } // **** BranchMenuItem **** // points to a set of menu items higher in th etree BranchMenuItem::BranchMenuItem(const char* name, const MenuItem* child) { BranchMenuItem::name = name; BranchMenuItem::child = child; } // the goRight() function points towards a child menu item MenuItem* BranchMenuItem::goRight() { return BranchMenuItem::child; } String BranchMenuItem::display() { return String(BranchMenuItem::name) + " ->"; } // **** IntValueItem **** // contains an integer, whose value can be edited by the user IntValueItem::IntValueItem(char const* name, int initial, int min, int max) { IntValueItem::name = name; IntValueItem::value = initial; IntValueItem::min = min; IntValueItem::max = max; } // selectLeft() and selectRight() - decrease or increase the value of the integer by 1, respectively void IntValueItem::selectRight() { if (IntValueItem::value < IntValueItem::max){ IntValueItem::value++; } } void IntValueItem::selectLeft() { if (IntValueItem::value > IntValueItem::min){ IntValueItem::value--; } } // display() - outputs the name and current value of the integer on separate lines. String IntValueItem::display() { return String(IntValueItem::name) + "\n" + String(IntValueItem::value); } // indicates that it's possible to select this item bool IntValueItem::select() { return true; } // **** BoolValueItem **** // contains a boolean, whose value can be edited by the user BoolValueItem::BoolValueItem(char const* name, bool initial) { BoolValueItem::name = name; BoolValueItem::value = initial; } // both selectRight() and selectLeft() invert the current value of the item void BoolValueItem::selectRight() { BoolValueItem::value = !BoolValueItem::value; } void BoolValueItem::selectLeft() { BoolValueItem::value = !BoolValueItem::value; } // display() - outputs the name and current value of the boolean on separate lines. String BoolValueItem::display() { return String(BoolValueItem::name) + "\n" + (BoolValueItem::value ? "true" : "false"); } // indicates that it's possible to select this item bool BoolValueItem::select() { return true; }