WIP
This commit is contained in:
parent
13fdacfcec
commit
1441fc49b4
@ -87,6 +87,7 @@ int main(void) {
|
||||
InitSequence initializer(display);
|
||||
initializer.runInitSequence();
|
||||
|
||||
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
|
||||
|
||||
using namespace floatpump::menu;
|
||||
Menu mainmenu(display);
|
||||
@ -112,8 +113,7 @@ int main(void) {
|
||||
while (1) {
|
||||
|
||||
|
||||
|
||||
mainmenu.displayMenu();
|
||||
mainmenu.updateMenu();
|
||||
if(rot_button) {
|
||||
rot_button = false;
|
||||
mainmenu.keypress();
|
||||
|
@ -89,6 +89,7 @@ void HardFault_Handler(void)
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define FLOATPUMP_MENU_H
|
||||
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
#include "Menu_Entry.h"
|
||||
#include "LCD_I2C_Driver.h"
|
||||
|
||||
@ -22,10 +23,9 @@ namespace floatpump {
|
||||
void addEntry(Menu_Entry entry) {
|
||||
m_entries.push_back(entry);
|
||||
}
|
||||
|
||||
void displayMenu() {
|
||||
int page = m_first_index / 4;
|
||||
int pageindex = m_first_index % 4;
|
||||
void updateMenu() {
|
||||
int page = m_current_index / 4;
|
||||
int pageindex = m_current_index % 4;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
m_driver.LCDSetCursor(0, i);
|
||||
@ -37,9 +37,16 @@ namespace floatpump {
|
||||
}
|
||||
|
||||
m_driver.LCDSetCursor(1, i);
|
||||
|
||||
int entry_index = (page * 4) + i;
|
||||
if( m_entries.size() > entry_index ) {
|
||||
std::string dspstring = m_entries[entry_index].printLine();
|
||||
//Display submenus first and then entries
|
||||
if (entry_index < m_submenus.size()) {
|
||||
std::string dspstring = "submenu";
|
||||
m_driver.LCDSendCString("submenu");
|
||||
//TODO: display submenu contentsnames
|
||||
//Display entries
|
||||
} else if (entry_index < (m_entries.size() + m_submenus.size())) {
|
||||
std::string dspstring = m_entries[entry_index - m_submenus.size()].printLine();
|
||||
|
||||
if (dspstring.length() > 19) {
|
||||
m_driver.LCDSendCString("-------------------");
|
||||
@ -47,40 +54,60 @@ namespace floatpump {
|
||||
dspstring.append((19 - dspstring.length()), ' ');
|
||||
m_driver.LCDSendCString(const_cast<char *>(dspstring.c_str()));
|
||||
}
|
||||
} else {
|
||||
m_driver.LCDSendCString("-------------------");
|
||||
} else { //Show separator at end of menu
|
||||
//TODO: make this look better
|
||||
m_driver.LCDSendCString("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keypress() {
|
||||
if(m_first_index < m_entries.size()) {
|
||||
m_entries[m_first_index].action_press();
|
||||
//enter submenu
|
||||
if (m_current_index < m_submenus.size()) {
|
||||
//forward press to entry
|
||||
} else if (m_current_index < (m_entries.size() + m_submenus.size())) {
|
||||
m_entries[m_current_index - m_submenus.size()].action_press();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void increase() {
|
||||
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()) {
|
||||
m_first_index++;
|
||||
//always increase
|
||||
if (m_current_index < m_submenus.size()) {
|
||||
m_current_index++;
|
||||
//increase when not in entry entered state
|
||||
} else if (m_current_index < (m_submenus.size() + m_entries.size())) {
|
||||
if (m_entries[m_current_index - m_submenus.size()].isEntered()) {
|
||||
m_entries[m_current_index - m_submenus.size()].action_increase();
|
||||
} else if (m_current_index < (m_submenus.size() + m_entries.size() - 1)) {
|
||||
m_current_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void decrease() {
|
||||
if(m_entries[m_first_index].isEntered()) {
|
||||
m_entries[m_first_index].action_decrease();
|
||||
} else if(m_first_index > 0) {
|
||||
m_first_index--;
|
||||
if (m_current_index > m_submenus.size()) {
|
||||
if (m_entries[m_current_index - m_submenus.size()].isEntered()) {
|
||||
m_entries[m_current_index - m_submenus.size()].action_decrease();
|
||||
} else {
|
||||
m_current_index--;
|
||||
}
|
||||
} else if (m_current_index > 0) {
|
||||
m_current_index--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void addSubmenu(Menu *submenu) {
|
||||
submenu->m_parent = this;
|
||||
m_submenus.push_back(submenu);
|
||||
}
|
||||
|
||||
private:
|
||||
LCD_I2C_Driver &m_driver;
|
||||
std::vector<Menu_Entry> m_entries;
|
||||
|
||||
int m_first_index = 0;
|
||||
std::vector<Menu *> m_submenus;
|
||||
Menu *m_parent = nullptr;
|
||||
int m_current_index = 0;
|
||||
};
|
||||
|
||||
} // floatpump
|
||||
|
23
Middlewares/floatpump/Inc/Menu_Controller.h
Normal file
23
Middlewares/floatpump/Inc/Menu_Controller.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#ifndef FLOATPUMP_MENU_CONTROLLER_H
|
||||
#define FLOATPUMP_MENU_CONTROLLER_H
|
||||
|
||||
#include "Menu.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
||||
class Menu_Controller {
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // floatpump
|
||||
} // menu
|
||||
|
||||
#endif //FLOATPUMP_MENU_CONTROLLER_H
|
10
Middlewares/floatpump/Src/Menu_Controller.cpp
Normal file
10
Middlewares/floatpump/Src/Menu_Controller.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#include "Menu_Controller.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
} // floatpump
|
||||
} // menu
|
Loading…
Reference in New Issue
Block a user