From 033f6edff55932e55e47b98b64ecd5d0684aa819 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 16 Jun 2023 22:22:26 -0500 Subject: [PATCH] Implement panel checking. --- sample/PGEX_SMX.h | 73 +++++++++++++++++++++++++++++++++---- sample/PGEX_SMX_Example.cpp | 1 - 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/sample/PGEX_SMX.h b/sample/PGEX_SMX.h index e169828..0b8bd53 100644 --- a/sample/PGEX_SMX.h +++ b/sample/PGEX_SMX.h @@ -4,15 +4,26 @@ using namespace olc; - class PGEX_SMX : public PGEX{ - public: - PGEX_SMX():PGEX(true){}; + PGEX_SMX():PGEX(true){ + + }; + //UP is 0x2 + //RIGHT is 0x20 + //DOWN is 0x80 + //LEFT is 0x08 + //Add these bytes together to get the combination (all 4 held down is 0xAA HWButton GetPanel(Key k,int pad)const{ - std::cout< %s\n", log); + if(logMessages){ + printf("-> %s\n", log); + } } + //The key enums are UP, DOWN, LEFT, RIGHT. void SMXStateChanged(int pad, SMXUpdateCallbackReason reason) { - printf("Device %i state changed: %04x\n", pad, SMX_GetInputState(pad)); - + if(logMessages){ + printf("Device %i state changed: %04x\n", pad, SMX_GetInputState(pad)); + } + int16_t state(SMX_GetInputState(pad)); + if(state&0x2&&!internal_panelState[UP-UP].bPressed){ + internal_panelState[UP-UP]={true,false,true}; + }else + if(!(state&0x2)&&!internal_panelState[UP-UP].bReleased){ + internal_panelState[UP-UP]={false,true,false}; + } + if(state&0x20&&!internal_panelState[RIGHT-UP].bPressed){ + internal_panelState[RIGHT-UP]={true,false,true}; + }else + if(!(state&0x20)&&!internal_panelState[RIGHT-UP].bReleased){ + internal_panelState[RIGHT-UP]={false,true,false}; + } + if(state&0x80&&!internal_panelState[DOWN-UP].bPressed){ + internal_panelState[DOWN-UP]={true,false,true}; + }else + if(!(state&0x80)&&!internal_panelState[DOWN-UP].bReleased){ + internal_panelState[DOWN-UP]={false,true,false}; + } + if(state&0x8&&!internal_panelState[LEFT-UP].bPressed){ + internal_panelState[LEFT-UP]={true,false,true}; + }else + if(!(state&0x8)&&!internal_panelState[LEFT-UP].bReleased){ + internal_panelState[LEFT-UP]={false,true,false}; + } } virtual void OnAfterUserCreate()override{ SMX_Start( SMXStateChangedCallback, this ); }; + virtual bool OnBeforeUserUpdate(float& fElapsedTime){ + //We don't want the panel states changing in the middle of a frame, since the input polling is on a separate thread. + //Copy over the internal button states to the current panel state. + for(int i=0;i<4;i++){ + panelState[i]=internal_panelState[i]; + internal_panelState[i].bPressed=false; + internal_panelState[i].bReleased=false; + } + return true; + } + virtual void OnAfterUserUpdate(float fElapsedTime)override{ + for(int i=0;i<4;i++){ + panelState[i].bPressed=false; + panelState[i].bReleased=false; + } 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. @@ -78,4 +133,6 @@ private: } SMX_SetLights2( lightData.data(), lightData.size() ); } -}; \ No newline at end of file +}; + +bool PGEX_SMX::logMessages=false; \ No newline at end of file diff --git a/sample/PGEX_SMX_Example.cpp b/sample/PGEX_SMX_Example.cpp index b5039fc..311cd4e 100644 --- a/sample/PGEX_SMX_Example.cpp +++ b/sample/PGEX_SMX_Example.cpp @@ -21,7 +21,6 @@ public: bool OnUserUpdate(float fElapsedTime) override { - smx.GetPanel(RIGHT,0).bHeld; // called once per frame for (int x = 0; x < ScreenWidth(); x++) for (int y = 0; y < ScreenHeight(); y++)