[ion/simulator] Add haptic feedback

This commit is contained in:
Léa Saviot
2020-07-01 15:58:24 +02:00
committed by EmilieNumworks
parent 1c0f6a7913
commit b020cb2f98
16 changed files with 120 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ bool isLockActive();
void setLongRepetition(bool longRepetition);
bool isLongRepetition();
void updateModifiersFromEvent(Event e);
void didPressNewKey(); // Used for haptic feedback on simulators
// Plain

View File

@@ -3,5 +3,6 @@ include ion/src/device/shared/usb/Makefile
include ion/src/device/shared/drivers/Makefile
ion_device_src += $(addprefix ion/src/device/shared/, \
events.cpp \
stack.cpp \
)

View File

@@ -0,0 +1,10 @@
#include <ion/events.h>
namespace Ion {
namespace Events {
void didPressNewKey() {
}
}
}

View File

@@ -65,6 +65,7 @@ Event getEvent(int * timeout) {
if (keysSeenTransitionningFromUpToDown != 0) {
sEventIsRepeating = false;
resetLongRepetition();
didPressNewKey();
/* The key that triggered the event corresponds to the first non-zero bit
* in "match". This is a rather simple logic operation for the which many
* processors have an instruction (ARM thumb uses CLZ).

View File

@@ -11,6 +11,7 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
console_stdio.cpp:-consoledisplay \
crc32.cpp \
display.cpp:-headless \
events.cpp \
events_keyboard.cpp:-headless \
events_stdin.cpp:+headless \
framebuffer_base.cpp \

View File

@@ -5,6 +5,7 @@ ion_src += $(addprefix ion/src/simulator/android/src/cpp/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/callback.cpp \
dummy/language.cpp \
haptics.cpp \
)
ion_src += ion/src/shared/collect_registers.cpp

View File

@@ -5,6 +5,7 @@ ion_src += $(addprefix ion/src/simulator/ios/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
apple/language.m \
dummy/callback.cpp \
haptics.cpp \
)
ion_src += ion/src/shared/collect_registers.cpp

View File

@@ -15,6 +15,7 @@ ion_src += $(addprefix ion/src/simulator/linux/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/callback.cpp \
dummy/haptics.cpp \
collect_registers_x86_64.s \
collect_registers.cpp \
)

View File

@@ -5,6 +5,7 @@ ion_src += $(addprefix ion/src/simulator/macos/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
apple/language.m \
dummy/callback.cpp \
dummy/haptics.cpp \
collect_registers_x86_64.s \
collect_registers.cpp \
)

View File

@@ -0,0 +1,19 @@
#include "haptics.h"
namespace Ion {
namespace Simulator {
namespace Haptics {
void init() {
}
void shutdown() {
}
void perform() {
}
}
}
}

View File

@@ -0,0 +1,13 @@
#include <ion/events.h>
#include "haptics.h"
#include <SDL.h>
namespace Ion {
namespace Events {
void didPressNewKey() {
Simulator::Haptics::perform();
}
}
}

View File

@@ -0,0 +1,44 @@
#include "haptics.h"
#include <SDL.h>
namespace Ion {
namespace Simulator {
namespace Haptics {
#if !EPSILON_SDL_SCREEN_ONLY
static SDL_Haptic * sSDLHaptic = nullptr;
#endif
void init() {
#if !EPSILON_SDL_SCREEN_ONLY
if (SDL_Init(SDL_INIT_HAPTIC) == 0) {
sSDLHaptic = SDL_HapticOpen(0);
if (sSDLHaptic) {
if (SDL_HapticRumbleInit(sSDLHaptic) != 0) {
sSDLHaptic = nullptr;
}
}
}
#endif
}
void shutdown() {
#if !EPSILON_SDL_SCREEN_ONLY
if (sSDLHaptic) {
SDL_HapticClose(sSDLHaptic);
}
#endif
}
void perform() {
#if !EPSILON_SDL_SCREEN_ONLY
if (sSDLHaptic) {
SDL_HapticRumblePlay(sSDLHaptic, 1.0, 40);
}
#endif
}
}
}
}

View File

@@ -0,0 +1,16 @@
#ifndef ION_SIMULATOR_HAPTICS_H
#define ION_SIMULATOR_HAPTICS_H
namespace Ion {
namespace Simulator {
namespace Haptics {
void init();
void perform();
void shutdown();
}
}
}
#endif

View File

@@ -1,9 +1,10 @@
#include "main.h"
#include "display.h"
#include "platform.h"
#include "haptics.h"
#if !EPSILON_SDL_SCREEN_ONLY
#include "layout.h"
#endif
#include "platform.h"
#include "telemetry.h"
#include "random.h"
@@ -27,11 +28,17 @@ int main(int argc, char * argv[]) {
arguments.push_back(language);
}
// Init
#if EPSILON_TELEMETRY
Ion::Simulator::Telemetry::init();
#endif
Ion::Simulator::Main::init();
Ion::Simulator::Haptics::init();
ion_main(arguments.size(), &arguments[0]);
// Shutdown
Ion::Simulator::Haptics::shutdown();
Ion::Simulator::Main::quit();
#if EPSILON_TELEMETRY
Ion::Simulator::Telemetry::shutdown();

View File

@@ -20,6 +20,7 @@ ion_src += $(addprefix ion/src/simulator/web/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/language.cpp \
dummy/haptics.cpp \
)
ion_src += ion/src/shared/collect_registers.cpp

View File

@@ -6,6 +6,7 @@ ion_src += $(addprefix ion/src/simulator/windows/, \
ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/callback.cpp \
dummy/haptics.cpp \
)
ion_src += ion/src/shared/collect_registers.cpp