From 96b8e1859ad8e1aaf0cc810b2230dd8ba368de91 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 1 Oct 2020 15:49:23 +0200 Subject: [PATCH] [ion/events] Create event ExternalText Added an event to represent the typing of text that is not on the device's keyboard. ExternalText event's text is read from a buffer, that will be filled when the event is generated. ExternalText only exists on the simulator. Change-Id: Ie78d2c7c2de91da986a1ce2130a5ecd123db48ee --- ion/include/ion/events.h | 3 +++ ion/src/device/shared/events.cpp | 16 ++++++++++++++++ ion/src/shared/events.cpp | 15 --------------- ion/src/simulator/shared/events.cpp | 27 ++++++++++++++++++++++++++- ion/src/simulator/shared/events.h | 9 +++++++++ 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index b58727399..12079586a 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -229,6 +229,9 @@ constexpr Event TimerFire = Event::Special(2); constexpr Event USBEnumeration = Event::Special(3); constexpr Event USBPlug = Event::Special(4); constexpr Event BatteryCharging = Event::Special(5); +/* This event is only used in the simulator, to handle text that cannot be + * associated with a key. */ +// constexpr Event ExternalText = Event::Special(6); } } diff --git a/ion/src/device/shared/events.cpp b/ion/src/device/shared/events.cpp index 6eab2b3fc..12cb1c272 100644 --- a/ion/src/device/shared/events.cpp +++ b/ion/src/device/shared/events.cpp @@ -1,4 +1,5 @@ #include +#include namespace Ion { namespace Events { @@ -6,5 +7,20 @@ namespace Events { void didPressNewKey() { } +bool Event::isDefined() const { + if (isKeyboardEvent()) { + return s_dataForEvent[m_id].isDefined(); + } else { + return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging); + } +} + +const char * Event::text() const { + if (m_id >= 4*PageSize) { + return nullptr; + } + return s_dataForEvent[m_id].text(); +} + } } diff --git a/ion/src/shared/events.cpp b/ion/src/shared/events.cpp index 519c4acd3..d09501822 100644 --- a/ion/src/shared/events.cpp +++ b/ion/src/shared/events.cpp @@ -48,24 +48,9 @@ Event::Event(Keyboard::Key key, bool shift, bool alpha, bool lock) { assert(m_id != Events::None.m_id); } -const char * Event::text() const { - if (m_id >= 4*PageSize) { - return nullptr; - } - return s_dataForEvent[m_id].text(); -} - bool Event::hasText() const { return text() != nullptr; } -bool Event::isDefined() const { - if (isKeyboardEvent()) { - return s_dataForEvent[m_id].isDefined(); - } else { - return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging); - } -} - } } diff --git a/ion/src/simulator/shared/events.cpp b/ion/src/simulator/shared/events.cpp index a522fe7dd..5fb318e73 100644 --- a/ion/src/simulator/shared/events.cpp +++ b/ion/src/simulator/shared/events.cpp @@ -1,5 +1,7 @@ -#include +#include "events.h" #include "haptics.h" +#include +#include #include namespace Ion { @@ -9,5 +11,28 @@ void didPressNewKey() { Simulator::Haptics::rumble(); } +char * sharedExternalTextBuffer() { + static char buffer[32]; + return buffer; +} + +const char * Event::text() const { + if (m_id >= 4*PageSize) { + if (*this == ExternalText) { + return const_cast(sharedExternalTextBuffer()); + } + return nullptr; + } + return s_dataForEvent[m_id].text(); +} + +bool Event::isDefined() const { + if (isKeyboardEvent()) { + return s_dataForEvent[m_id].isDefined(); + } else { + return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging || *this == ExternalText); + } +} + } } diff --git a/ion/src/simulator/shared/events.h b/ion/src/simulator/shared/events.h index 5245e0a20..609d09b52 100644 --- a/ion/src/simulator/shared/events.h +++ b/ion/src/simulator/shared/events.h @@ -1,6 +1,8 @@ #ifndef ION_SIMULATOR_EVENTS_H #define ION_SIMULATOR_EVENTS_H +#include + namespace Ion { namespace Simulator { namespace Events { @@ -9,6 +11,13 @@ void dumpEventCount(int i); void logAfter(int numberOfEvents); } +} + +namespace Events { + +char * sharedExternalTextBuffer(); +constexpr Event ExternalText = Event::Special(6); + } }