Thomas Milburn
/
FBRDash-tom
can't push chnages :(
Fork of FBRDash by
src/Menu.cpp
- Committer:
- intrinseca
- Date:
- 2012-06-25
- Revision:
- 1:b3907b8d9f65
- Child:
- 2:825f572902c6
File content as of revision 1:b3907b8d9f65:
#include "Menu.h" #include "mbed.h" #include <string> Menu::Menu(TextLCD* _screen, PinName ok, PinName left, PinName right) { screen = _screen; entryCount = 0; position = 0; btnOK = new PinDetect(ok, PullUp); btnLeft = new PinDetect(left, PullUp); btnRight = new PinDetect(right, PullUp); btnOK->attach_deasserted(this, &Menu::enter); btnOK->attach_asserted_held(this, &Menu::done); btnLeft->attach_asserted(this, &Menu::left); btnLeft->attach_asserted_held(this, &Menu::leftHeld); btnLeft->attach_deasserted(this, &Menu::cancelLeftHeld); btnRight->attach_asserted(this, &Menu::right); btnRight->attach_asserted_held(this, &Menu::rightHeld); btnRight->attach_deasserted(this, &Menu::cancelRightHeld); btnOK->setAssertValue(0); btnLeft->setAssertValue(0); btnRight->setAssertValue(0); btnOK->setSampleFrequency(); btnLeft->setSampleFrequency(); btnRight->setSampleFrequency(); ignoreNextEnter = false; } void Menu::refresh() { char labelLeft = (!edit & position > 0)?leftArrow:' '; char labelRight = (!edit & position < entryCount)?rightArrow:' '; char editIndic = (entries[position]->editable)?'*':' '; screen->locate(0, 0); if(position <= entryCount - 1) { screen->printf("%c%-14s%c", labelLeft, (entries[position])->label.c_str(), labelRight); char editLeft = (edit)?'-':editIndic; char editRight = (edit)?'+':' '; screen->putc(editLeft); screen->printf(entries[position]->getFormatted().c_str()); screen->locate(15, 1); screen->putc(editRight); } else { screen->printf("%cReturn ", leftArrow); } } void Menu::enter() { if(!display && !ignoreNextEnter) { display = true; edit = false; } else { if(position <= entryCount - 1) { if(entries[position]->editable) edit = !edit; } else { position = 0; done(); } } ignoreNextEnter = false; } void Menu::done() { display = false; ignoreNextEnter = true; } void Menu::left() { if(!edit && display && position > 0) position--; else if(edit) entries[position]->decrement(); } void Menu::leftHeld() { left(); leftHeldTimeout.attach(this, &Menu::leftHeld, holdRepeatTime); } void Menu::cancelLeftHeld() { leftHeldTimeout.detach(); } void Menu::right() { if(!edit && display && position < entryCount) position++; else if(edit) entries[position]->increment(); } void Menu::rightHeld() { right(); rightHeldTimeout.attach(this, &Menu::rightHeld, holdRepeatTime); } void Menu::cancelRightHeld() { rightHeldTimeout.detach(); }