# pragma once
# include "olcPixelGameEngine.h"
# include "SMX.h"
using namespace olc ;
class PGEX_SMX : public PGEX {
public :
PGEX_SMX ( ) : PGEX ( true ) { } ;
HWButton GetPanel ( Key k , int pad ) const {
std : : cout < < SMX_GetInputState ( pad ) ;
} ;
private :
//SMX "screen" is 12x21
//Each panel is 4x7
static void SMXStateChangedCallback ( int pad , SMXUpdateCallbackReason reason , void * pUser )
{
PGEX_SMX * pSelf = ( PGEX_SMX * ) pUser ;
pSelf - > SMXStateChanged ( pad , reason ) ;
}
static void SMXLogCallback ( const char * log )
{
printf ( " -> %s \n " , log ) ;
}
void SMXStateChanged ( int pad , SMXUpdateCallbackReason reason )
{
printf ( " Device %i state changed: %04x \n " , pad , SMX_GetInputState ( pad ) ) ;
}
virtual void OnAfterUserCreate ( ) override {
SMX_Start ( SMXStateChangedCallback , this ) ;
} ;
virtual void OnAfterUserUpdate ( float fElapsedTime ) override {
std : : string lightData ;
//The light data for an SMX dance pad is outlined in the docs but the code used to transform the PGE's pixels to SMX pad's lights will be annotated here.
//Both pads receive data sequentially, and for now we can mimic the data on both ends.
for ( int pad = 0 ; pad < 2 ; pad + + ) {
for ( int i = 0 ; i < 9 ; i + + ) {
int row = 0 ;
for ( int y = i / 3 * 7 ; y < i / 3 * 7 + 7 ; y + = 2 ) {
int col = 0 ;
for ( int x = i % 3 * 4 ; x < i % 3 * 4 + 4 ; x + + ) {
if ( row % 2 = = 1 & & col % 4 = = 0 ) {
col + + ;
continue ;
}
Pixel p ( pge - > GetDrawTarget ( ) - > GetPixel ( x , y ) ) ;
lightData . append ( 1 , p . r ) ;
lightData . append ( 1 , p . g ) ;
lightData . append ( 1 , p . b ) ;
col + + ;
}
row + = 2 ;
}
row = 1 ;
for ( int y = i / 3 * 7 + 1 ; y < i / 3 * 7 + 7 ; y + = 2 ) {
int col = 0 ;
for ( int x = i % 3 * 4 ; x < i % 3 * 4 + 4 ; x + + ) {
if ( row % 2 = = 1 & & col % 4 = = 0 ) {
col + + ;
continue ;
}
Pixel p ( pge - > GetDrawTarget ( ) - > GetPixel ( x , y ) ) ;
lightData . append ( 1 , p . r ) ;
lightData . append ( 1 , p . g ) ;
lightData . append ( 1 , p . b ) ;
col + + ;
}
row + = 2 ;
}
}
}
SMX_SetLights2 ( lightData . data ( ) , lightData . size ( ) ) ;
}
} ;