Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Web console (GitHub Pages)

# The Emulator Console (web/): the page the firmware advertises as its WebUSB
# landing page (esp-cpp.github.io/<repo>/). Needs Settings -> Pages -> Source:
# GitHub Actions.
# The Emulator Console (web/, from the emulink submodule): the page the
# firmware advertises as its WebUSB landing page (esp-cpp.github.io/<repo>/).
# Needs Settings -> Pages -> Source: GitHub Actions.
on:
push:
branches: [main]
paths:
- 'web/**'
- 'components/emulink'
- '.github/workflows/pages.yml'
workflow_dispatch:

Expand All @@ -28,11 +28,13 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: The emulink submodule (only it)
run: git submodule update --init components/emulink
- name: Check the scripts parse
run: for f in web/*.js; do node --check "$f"; done
run: for f in components/emulink/web/*.js; do node --check "$f"; done
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: web
path: components/emulink/web
- id: deployment
uses: actions/deploy-pages@v4
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@
path = components/darkforces/TheForceEngine
url = https://github.com/esp-cpp/TheForceEngine.git
branch = main
[submodule "components/emulink"]
path = components/emulink
url = https://github.com/esp-cpp/emulink.git
branch = main
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ set(EMULATOR_COMPONENTS

set(
COMPONENTS
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor timer ${EMULATOR_COMPONENTS} box-emu gui menu settings devlink"
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor timer ${EMULATOR_COMPONENTS} box-emu gui menu settings emulink"
CACHE STRING
"List of components to include"
FORCE
Expand Down
26 changes: 26 additions & 0 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ class BoxEmu : public espp::BaseComponent {
/// Buttons held by the USB link's test control (scripted input), merged
/// into gamepad_state() like any other input (GamepadState::buttons bits).
void set_remote_buttons(uint16_t buttons);
/// A finger held by the USB link's test control (emulink tap / touch /
/// drag), in LCD pixels; fingers = 0 lifts it. It counts as a touch for
/// touch_pointer() and the LVGL menus.
void set_remote_touch(uint8_t fingers, uint16_t x, uint16_t y);
/// A finger used as a pointer (LCD pixels); fingers = 0: none
struct TouchPoint {
uint8_t fingers{0}; ///< fingers on the screen
int x{0};
int y{0};
};
/// The finger on the touch screen (or held by the link's test control).
/// `skip_gamepad` is for boards with a touch virtual gamepad (tab5-emu);
/// the box has none.
TouchPoint touch_pointer(bool skip_gamepad = false) const;
/// The touch virtual gamepad's buttons: none on the box (tab5-emu has one)
GamepadState touch_gamepad_state() const { return {}; }
/// A point on the screen in the running game's frame (width x height),
/// which is drawn at display_size, centered; clamped to the frame
std::pair<int, int> screen_to_frame(int x, int y, int width, int height) const;
/// And back: a point of the running game's frame (width x height) on the
/// screen (the middle of its pixel)
std::pair<int, int> frame_to_screen(int x, int y, int width, int height) const;

protected:
BoxEmu();
Expand Down Expand Up @@ -468,6 +490,10 @@ class BoxEmu : public espp::BaseComponent {
std::function<void(std::span<const uint8_t>)> vendor_rx_;
std::mutex vendor_tx_mutex_;
uint16_t remote_buttons_{0}; // guarded by gamepad_state_mutex_
static void remote_pointer_read(lv_indev_t *indev, lv_indev_data_t *data);
mutable std::mutex remote_touch_mutex_;
TouchPoint remote_touch_{};
lv_indev_t *remote_pointer_indev_{nullptr};
// The USB-Serial-JTAG console PHY, re-created after USB mass storage is stopped
// so the console comes back (the OTG stack owns the PHY while it runs).
usb_phy_handle_t jtag_phy_{nullptr};
Expand Down
57 changes: 57 additions & 0 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ bool BoxEmu::initialize_gamepad() {
.log_level = espp::Logger::Verbosity::WARN
});

// the USB link's test control's finger (emulink tap / touch / drag)
remote_pointer_indev_ = lv_indev_create();
if (remote_pointer_indev_) {
lv_indev_set_type(remote_pointer_indev_, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(remote_pointer_indev_, &BoxEmu::remote_pointer_read);
lv_indev_set_user_data(remote_pointer_indev_, this);
}

// now initialize the input timer
input_timer_ = std::make_shared<espp::HighResolutionTimer>(espp::HighResolutionTimer::Config{
.name = "Input timer",
Expand All @@ -312,6 +320,55 @@ void BoxEmu::set_remote_buttons(uint16_t buttons) {
remote_buttons_ = buttons;
}

void BoxEmu::set_remote_touch(uint8_t fingers, uint16_t x, uint16_t y) {
std::lock_guard<std::mutex> lock(remote_touch_mutex_);
remote_touch_ = {fingers, std::min<int>(x, lcd_width() - 1), std::min<int>(y, lcd_height() - 1)};
}

BoxEmu::TouchPoint BoxEmu::touch_pointer(bool) const {
{
std::lock_guard<std::mutex> lock(remote_touch_mutex_);
if (remote_touch_.fingers > 0) {
return remote_touch_;
}
}
auto &bsp = Bsp::get();
const auto data = bsp.touchpad_convert(bsp.touchpad_data());
if (data.num_touch_points == 0) {
return {};
}
return {data.num_touch_points, data.x, data.y};
}

std::pair<int, int> BoxEmu::screen_to_frame(int x, int y, int width, int height) const {
const int dw = std::max<int>(1, display_width_), dh = std::max<int>(1, display_height_);
const int ox = (static_cast<int>(lcd_width()) - dw) / 2, oy = (static_cast<int>(lcd_height()) - dh) / 2;
return {std::clamp((x - ox) * width / dw, 0, width - 1), std::clamp((y - oy) * height / dh, 0, height - 1)};
}

std::pair<int, int> BoxEmu::frame_to_screen(int x, int y, int width, int height) const {
const int dw = std::max<int>(1, display_width_), dh = std::max<int>(1, display_height_);
const int ox = (static_cast<int>(lcd_width()) - dw) / 2, oy = (static_cast<int>(lcd_height()) - dh) / 2;
width = std::max(1, width);
height = std::max(1, height);
return {ox + (2 * x + 1) * dw / (2 * width), oy + (2 * y + 1) * dh / (2 * height)};
}

void BoxEmu::remote_pointer_read(lv_indev_t *indev, lv_indev_data_t *data) {
// the link's test control's finger, for the LVGL menus (the touch screen
// has its own input device, from the BSP)
auto *self = static_cast<BoxEmu *>(lv_indev_get_user_data(indev));
std::lock_guard<std::mutex> lock(self->remote_touch_mutex_);
const auto &r = self->remote_touch_;
if (r.fingers > 0) {
data->point.x = r.x;
data->point.y = r.y;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}

bool BoxEmu::update_gamepad_state() {
if (!input_) {
return false;
Expand Down
12 changes: 0 additions & 12 deletions components/devlink/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions components/devlink/idf_component.yml

This file was deleted.

112 changes: 0 additions & 112 deletions components/devlink/include/devlink.hpp

This file was deleted.

Loading
Loading