66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <expected>
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
#include <boost/asio/any_io_executor.hpp>
|
|
#include <boost/asio/steady_timer.hpp>
|
|
|
|
#include <luma.hpp>
|
|
#include <modulus.hpp>
|
|
|
|
#include <vamp_protocol/page_control.hpp>
|
|
#include <vamp_zero/config.hpp>
|
|
#include <vamp_zero/types.hpp>
|
|
|
|
namespace vamp_zero {
|
|
|
|
struct score_draw_cache;
|
|
|
|
struct ui_state {
|
|
vamp_zero::app_state app{};
|
|
std::string ap_ssid{};
|
|
std::string zero_ip{};
|
|
std::uint16_t port{8080};
|
|
};
|
|
|
|
class zero_ui {
|
|
public:
|
|
using command_handler = std::function<void(vamp_protocol::page_command)>;
|
|
|
|
zero_ui(boost::asio::any_io_executor executor, luma::application_config config, command_handler command_handler = {});
|
|
auto run() -> std::expected<void, modulus::error>;
|
|
auto stop() -> void;
|
|
auto publish(vamp_zero::ui_state state) -> std::expected<void, modulus::error>;
|
|
auto snapshot() const -> vamp_zero::ui_state;
|
|
private:
|
|
auto handle_touch(luma::touch_event const& event) -> std::bool_t;
|
|
auto send_touch_command(vamp_protocol::page_command command) -> void;
|
|
auto arm_pending_tap() -> void;
|
|
auto cancel_pending_tap_locked() -> void;
|
|
auto make_root(vamp_zero::ui_state const& state) -> std::expected<std::unique_ptr<luma::control>, modulus::error>;
|
|
boost::asio::any_io_executor executor_;
|
|
boost::asio::steady_timer tap_timer_;
|
|
luma::application application_;
|
|
command_handler command_handler_{};
|
|
std::shared_ptr<vamp_zero::score_draw_cache> score_cache_{};
|
|
mutable std::mutex mutex_{};
|
|
vamp_zero::ui_state state_{};
|
|
mutable std::mutex touch_mutex_{};
|
|
std::optional<std::int32_t> active_touch_id_{};
|
|
std::chrono::steady_clock::time_point touch_down_time_{};
|
|
std::chrono::steady_clock::time_point last_tap_time_{};
|
|
std::bool_t hold_sent_{};
|
|
std::bool_t pending_tap_{};
|
|
};
|
|
|
|
auto make_ui_state(vamp_zero::config const& config, vamp_zero::app_state app) -> vamp_zero::ui_state;
|
|
|
|
}
|