mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion/simulator] Add haptic feedback
This commit is contained in:
committed by
EmilieNumworks
parent
1c0f6a7913
commit
b020cb2f98
@@ -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
|
||||
|
||||
|
||||
@@ -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 \
|
||||
)
|
||||
|
||||
10
ion/src/device/shared/events.cpp
Normal file
10
ion/src/device/shared/events.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <ion/events.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Events {
|
||||
|
||||
void didPressNewKey() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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).
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
)
|
||||
|
||||
@@ -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 \
|
||||
)
|
||||
|
||||
19
ion/src/simulator/shared/dummy/haptics.cpp
Normal file
19
ion/src/simulator/shared/dummy/haptics.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "haptics.h"
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
void perform() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
13
ion/src/simulator/shared/events.cpp
Normal file
13
ion/src/simulator/shared/events.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <ion/events.h>
|
||||
#include "haptics.h"
|
||||
#include <SDL.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Events {
|
||||
|
||||
void didPressNewKey() {
|
||||
Simulator::Haptics::perform();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
44
ion/src/simulator/shared/haptics.cpp
Normal file
44
ion/src/simulator/shared/haptics.cpp
Normal 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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
16
ion/src/simulator/shared/haptics.h
Normal file
16
ion/src/simulator/shared/haptics.h
Normal 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
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user