diff --git a/Artemis/LightFX2Artemis/LightFX2Artemis.vcxproj b/Artemis/LightFX2Artemis/LightFX2Artemis.vcxproj
index a6252b787..69d2d3d31 100644
--- a/Artemis/LightFX2Artemis/LightFX2Artemis.vcxproj
+++ b/Artemis/LightFX2Artemis/LightFX2Artemis.vcxproj
@@ -105,6 +105,7 @@
Disabled
_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ $(ProjectDir)includes;%(AdditionalIncludeDirectories)
Console
diff --git a/Artemis/LightFX2Artemis/LightFxDevice.cpp b/Artemis/LightFX2Artemis/LightFxDevice.cpp
index 39e05a86e..365d7d684 100644
--- a/Artemis/LightFX2Artemis/LightFxDevice.cpp
+++ b/Artemis/LightFX2Artemis/LightFxDevice.cpp
@@ -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;
diff --git a/Artemis/LightFX2Artemis/LightFxDevice.h b/Artemis/LightFX2Artemis/LightFxDevice.h
index 9c4817f6d..7a55faec7 100644
--- a/Artemis/LightFX2Artemis/LightFxDevice.h
+++ b/Artemis/LightFX2Artemis/LightFxDevice.h
@@ -1,6 +1,6 @@
#pragma once
#include "LightFxLight.h"
-#include
+#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];
};
diff --git a/Artemis/LightFX2Artemis/LightFxLight.cpp b/Artemis/LightFX2Artemis/LightFxLight.cpp
index bb3d5fe19..b5e5cbf85 100644
--- a/Artemis/LightFX2Artemis/LightFxLight.cpp
+++ b/Artemis/LightFX2Artemis/LightFxLight.cpp
@@ -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;
+}
diff --git a/Artemis/LightFX2Artemis/LightFxLight.h b/Artemis/LightFX2Artemis/LightFxLight.h
index d67adc20e..123684a50 100644
--- a/Artemis/LightFX2Artemis/LightFxLight.h
+++ b/Artemis/LightFX2Artemis/LightFxLight.h
@@ -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;
};
diff --git a/Artemis/LightFX2Artemis/LightFxState.cpp b/Artemis/LightFX2Artemis/LightFxState.cpp
index 168f20eb2..abd02c572 100644
--- a/Artemis/LightFX2Artemis/LightFxState.cpp
+++ b/Artemis/LightFX2Artemis/LightFxState.cpp
@@ -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;
}
diff --git a/Artemis/LightFX2Artemis/LightFxState.h b/Artemis/LightFX2Artemis/LightFxState.h
index e2381d9b4..ab74f7c6d 100644
--- a/Artemis/LightFX2Artemis/LightFxState.h
+++ b/Artemis/LightFX2Artemis/LightFxState.h
@@ -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;
};
diff --git a/Artemis/LightFX2Artemis/Source.cpp b/Artemis/LightFX2Artemis/Source.cpp
index e248ea176..5da496bc8 100644
--- a/Artemis/LightFX2Artemis/Source.cpp
+++ b/Artemis/LightFX2Artemis/Source.cpp
@@ -4,28 +4,27 @@
#include
#include
#include
-#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;
}