mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-04 22:32:57 +12:00
I NEED SLEEP
This commit is contained in:
parent
4cdcb8a2ab
commit
eab5fd3a44
4 changed files with 145 additions and 34 deletions
93
src/lua.cpp
93
src/lua.cpp
|
@ -2,6 +2,7 @@
|
|||
#include <teakra/disassembler.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#include "capstone.hpp"
|
||||
#include "emulator.hpp"
|
||||
|
@ -11,6 +12,8 @@
|
|||
extern "C" {
|
||||
#include "luv.h"
|
||||
}
|
||||
|
||||
#include "external_haptics_manager.hpp"
|
||||
#endif
|
||||
|
||||
void LuaManager::initialize() {
|
||||
|
@ -242,6 +245,80 @@ static int disassembleTeakThunk(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifndef __ANDROID__
|
||||
// Haptics functions
|
||||
|
||||
namespace Haptics {
|
||||
std::unique_ptr<ExternalHapticsManager> hapticsManager = nullptr;
|
||||
|
||||
static int initHapticsThunk(lua_State* L) {
|
||||
if (hapticsManager == nullptr) {
|
||||
hapticsManager.reset(new ExternalHapticsManager());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define HAPTICS_THUNK(func) \
|
||||
static int func##Thunk(lua_State* L) { \
|
||||
if (hapticsManager != nullptr) { \
|
||||
hapticsManager->func(); \
|
||||
} \
|
||||
\
|
||||
return 0; \
|
||||
}
|
||||
|
||||
HAPTICS_THUNK(startScan)
|
||||
HAPTICS_THUNK(stopScan)
|
||||
HAPTICS_THUNK(connect)
|
||||
HAPTICS_THUNK(requestDeviceList)
|
||||
HAPTICS_THUNK(getDevices)
|
||||
HAPTICS_THUNK(getSensors)
|
||||
HAPTICS_THUNK(stopAllDevices)
|
||||
#undef HAPTICS_THUNK
|
||||
|
||||
static int sendScalarThunk(lua_State* L) {
|
||||
const int device = (int)lua_tonumber(L, 1);
|
||||
const auto value = lua_tonumber(L, 2);
|
||||
|
||||
if (hapticsManager != nullptr) {
|
||||
hapticsManager->sendScalar(device, value);
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int stopDeviceThunk(lua_State* L) {
|
||||
const int device = (int)lua_tonumber(L, 1);
|
||||
|
||||
if (hapticsManager != nullptr) {
|
||||
hapticsManager->stopDevice(device);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
static constexpr luaL_Reg functions[] = {
|
||||
{ "initHaptics", initHapticsThunk },
|
||||
{ "startScan", startScanThunk },
|
||||
{ "stopScan", stopScanThunk },
|
||||
{ "connect", connectThunk },
|
||||
{ "requestDeviceList", requestDeviceListThunk },
|
||||
{ "getDevices", getDevicesThunk },
|
||||
{ "getSensors", getSensorsThunk },
|
||||
{ "stopAllDevices", stopAllDevicesThunk },
|
||||
{ "sendScalar", sendScalarThunk },
|
||||
{ "stopDevice", stopDeviceThunk },
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
void registerFunctions(lua_State* L) {
|
||||
luaL_register(L, "HAPTICS", functions);
|
||||
}
|
||||
} // namespace Haptics
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
static constexpr luaL_Reg functions[] = {
|
||||
{ "__read8", read8Thunk },
|
||||
|
@ -310,6 +387,20 @@ void LuaManager::initializeThunks() {
|
|||
ButtonLeft = __ButtonLeft,
|
||||
ButtonRight= __ButtonRight,
|
||||
}
|
||||
|
||||
Buzz = {
|
||||
initHaptics = function() HAPTICS.initHaptics() end,
|
||||
startScan = function() HAPTICS.startScan() end,
|
||||
stopScan = function() HAPTICS.stopScan() end,
|
||||
connect = function() HAPTICS.connect() end,
|
||||
requestDeviceList = function() HAPTICS.requestDeviceList() end,
|
||||
getDevices = function() HAPTICS.getDevices() end,
|
||||
getSensors = function() HAPTICS.getSensors() end,
|
||||
stopAllDevices = function() HAPTICS.stopAllDevices() end,
|
||||
|
||||
sendScalar = function(device, value) HAPTICS.sendScalar(device, value) end,
|
||||
stopDevice = function(device) HAPTICS.stopDevice(device) end,
|
||||
}
|
||||
)";
|
||||
|
||||
auto addIntConstant = [&]<typename T>(T x, const char* name) {
|
||||
|
@ -318,6 +409,8 @@ void LuaManager::initializeThunks() {
|
|||
};
|
||||
|
||||
luaL_register(L, "GLOBALS", functions);
|
||||
Haptics::registerFunctions(L);
|
||||
|
||||
// Add values for event enum
|
||||
addIntConstant(LuaEvent::Frame, "__Frame");
|
||||
|
||||
|
|
|
@ -1,40 +1,7 @@
|
|||
#include "panda_sdl/frontend_sdl.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
#include "buttplugclient.h"
|
||||
|
||||
void callbackFunction(const mhl::Messages msg) {
|
||||
switch (msg.messageType) {
|
||||
case mhl::MessageTypes::DeviceList: printf("Device List callback\n"); break;
|
||||
case mhl::MessageTypes::DeviceAdded: printf("Device List callback\n"); break;
|
||||
case mhl::MessageTypes::ServerInfo: printf("Server info callback\n"); break;
|
||||
case mhl::MessageTypes::DeviceRemoved: printf("Device Removed callback\n"); break;
|
||||
case mhl::MessageTypes::SensorReading: printf("Sensor reading callback\n"); break;
|
||||
default: printf("Unknown message");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FrontendSDL app;
|
||||
std::string url = "ws://127.0.0.1";
|
||||
Client client(url, 12345, "test.txt");
|
||||
client.connect(callbackFunction);
|
||||
client.requestDeviceList();
|
||||
|
||||
while (1) {
|
||||
client.startScan();
|
||||
|
||||
std::vector<DeviceClass> myDevices = client.getDevices();
|
||||
if (myDevices.size() > 0) {
|
||||
client.sendScalar(myDevices[0], 0.5);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
client.stopScan();
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
auto romPath = std::filesystem::current_path() / argv[1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue