mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Finalized LightFX C++ project
Implemented JSON serialization Implemented pipe transmission Made sure both x86 and x64 compile
This commit is contained in:
parent
4be324dc69
commit
3e9a86d893
@ -105,6 +105,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
@ -3,7 +3,11 @@ using json = nlohmann::json;
|
||||
|
||||
|
||||
LightFxDevice::LightFxDevice()
|
||||
{
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Lights[i] = new LightFxLight();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,20 +16,17 @@ LightFxDevice::~LightFxDevice()
|
||||
}
|
||||
|
||||
void LightFxDevice::SetLightFromInt(int lightIndex, const unsigned colorVal)
|
||||
{
|
||||
Lights[lightIndex].Color->brightness = (colorVal >> 24) & 0xFF;
|
||||
Lights[lightIndex].Color->red = (colorVal >> 16) & 0xFF;
|
||||
Lights[lightIndex].Color->green = (colorVal >> 8) & 0xFF;
|
||||
Lights[lightIndex].Color->blue = colorVal & 0xFF;
|
||||
{
|
||||
Lights[lightIndex]->FromInt(colorVal);
|
||||
}
|
||||
|
||||
json LightFxDevice::GetJson()
|
||||
{
|
||||
json j;
|
||||
j["lights"] = {};
|
||||
for (LightFxLight light : Lights)
|
||||
for (LightFxLight* light : Lights)
|
||||
{
|
||||
j["lights"].push_back(light.GetJson());
|
||||
j["lights"].push_back(light->GetJson());
|
||||
}
|
||||
|
||||
return j;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "LightFxLight.h"
|
||||
#include <json.hpp>
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@ -11,5 +11,5 @@ public:
|
||||
~LightFxDevice();
|
||||
void SetLightFromInt(int lightIndex, const unsigned colorVal);
|
||||
json GetJson();
|
||||
LightFxLight Lights[128];
|
||||
LightFxLight* Lights[5];
|
||||
};
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
LightFxLight::LightFxLight()
|
||||
{
|
||||
Color = new LFX_COLOR{0,0,0,0};
|
||||
}
|
||||
|
||||
|
||||
@ -21,3 +22,11 @@ json LightFxLight::GetJson()
|
||||
};
|
||||
return j;
|
||||
}
|
||||
|
||||
void LightFxLight::FromInt(const unsigned colorVal)
|
||||
{
|
||||
Color->brightness = (colorVal >> 24) & 0xFF;
|
||||
Color->red = (colorVal >> 16) & 0xFF;
|
||||
Color->green = (colorVal >> 8) & 0xFF;
|
||||
Color->blue = colorVal & 0xFF;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "includes/LFXDecl.h"
|
||||
#include "LFXDecl.h"
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
@ -10,5 +10,6 @@ public:
|
||||
LightFxLight();
|
||||
~LightFxLight();
|
||||
json GetJson();
|
||||
PLFX_COLOR Color;
|
||||
void FromInt(const unsigned colorVal);
|
||||
LFX_COLOR* Color;
|
||||
};
|
||||
|
||||
@ -6,6 +6,11 @@ using json = nlohmann::json;
|
||||
LightFxState::LightFxState(char* game)
|
||||
{
|
||||
Game = game;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Devices[i] = new LightFxDevice();
|
||||
}
|
||||
LocationMaskLight = new LightFxLight();
|
||||
}
|
||||
|
||||
|
||||
@ -13,16 +18,22 @@ LightFxState::~LightFxState()
|
||||
{
|
||||
}
|
||||
|
||||
const char* LightFxState::Update()
|
||||
json LightFxState::GetJson()
|
||||
{
|
||||
json root;
|
||||
json j;
|
||||
root["lightFxState"] = { j };
|
||||
|
||||
j["game"] = Game;
|
||||
j["mask"] = {
|
||||
{ "location", LocationMask },
|
||||
{ "light", LocationMaskLight->GetJson() }
|
||||
};
|
||||
j["devices"] = {};
|
||||
for (LightFxDevice device : Devices)
|
||||
for (LightFxDevice* device : Devices)
|
||||
{
|
||||
j["devices"].push_back(device.GetJson());
|
||||
j["devices"].push_back(device->GetJson());
|
||||
}
|
||||
|
||||
std::string s = j.dump();
|
||||
return s.c_str();
|
||||
return j;
|
||||
}
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
#pragma once
|
||||
#include "LightFxDevice.h"
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class LightFxState
|
||||
{
|
||||
public:
|
||||
LightFxState(char* game);
|
||||
~LightFxState();
|
||||
const char* Update();
|
||||
json GetJson();
|
||||
char* Game;
|
||||
LightFxDevice Devices[5];
|
||||
LightFxDevice* Devices[5];
|
||||
unsigned LocationMask;
|
||||
LightFxLight* LocationMaskLight;
|
||||
};
|
||||
|
||||
@ -4,28 +4,27 @@
|
||||
#include <complex>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include "../LightFX2Artemis/LightFxState.h"
|
||||
#include "includes/LFX2.h"
|
||||
#include "includes/LFXDecl.h"
|
||||
#include "includes/log.h"
|
||||
#include "LightFxState.h"
|
||||
#include "LFX2.h"
|
||||
#include "LFXDecl.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
LightFxState* lightFxState;
|
||||
|
||||
char* GetGame()
|
||||
{
|
||||
CHAR szPath[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, szPath, MAX_PATH);
|
||||
|
||||
return szPath;
|
||||
};
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID)
|
||||
{
|
||||
if (fdwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
lightFxState = new LightFxState("Payday2");
|
||||
// Get executing .exe path. Not very pretty but other methods messed JSON up
|
||||
WCHAR ownPth[MAX_PATH];
|
||||
HMODULE hModule = GetModuleHandle(NULL);
|
||||
GetModuleFileName(hModule, ownPth, sizeof ownPth);
|
||||
char* moduleName = new char[sizeof ownPth];
|
||||
wcstombs(moduleName, ownPth, sizeof ownPth);
|
||||
|
||||
lightFxState = new LightFxState(moduleName);
|
||||
FILELog::ReportingLevel() = logDEBUG1;
|
||||
FILE* log_fd = fopen("log.txt", "w");
|
||||
Output2FILE::Stream() = log_fd;
|
||||
@ -75,8 +74,15 @@ FN_DECLSPEC LFX_RESULT STDCALL LFX_Update()
|
||||
{
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_Update()";
|
||||
|
||||
const char* jsonString = lightFxState->Update();
|
||||
FILE_LOG(logDEBUG1) << "JSON: " << jsonString;
|
||||
// Get the JSON
|
||||
json j = lightFxState->GetJson();
|
||||
// Transmit to Artemis
|
||||
Transmit(j.dump().c_str());
|
||||
|
||||
// Only bother dumping it indented if actually debugging
|
||||
if (FILELog::ReportingLevel() == logDEBUG1)
|
||||
FILE_LOG(logDEBUG1) << "JSON: " << j.dump(4);
|
||||
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
@ -126,7 +132,7 @@ FN_DECLSPEC LFX_RESULT STDCALL LFX_GetNumLights(const unsigned int devIndex, uns
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_GetNumLights()";
|
||||
|
||||
// Just do one for now
|
||||
*numLights = 1;
|
||||
*numLights = 5;
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
@ -156,7 +162,7 @@ FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightColor(const unsigned int devIndex, co
|
||||
{
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_GetLightColor()";
|
||||
|
||||
*lightCol = *lightFxState->Devices[devIndex].Lights[lightIndex].Color;
|
||||
*lightCol = *lightFxState->Devices[devIndex]->Lights[lightIndex]->Color;
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
@ -164,18 +170,16 @@ FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightColor(const unsigned int devIndex, co
|
||||
{
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_SetLightColor()";
|
||||
|
||||
lightFxState->Devices[devIndex].Lights[lightIndex].Color = lightCol;
|
||||
lightFxState->Devices[devIndex]->Lights[lightIndex]->Color = lightCol;
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
FN_DECLSPEC LFX_RESULT STDCALL LFX_Light(const unsigned int locationMask, const unsigned int colorVal)
|
||||
{
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_Light()";
|
||||
FILE_LOG(logDEBUG1) << "Called LFX_Light(locationMask " << locationMask << ", colorVal " << colorVal << ")";
|
||||
|
||||
for (LightFxDevice device : lightFxState->Devices)
|
||||
{
|
||||
device.SetLightFromInt(0, colorVal);
|
||||
}
|
||||
lightFxState->LocationMask = locationMask;
|
||||
lightFxState->LocationMaskLight->FromInt(colorVal);
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user