98 lines
2.3 KiB
C++
98 lines
2.3 KiB
C++
/**
|
|
* @file menuIntInput.cpp
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2022-09-12
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
|
|
#include "menuIntInput.h"
|
|
|
|
MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper* wrapper) {
|
|
this->values = values;
|
|
this->names = names;
|
|
this->length = length;
|
|
this->wrapper = wrapper;
|
|
}
|
|
|
|
void MenuIntInput::down() {
|
|
if (values[currentPosition] > this->min)
|
|
values[currentPosition]--;
|
|
|
|
this->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::up() {
|
|
if (values[currentPosition] < this->max)
|
|
values[currentPosition]++;
|
|
|
|
this->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::right() {
|
|
if (currentPosition < this->length - 1)
|
|
currentPosition++;
|
|
else
|
|
currentPosition = 0;
|
|
|
|
this->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::left() {
|
|
if (currentPosition > 0)
|
|
currentPosition--;
|
|
else
|
|
currentPosition = this->length - 1;
|
|
|
|
this->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::no() {
|
|
if (parentMenu)
|
|
this->parentMenu->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::yes() {
|
|
this->wrapper->action(this->values, this->length);
|
|
if (parentMenu)
|
|
this->parentMenu->printMenu();
|
|
}
|
|
|
|
void MenuIntInput::printMenu() {
|
|
// TODO: Name max 12 chars
|
|
|
|
char bufferName[17];
|
|
if (this->currentPosition == 0 && this->length == 1) {
|
|
// No arrow
|
|
sprintf(bufferName, " %s ", this->names[this->currentPosition]);
|
|
} else if (this->currentPosition > 0 && this->length - 1 == this->currentPosition) {
|
|
// Left arrow only
|
|
sprintf(bufferName, "< %s ", this->names[this->currentPosition]);
|
|
} else if (this->currentPosition == 0 && this->length > 1) {
|
|
// Right arrow only
|
|
sprintf(bufferName, " %s >", this->names[this->currentPosition]);
|
|
} else {
|
|
// Both arrow
|
|
sprintf(bufferName, "< %s >", this->names[this->currentPosition]);
|
|
}
|
|
|
|
char bufferValue[17];
|
|
sprintf(bufferValue, " -> %5.d", this->values[this->currentPosition]);
|
|
|
|
|
|
if (this->lcd) {
|
|
lcd->clear();
|
|
lcd->setCursor(0, 0);
|
|
lcd->print(bufferName);
|
|
lcd->setCursor(0, 1);
|
|
lcd->print(bufferValue);
|
|
}
|
|
std::cout << bufferName << " : " << bufferValue << std::endl;
|
|
}
|
|
|
|
|
|
|