I NEED SLEEP

This commit is contained in:
sylvieee-iot 2024-05-08 22:47:41 +03:00 committed by GitHub
parent 4cdcb8a2ab
commit eab5fd3a44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 145 additions and 34 deletions

View file

@ -241,7 +241,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
include/PICA/dynapica/shader_rec_emitter_arm64.hpp include/scheduler.hpp include/applets/error_applet.hpp include/PICA/dynapica/shader_rec_emitter_arm64.hpp include/scheduler.hpp include/applets/error_applet.hpp
include/audio/dsp_core.hpp include/audio/null_core.hpp include/audio/teakra_core.hpp include/audio/dsp_core.hpp include/audio/null_core.hpp include/audio/teakra_core.hpp
include/audio/miniaudio_device.hpp include/ring_buffer.hpp include/bitfield.hpp include/audio/dsp_shared_mem.hpp include/audio/miniaudio_device.hpp include/ring_buffer.hpp include/bitfield.hpp include/audio/dsp_shared_mem.hpp
include/audio/hle_core.hpp include/capstone.hpp include/audio/aac.hpp include/audio/hle_core.hpp include/capstone.hpp include/audio/aac.hpp include/external_haptics_manager.hpp
) )
cmrc_add_resource_library( cmrc_add_resource_library(

View file

@ -0,0 +1,51 @@
#pragma once
#include <chrono>
#include <cstdio>
#include <string>
#include <thread>
#include <vector>
#include "buttplugclient.h"
class ExternalHapticsManager {
Client client;
std::vector<DeviceClass> devices;
SensorClass sensors;
public:
ExternalHapticsManager() : client("ws://127.0.0.1", 12345) {}
void connect() {
client.connect([](const mhl::Messages message) {
switch (message.messageType) {
case mhl::MessageTypes::DeviceList: std::printf("Device List callback\n"); break;
case mhl::MessageTypes::DeviceAdded: std::printf("Device List callback\n"); break;
case mhl::MessageTypes::ServerInfo: std::printf("Server info callback\n"); break;
case mhl::MessageTypes::DeviceRemoved: std::printf("Device Removed callback\n"); break;
case mhl::MessageTypes::SensorReading: std::printf("Sensor reading callback\n"); break;
default: std::printf("Unknown message");
}
});
}
void requestDeviceList() { client.requestDeviceList(); }
void startScan() { client.startScan(); }
void stopScan() { client.stopScan(); }
void stopAllDevices() { client.stopAllDevices(); }
void getDevices() { devices = client.getDevices(); }
void getSensors() { sensors = client.getSensors(); }
void sendScalar(int index, double value) {
if (index < devices.size()) {
client.sendScalar(devices[index], value);
}
}
void stopDevice(int index) {
if (index < devices.size()) {
client.stopDevice(devices[index]);
}
}
};

View file

@ -2,6 +2,7 @@
#include <teakra/disassembler.h> #include <teakra/disassembler.h>
#include <array> #include <array>
#include <memory>
#include "capstone.hpp" #include "capstone.hpp"
#include "emulator.hpp" #include "emulator.hpp"
@ -11,6 +12,8 @@
extern "C" { extern "C" {
#include "luv.h" #include "luv.h"
} }
#include "external_haptics_manager.hpp"
#endif #endif
void LuaManager::initialize() { void LuaManager::initialize() {
@ -242,6 +245,80 @@ static int disassembleTeakThunk(lua_State* L) {
return 1; 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 // clang-format off
static constexpr luaL_Reg functions[] = { static constexpr luaL_Reg functions[] = {
{ "__read8", read8Thunk }, { "__read8", read8Thunk },
@ -310,6 +387,20 @@ void LuaManager::initializeThunks() {
ButtonLeft = __ButtonLeft, ButtonLeft = __ButtonLeft,
ButtonRight= __ButtonRight, 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) { auto addIntConstant = [&]<typename T>(T x, const char* name) {
@ -318,6 +409,8 @@ void LuaManager::initializeThunks() {
}; };
luaL_register(L, "GLOBALS", functions); luaL_register(L, "GLOBALS", functions);
Haptics::registerFunctions(L);
// Add values for event enum // Add values for event enum
addIntConstant(LuaEvent::Frame, "__Frame"); addIntConstant(LuaEvent::Frame, "__Frame");

View file

@ -1,40 +1,7 @@
#include "panda_sdl/frontend_sdl.hpp" #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[]) { int main(int argc, char *argv[]) {
FrontendSDL app; 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) { if (argc > 1) {
auto romPath = std::filesystem::current_path() / argv[1]; auto romPath = std::filesystem::current_path() / argv[1];