From 55443cccb8fb571560e42a3581aeda6fd4aa8a41 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 8 Dec 2018 18:26:22 -0600 Subject: [PATCH] Add SMX_SetLights2 to specify the buffer size explicitly. --- sdk/SMX.h | 11 +++++------ sdk/Windows/SMX.cpp | 28 +++++++++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sdk/SMX.h b/sdk/SMX.h index ce8d9fb..3412134 100644 --- a/sdk/SMX.h +++ b/sdk/SMX.h @@ -45,7 +45,7 @@ SMX_API void SMX_GetInfo(int pad, SMXInfo *info); // Get a mask of the currently pressed panels. SMX_API uint16_t SMX_GetInputState(int pad); -// Update the lights. Both pads are always updated together. lightsData is a list of 8-bit RGB +// Update the lights. Both pads are always updated together. lightData is a list of 8-bit RGB // colors, one for each LED. Each panel has lights in the following order: // // 0123 @@ -66,12 +66,11 @@ SMX_API uint16_t SMX_GetInputState(int pad); // // The panels will return to automatic lighting if no lights are received for a while, so applications // controlling lights should send light updates continually, even if the lights aren't changing. -SMX_API void SMX_SetLights(const char lightsData[864]); +SMX_API void SMX_SetLights(const char lightData[864]); -// This is the same as SMX_SetLights, but receives lights for each pad in separate -// buffers of 432 colors each. lightsDataSize[pad] is the size of lightsData. If -// it's not 432, that pad's lights will be left unchanged. -SMX_API void SMX_SetLights2(const char *lightsData[2], int lightsDataSize[2]); +// This is the same as SMX_SetLights, but specifies the size of the buffer. The +// buffer size must be 864 bytes (2 pads * 9 panels * 16 lights * 3). +SMX_API void SMX_SetLights2(const char *lightData, int lightDataSize); // By default, the panels light automatically when stepped on. If a lights command is sent by // the application, this stops happening to allow the application to fully control lighting. diff --git a/sdk/Windows/SMX.cpp b/sdk/Windows/SMX.cpp index 83a065d..999a2b0 100644 --- a/sdk/Windows/SMX.cpp +++ b/sdk/Windows/SMX.cpp @@ -64,20 +64,26 @@ SMX_API void SMX_FactoryReset(int pad) { SMXManager::g_pSMX->GetDevice(pad)->Fac SMX_API void SMX_ForceRecalibration(int pad) { SMXManager::g_pSMX->GetDevice(pad)->ForceRecalibration(); } SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { SMXManager::g_pSMX->GetDevice(pad)->SetSensorTestMode((SensorTestMode) mode); } SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data) { return SMXManager::g_pSMX->GetDevice(pad)->GetTestData(*data); } -SMX_API void SMX_SetLights(const char lightsData[864]) +SMX_API void SMX_SetLights(const char lightData[864]) { - string lights[] = { - string(lightsData, 432), - string(lightsData+432, 432), - }; - SMXManager::g_pSMX->SetLights(lights); + SMX_SetLights2(lightData, 864); } -SMX_API void SMX_SetLights2(const char *lightsData[2], int lightsDataSize[2]) +SMX_API void SMX_SetLights2(const char *lightData, int lightDataSize) { - string lights[] = { - string(lightsData[0], lightsDataSize[0]), - string(lightsData[1], lightsDataSize[1]), - }; + // The lightData into data per pad. + string lights[2]; + const int BytesPerPad16 = 9*16*3; + if(lightDataSize == 2*BytesPerPad16) + { + lights[0] = string(lightData, BytesPerPad16); + lights[1] = string(lightData + BytesPerPad16, BytesPerPad16); + } + else + { + Log(ssprintf("SMX_SetLights2: lightDataSize is invalid (must be %ii)\n", 2*BytesPerPad16)); + return; + } + SMXManager::g_pSMX->SetLights(lights); } SMX_API void SMX_ReenableAutoLights() { SMXManager::g_pSMX->ReenableAutoLights(); }