|
|
|
@ -1,27 +1,19 @@ |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <windows.h> |
|
|
|
|
#include "SMX.h" |
|
|
|
|
#include <memory> |
|
|
|
|
#include <string> |
|
|
|
|
using namespace std; |
|
|
|
|
#define OLC_PGE_APPLICATION |
|
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
|
class InputSample |
|
|
|
|
class SMX_PGE : public olc::PixelGameEngine |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
InputSample() |
|
|
|
|
SMX_PGE() |
|
|
|
|
{ |
|
|
|
|
// Set a logging callback. This can be called before SMX_Start.
|
|
|
|
|
// SMX_SetLogCallback( SMXLogCallback );
|
|
|
|
|
|
|
|
|
|
// Start scanning. The update callback will be called when devices connect or
|
|
|
|
|
// disconnect or panels are pressed or released. This callback will be called
|
|
|
|
|
// from a thread.
|
|
|
|
|
SMX_Start( SMXStateChangedCallback, this ); |
|
|
|
|
sAppName = "Example"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void SMXStateChangedCallback(int pad, SMXUpdateCallbackReason reason, void *pUser) |
|
|
|
|
{ |
|
|
|
|
InputSample *pSelf = (InputSample *) pUser; |
|
|
|
|
SMX_PGE *pSelf = (SMX_PGE*) pUser; |
|
|
|
|
pSelf->SMXStateChanged( pad, reason ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -36,76 +28,30 @@ public: |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int iPanelToLight = 0; |
|
|
|
|
void SetLights() |
|
|
|
|
{ |
|
|
|
|
string sLightsData; |
|
|
|
|
auto addColor = [&sLightsData](uint8_t r, uint8_t g, uint8_t b) |
|
|
|
|
{ |
|
|
|
|
sLightsData.append( 1, r ); |
|
|
|
|
sLightsData.append( 1, g ); |
|
|
|
|
sLightsData.append( 1, b ); |
|
|
|
|
}; |
|
|
|
|
for( int iPad = 0; iPad < 2; ++iPad ) |
|
|
|
|
{ |
|
|
|
|
for( int iPanel = 0; iPanel < 9; ++iPanel ) |
|
|
|
|
{ |
|
|
|
|
bool bLight = iPanel == iPanelToLight && iPad == 0; |
|
|
|
|
if( !bLight ) |
|
|
|
|
public: |
|
|
|
|
bool OnUserCreate() override |
|
|
|
|
{ |
|
|
|
|
// We're not lighting this panel, so append black for the 4x4 and 3x3 lights.
|
|
|
|
|
for( int iLED = 0; iLED < 25; ++iLED ) |
|
|
|
|
addColor( 0, 0, 0 ); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Append light data for the outer 4x4 grid of lights.
|
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0xFF, 0xFF, 0 ); |
|
|
|
|
addColor( 0xFF, 0xFF, 0 ); |
|
|
|
|
addColor( 0xFF, 0xFF, 0 ); |
|
|
|
|
addColor( 0xFF, 0xFF, 0 ); |
|
|
|
|
|
|
|
|
|
// Append light data for the inner 3x3 grid of lights, if present. These
|
|
|
|
|
// are ignored if the platform doesn't have them.
|
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0xFF, 0, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0xFF, 0 ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
addColor( 0, 0, 0xFF ); |
|
|
|
|
} |
|
|
|
|
SMX_Start( SMXStateChangedCallback, this ); |
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SMX_SetLights2( sLightsData.data(), sLightsData.size() ); |
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
|
{ |
|
|
|
|
// called once per frame
|
|
|
|
|
for (int x = 0; x < ScreenWidth(); x++) |
|
|
|
|
for (int y = 0; y < ScreenHeight(); y++) |
|
|
|
|
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255));
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
InputSample demo; |
|
|
|
|
|
|
|
|
|
// Loop forever for this sample.
|
|
|
|
|
while(1) |
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
Sleep(500); |
|
|
|
|
demo.SetLights(); |
|
|
|
|
} |
|
|
|
|
SMX_PGE demo; |
|
|
|
|
if (demo.Construct(256, 240, 4, 4)) |
|
|
|
|
demo.Start(); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|