Prusa-Firmware/Firmware/MenuStack.cpp
Marek Bel 235803bc2a Move encoder stack to separate class MenuStack. Add menu record to MenuStack.
It was needed to add menuFunc_t menu to stack, as in some places in menu, it is impossible to hardcode parent menu. Example: lcd_babystep_z can be invoked both from main_menu() and settings_menu() depending on printer status.
2018-03-06 19:47:27 +01:00

30 lines
589 B
C++

/**
* @file
* @author Marek Bel
*/
#include "MenuStack.h"
/**
* @brief Push menu on stack
* @param menu
* @param position selected position in menu being pushed
*/
void MenuStack::push(menuFunc_t menu, uint8_t position)
{
if (m_index >= max_depth) return;
m_stack[m_index].menu = menu;
m_stack[m_index].position = position;
++m_index;
}
/**
* @brief Pop menu from stack
* @return Record containing menu function pointer and previously selected line number
*/
MenuStack::Record MenuStack::pop()
{
if (m_index != 0) m_index--;
return m_stack[m_index];
}