2022-12-13 11:14:45 +00:00
|
|
|
//
|
|
|
|
// Created by robtor on 09.12.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FLOATPUMP_MENU_H
|
|
|
|
#define FLOATPUMP_MENU_H
|
|
|
|
|
2023-01-04 12:22:45 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "Menu_Entry.h"
|
|
|
|
#include "LCD_I2C_Driver.h"
|
|
|
|
|
2022-12-13 11:14:45 +00:00
|
|
|
namespace floatpump {
|
|
|
|
namespace menu {
|
|
|
|
|
|
|
|
class Menu {
|
|
|
|
|
2023-01-04 12:22:45 +00:00
|
|
|
public:
|
|
|
|
Menu(LCD_I2C_Driver &driver) : m_driver(driver) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void addEntry(Menu_Entry entry) {
|
|
|
|
m_entries.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayMenu() {
|
|
|
|
int page = m_first_index / 4;
|
|
|
|
int pageindex = m_first_index % 4;
|
|
|
|
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
m_driver.LCDSetCursor(0,i);
|
|
|
|
|
|
|
|
if(pageindex == i) {
|
|
|
|
m_driver.LCDSendChar(LCD_I2C_Driver::SpecialChars::RightArrow);
|
|
|
|
} else {
|
|
|
|
m_driver.LCDSendCString(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_driver.LCDSetCursor(1,i);
|
|
|
|
int entry_index = (page * 4) + i;
|
2023-01-04 13:54:51 +00:00
|
|
|
if( m_entries.size() > entry_index ) {
|
2023-01-04 12:22:45 +00:00
|
|
|
std::string dspstring = m_entries[entry_index].printLine();
|
2023-01-04 13:54:51 +00:00
|
|
|
|
|
|
|
if(dspstring.length() > 19) {
|
|
|
|
m_driver.LCDSendCString("-------------------");
|
|
|
|
} else {
|
|
|
|
dspstring.append((19 - dspstring.length()), ' ');
|
|
|
|
m_driver.LCDSendCString(const_cast<char *>(dspstring.c_str()));
|
|
|
|
}
|
2023-01-04 12:22:45 +00:00
|
|
|
} else {
|
|
|
|
m_driver.LCDSendCString("-------------------");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void keypress() {
|
|
|
|
if(m_first_index < m_entries.size()) {
|
|
|
|
m_entries[m_first_index].action_press();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void increase() {
|
2023-01-04 13:54:51 +00:00
|
|
|
if(m_entries[m_first_index].isEntered()) {
|
|
|
|
m_entries[m_first_index].action_increase();
|
|
|
|
} else if(m_first_index < m_entries.size() - 1 && !m_entries[m_first_index].isEntered()) {
|
2023-01-04 12:22:45 +00:00
|
|
|
m_first_index++;
|
2023-01-04 13:54:51 +00:00
|
|
|
}
|
2023-01-04 12:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void decrease() {
|
2023-01-04 13:54:51 +00:00
|
|
|
if(m_entries[m_first_index].isEntered()) {
|
|
|
|
m_entries[m_first_index].action_decrease();
|
|
|
|
} else if(m_first_index > 0) {
|
2023-01-04 12:22:45 +00:00
|
|
|
m_first_index--;
|
2023-01-04 13:54:51 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 12:22:45 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
LCD_I2C_Driver &m_driver;
|
|
|
|
std::vector<Menu_Entry> m_entries;
|
|
|
|
|
|
|
|
int m_first_index = 0;
|
2022-12-13 11:14:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // floatpump
|
|
|
|
} // menu
|
|
|
|
|
|
|
|
#endif //FLOATPUMP_MENU_H
|