mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#pragma once
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "activities/ActivityWithSubactivity.h"
|
|
|
|
class CrossPointSettings;
|
|
|
|
enum class SettingType { TOGGLE, ENUM, ACTION, VALUE };
|
|
|
|
struct SettingInfo {
|
|
const char* name;
|
|
SettingType type;
|
|
uint8_t CrossPointSettings::* valuePtr;
|
|
std::vector<std::string> enumValues;
|
|
|
|
struct ValueRange {
|
|
uint8_t min;
|
|
uint8_t max;
|
|
uint8_t step;
|
|
};
|
|
ValueRange valueRange;
|
|
|
|
static SettingInfo Toggle(const char* name, uint8_t CrossPointSettings::* ptr) {
|
|
return {name, SettingType::TOGGLE, ptr};
|
|
}
|
|
|
|
static SettingInfo Enum(const char* name, uint8_t CrossPointSettings::* ptr, std::vector<std::string> values) {
|
|
return {name, SettingType::ENUM, ptr, std::move(values)};
|
|
}
|
|
|
|
static SettingInfo Action(const char* name) { return {name, SettingType::ACTION, nullptr}; }
|
|
|
|
static SettingInfo Value(const char* name, uint8_t CrossPointSettings::* ptr, const ValueRange valueRange) {
|
|
return {name, SettingType::VALUE, ptr, {}, valueRange};
|
|
}
|
|
};
|
|
|
|
class SettingsActivity final : public ActivityWithSubactivity {
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
bool updateRequired = false;
|
|
int selectedCategoryIndex = 0; // Currently selected category
|
|
int selectedSettingIndex = 0;
|
|
int settingsCount = 0;
|
|
const SettingInfo* settingsList = nullptr;
|
|
|
|
const std::function<void()> onGoHome;
|
|
|
|
static constexpr int categoryCount = 4;
|
|
static const char* categoryNames[categoryCount];
|
|
|
|
static void taskTrampoline(void* param);
|
|
[[noreturn]] void displayTaskLoop();
|
|
void render() const;
|
|
void enterCategory(int categoryIndex);
|
|
void toggleCurrentSetting();
|
|
|
|
public:
|
|
explicit SettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
const std::function<void()>& onGoHome)
|
|
: ActivityWithSubactivity("Settings", renderer, mappedInput), onGoHome(onGoHome) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
};
|