111 lines
2.6 KiB
C
Raw 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 <stddef.h>
#include <string>
#include <vector>
namespace Doncon::Utils {
class Menu {
public:
enum class Page {
Main,
DeviceMode,
TriggerThreshold,
TriggerThresholdKaLeft,
TriggerThresholdDonLeft,
TriggerThresholdDonRight,
TriggerThresholdKaRight,
DebounceDelay,
2023-07-06 20:55:26 +02:00
LedBrightness,
2023-07-17 00:08:24 +02:00
Reset,
2023-07-06 20:55:26 +02:00
Bootsel,
BootselMsg,
};
struct State {
Page page;
uint16_t selection;
2023-07-06 20:55:26 +02:00
};
struct Descriptor {
enum class Type {
Root,
Selection,
Value,
RebootInfo,
};
enum class Action {
None,
2023-07-17 00:08:24 +02:00
GotoParent,
2023-07-06 20:55:26 +02:00
GotoPageDeviceMode,
GotoPageTriggerThreshold,
GotoPageTriggerThresholdKaLeft,
GotoPageTriggerThresholdDonLeft,
GotoPageTriggerThresholdDonRight,
GotoPageTriggerThresholdKaRight,
GotoPageDebounceDelay,
2023-07-06 20:55:26 +02:00
GotoPageLedBrightness,
2023-07-17 00:08:24 +02:00
GotoPageReset,
2023-07-06 20:55:26 +02:00
GotoPageBootsel,
ChangeUsbModeSwitchTatacon,
ChangeUsbModeSwitchHoripad,
ChangeUsbModeDS3,
ChangeUsbModePS4Tatacon,
ChangeUsbModeDS4,
2023-12-03 11:27:19 +01:00
ChangeUsbModeKeyboard,
2023-07-06 20:55:26 +02:00
ChangeUsbModeXbox360,
2023-07-17 22:50:27 +02:00
ChangeUsbModeMidi,
2023-07-06 20:55:26 +02:00
ChangeUsbModeDebug,
SetTriggerThresholdKaLeft,
SetTriggerThresholdDonLeft,
SetTriggerThresholdDonRight,
SetTriggerThresholdKaRight,
SetDebounceDelay,
2023-07-06 20:55:26 +02:00
SetLedBrightness,
DoRebootToBootsel,
2023-07-17 00:08:24 +02:00
DoReset,
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 getCurrentSelection(Page page);
2023-07-06 20:55:26 +02:00
void gotoPage(Page page);
2023-11-05 21:59:56 +01:00
void gotoParent();
2023-07-06 20:55:26 +02:00
void performSelectionAction(Descriptor::Action action);
void performValueAction(Descriptor::Action action, uint16_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_