diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 99e5e2ae..9124adfd 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -238,6 +238,10 @@ ui::Widget* EventDispatcher::touch_widget(ui::Widget* const w, ui::TouchEvent ev return nullptr; } +void EventDispatcher::emulateTouch(ui::TouchEvent event) { + on_touch_event(event); +} + void EventDispatcher::on_touch_event(ui::TouchEvent event) { /* TODO: Capture widget receiving the Start event, send Move and * End events to the same widget. diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index cbdb2900..d6ae1a10 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -86,6 +86,8 @@ class EventDispatcher { events_flag(EVT_MASK_LOCAL); } + void emulateTouch(ui::TouchEvent event); + private: static Thread* thread_event_loop; diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index 28d9fd21..5d215207 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -157,7 +157,7 @@ static void event_loop() { [&event_dispatcher](const Message* const) { event_dispatcher.set_display_sleep(true); }}; - + portapack::setEventDispatcherToUSBSerial(&event_dispatcher); event_dispatcher.run(); } diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 8813d30b..30b8c3e6 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -542,4 +542,8 @@ void shutdown(const bool leave_screen_on) { shutdown_base(); } +void setEventDispatcherToUSBSerial(EventDispatcher* evt) { + usb_serial.setEventDispatcher(evt); +} + } /* namespace portapack */ diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index a9cbebd5..3457365c 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -68,6 +68,8 @@ bool get_antenna_bias(); bool init(); void shutdown(const bool leave_screen_on = false); +void setEventDispatcherToUSBSerial(EventDispatcher* evt); + Backlight* backlight(); } /* namespace portapack */ diff --git a/firmware/application/usb_serial.cpp b/firmware/application/usb_serial.cpp index a1a8bd92..bf32e40a 100644 --- a/firmware/application/usb_serial.cpp +++ b/firmware/application/usb_serial.cpp @@ -32,7 +32,7 @@ void USBSerial::dispatch() { if (shell_created == false) { shell_created = true; - create_shell(); + create_shell(_eventDispatcher); } bulk_out_receive(); diff --git a/firmware/application/usb_serial.hpp b/firmware/application/usb_serial.hpp index f4f50ee3..55e1900b 100644 --- a/firmware/application/usb_serial.hpp +++ b/firmware/application/usb_serial.hpp @@ -24,6 +24,8 @@ #include "ch.h" #include "hal.h" +class EventDispatcher; + namespace portapack { class USBSerial { @@ -32,6 +34,7 @@ class USBSerial { void dispatch(); void on_channel_opened(); void on_channel_closed(); + void setEventDispatcher(EventDispatcher* ed) { _eventDispatcher = ed; } private: void enable_xtal(); @@ -43,6 +46,8 @@ class USBSerial { bool connected{false}; bool shell_created{false}; + + EventDispatcher* _eventDispatcher = NULL; }; } // namespace portapack \ No newline at end of file diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 72f9ed2e..84242967 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -51,6 +51,11 @@ #define SHELL_WA_SIZE THD_WA_SIZE(1024 * 3) #define palOutputPad(port, pad) (LPC_GPIO->DIR[(port)] |= 1 << (pad)) +static EventDispatcher* _eventDispatcherInstance = NULL; +static EventDispatcher* getEventDispatcherInstance() { + return _eventDispatcherInstance; +} + // queue handler from ch static msg_t qwait(GenericQueue* qp, systime_t time) { if (TIME_IMMEDIATE == time) @@ -338,6 +343,28 @@ static void cmd_button(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, "ok\r\n"); } +static void cmd_touch(BaseSequentialStream* chp, int argc, char* argv[]) { + if (argc != 2) { + chprintf(chp, "usage: touch x y\r\n"); + return; + } + + int x = (int)strtol(argv[0], NULL, 10); + int y = (int)strtol(argv[1], NULL, 10); + if (x < 0 || x > ui::screen_width || y < 0 || y > ui::screen_height) { + chprintf(chp, "usage: touch x y\r\n"); + return; + } + + auto evtd = getEventDispatcherInstance(); + if (evtd == NULL) { + chprintf(chp, "error\r\n"); + } + evtd->emulateTouch({{x, y}, ui::TouchEvent::Type::Start}); + evtd->emulateTouch({{x, y}, ui::TouchEvent::Type::End}); + chprintf(chp, "ok\r\n"); +} + static void cmd_sd_list_dir(BaseSequentialStream* chp, int argc, char* argv[]) { if (argc != 1) { chprintf(chp, "usage: ls /\r\n"); @@ -838,6 +865,7 @@ static const ShellCommand commands[] = { {"write_memory", cmd_write_memory}, {"read_memory", cmd_read_memory}, {"button", cmd_button}, + {"touch", cmd_touch}, {"ls", cmd_sd_list_dir}, {"rm", cmd_sd_delete}, {"open", cmd_sd_open}, @@ -854,6 +882,7 @@ static const ShellConfig shell_cfg1 = { (BaseSequentialStream*)&SUSBD1, commands}; -void create_shell() { +void create_shell(EventDispatcher* evtd) { + _eventDispatcherInstance = evtd; shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); } diff --git a/firmware/application/usb_serial_shell.hpp b/firmware/application/usb_serial_shell.hpp index bcfed055..d442f92b 100644 --- a/firmware/application/usb_serial_shell.hpp +++ b/firmware/application/usb_serial_shell.hpp @@ -26,4 +26,6 @@ #include "shell.h" -void create_shell(void); +class EventDispatcher; + +void create_shell(EventDispatcher* evtd);