DonCon2040/include/utils/Menu.h

116 lines
2.5 KiB
C
Raw Permalink Normal View History

2023-07-06 20:55:26 +02:00
#ifndef _UTILS_MENU_H_
#define _UTILS_MENU_H_
#include "utils/InputState.h"
#include "utils/SettingsStore.h"
#include <map>
#include <memory>
2023-11-05 21:59:56 +01:00
#include <stack>
2023-07-06 20:55:26 +02:00
#include <string>
#include <vector>
namespace Doncon::Utils {
class Menu {
public:
enum class Page {
Main,
2023-07-06 20:55:26 +02:00
DeviceMode,
Drum,
Led,
2023-07-17 00:08:24 +02:00
Reset,
2023-07-06 20:55:26 +02:00
Bootsel,
DrumDebounceDelay,
DrumTriggerThresholdKaLeft,
DrumTriggerThresholdDonLeft,
DrumTriggerThresholdDonRight,
DrumTriggerThresholdKaRight,
LedBrightness,
LedEnablePlayerColor,
2023-07-06 20:55:26 +02:00
BootselMsg,
};
struct State {
Page page;
uint16_t selected_value;
uint16_t original_value;
2023-07-06 20:55:26 +02:00
};
struct Descriptor {
enum class Type {
Menu,
2023-07-06 20:55:26 +02:00
Selection,
Value,
Toggle,
2023-07-06 20:55:26 +02:00
RebootInfo,
};
enum class Action {
None,
2023-07-17 00:08:24 +02:00
GotoParent,
2023-07-06 20:55:26 +02:00
GotoPageDeviceMode,
GotoPageDrum,
GotoPageLed,
2023-07-17 00:08:24 +02:00
GotoPageReset,
2023-07-06 20:55:26 +02:00
GotoPageBootsel,
GotoPageDrumDebounceDelay,
GotoPageDrumTriggerThresholdKaLeft,
GotoPageDrumTriggerThresholdDonLeft,
GotoPageDrumTriggerThresholdDonRight,
GotoPageDrumTriggerThresholdKaRight,
GotoPageLedBrightness,
GotoPageLedEnablePlayerColor,
SetUsbMode,
SetDrumDebounceDelay,
SetDrumTriggerThresholdKaLeft,
SetDrumTriggerThresholdDonLeft,
SetDrumTriggerThresholdDonRight,
SetDrumTriggerThresholdKaRight,
2023-07-06 20:55:26 +02:00
SetLedBrightness,
SetLedEnablePlayerColor,
2023-07-06 20:55:26 +02:00
2023-07-17 00:08:24 +02:00
DoReset,
DoRebootToBootsel,
2023-07-06 20:55:26 +02:00
};
Type type;
std::string name;
std::vector<std::pair<std::string, Action>> items;
uint16_t max_value;
2023-07-06 20:55:26 +02:00
};
const static std::map<Page, const Descriptor> descriptors;
private:
std::shared_ptr<SettingsStore> m_store;
bool m_active;
2023-11-05 21:59:56 +01:00
std::stack<State> m_state_stack;
2023-07-06 20:55:26 +02:00
uint16_t getCurrentValue(Page page);
2023-07-06 20:55:26 +02:00
void gotoPage(Page page);
void gotoParent(bool do_restore);
void performAction(Descriptor::Action action, uint8_t value);
2023-07-06 20:55:26 +02:00
public:
Menu(std::shared_ptr<SettingsStore> settings_store);
void activate();
void update(const InputState::Controller &controller_state);
bool active();
State getState();
};
2023-07-16 21:33:12 +02:00
} // namespace Doncon::Utils
2023-07-06 20:55:26 +02:00
#endif // _UTILS_MENU_H_