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,
|
2024-11-04 23:09:47 +01:00
|
|
|
|
2023-07-06 20:55:26 +02:00
|
|
|
DeviceMode,
|
2024-11-04 23:09:47 +01:00
|
|
|
Drum,
|
|
|
|
Led,
|
2023-07-17 00:08:24 +02:00
|
|
|
Reset,
|
2023-07-06 20:55:26 +02:00
|
|
|
Bootsel,
|
2024-11-04 23:09:47 +01:00
|
|
|
|
|
|
|
DrumDebounceDelay,
|
|
|
|
DrumTriggerThresholdKaLeft,
|
|
|
|
DrumTriggerThresholdDonLeft,
|
|
|
|
DrumTriggerThresholdDonRight,
|
|
|
|
DrumTriggerThresholdKaRight,
|
|
|
|
|
|
|
|
LedBrightness,
|
|
|
|
LedEnablePlayerColor,
|
|
|
|
|
2023-07-06 20:55:26 +02:00
|
|
|
BootselMsg,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
Page page;
|
2024-11-04 23:09:47 +01:00
|
|
|
uint16_t selected_value;
|
|
|
|
uint16_t original_value;
|
2023-07-06 20:55:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Descriptor {
|
|
|
|
enum class Type {
|
2024-11-04 23:09:47 +01:00
|
|
|
Menu,
|
2023-07-06 20:55:26 +02:00
|
|
|
Selection,
|
|
|
|
Value,
|
2024-11-04 23:09:47 +01:00
|
|
|
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,
|
2024-11-04 23:09:47 +01:00
|
|
|
GotoPageDrum,
|
|
|
|
GotoPageLed,
|
2023-07-17 00:08:24 +02:00
|
|
|
GotoPageReset,
|
2023-07-06 20:55:26 +02:00
|
|
|
GotoPageBootsel,
|
|
|
|
|
2024-11-04 23:09:47 +01:00
|
|
|
GotoPageDrumDebounceDelay,
|
|
|
|
GotoPageDrumTriggerThresholdKaLeft,
|
|
|
|
GotoPageDrumTriggerThresholdDonLeft,
|
|
|
|
GotoPageDrumTriggerThresholdDonRight,
|
|
|
|
GotoPageDrumTriggerThresholdKaRight,
|
|
|
|
|
|
|
|
GotoPageLedBrightness,
|
|
|
|
GotoPageLedEnablePlayerColor,
|
|
|
|
|
|
|
|
SetUsbMode,
|
|
|
|
|
|
|
|
SetDrumDebounceDelay,
|
|
|
|
SetDrumTriggerThresholdKaLeft,
|
|
|
|
SetDrumTriggerThresholdDonLeft,
|
|
|
|
SetDrumTriggerThresholdDonRight,
|
|
|
|
SetDrumTriggerThresholdKaRight,
|
|
|
|
|
2023-07-06 20:55:26 +02:00
|
|
|
SetLedBrightness,
|
2024-11-04 23:09:47 +01:00
|
|
|
SetLedEnablePlayerColor,
|
2023-07-06 20:55:26 +02:00
|
|
|
|
2023-07-17 00:08:24 +02:00
|
|
|
DoReset,
|
2024-11-04 23:09:47 +01:00
|
|
|
DoRebootToBootsel,
|
2023-07-06 20:55:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::pair<std::string, Action>> items;
|
2023-07-16 23:34:47 +02:00
|
|
|
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
|
|
|
|
2024-11-04 23:09:47 +01:00
|
|
|
uint16_t getCurrentValue(Page page);
|
2023-07-06 20:55:26 +02:00
|
|
|
void gotoPage(Page page);
|
2024-11-04 23:09:47 +01:00
|
|
|
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_
|