diff --git a/src/CMakeData-arch.cmake b/src/CMakeData-arch.cmake index f388a0b72b..62e2260d37 100644 --- a/src/CMakeData-arch.cmake +++ b/src/CMakeData-arch.cmake @@ -229,6 +229,7 @@ if(NOT APPLE) if(LINUX) list(APPEND SMDATA_LINK_LIB "udev") list(APPEND SMDATA_ARCH_LIGHTS_SRC + "arch/Lights/LightsDriver_Linux_Leds.cpp" "arch/Lights/LightsDriver_Linux_PIUIO.cpp" "arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp" "arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.cpp" @@ -236,6 +237,7 @@ if(NOT APPLE) "arch/Lights/LightsDriver_Linux_stac.cpp" "arch/Lights/LightsDriver_LinuxWeedTech.cpp") list(APPEND SMDATA_ARCH_LIGHTS_HPP + "arch/Lights/LightsDriver_Linux_Leds.h" "arch/Lights/LightsDriver_Linux_PIUIO.h" "arch/Lights/LightsDriver_Linux_PIUIO_Leds.h" "arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.h" diff --git a/src/arch/Lights/LightsDriver_Linux_ITGIO.cpp b/src/arch/Lights/LightsDriver_Linux_ITGIO.cpp index 21c4ab6c2b..f00786bb8e 100644 --- a/src/arch/Lights/LightsDriver_Linux_ITGIO.cpp +++ b/src/arch/Lights/LightsDriver_Linux_ITGIO.cpp @@ -18,121 +18,100 @@ REGISTER_LIGHTS_DRIVER_CLASS2(ITGIO, Linux_ITGIO); -//NOTE: light index 14 is not mapped, this is the coin drop "light" +//NOTE: light index 14 is not mapped, +//this is the coin drop "light" to increment the coin counter. -namespace { - const char *cabinet_leds[NUM_CabinetLight] = { - //UL, UR, LL, LR, Bass L, Bass R - "/sys/class/leds/itgio::output8/brightness", - "/sys/class/leds/itgio::output10/brightness", - "/sys/class/leds/itgio::output9/brightness", - "/sys/class/leds/itgio::output11/brightness", - "/sys/class/leds/itgio::output15/brightness", - "/sys/class/leds/itgio::output15/brightness", +namespace +{ + const int cabinet_lights[NUM_CabinetLight] = { + 8, //LIGHT_MARQUEE_UP_LEFT + 10, //LIGHT_MARQUEE_UP_RIGHT + 9, //LIGHT_MARQUEE_LR_LEFT + 11, //LIGHT_MARQUEE_LR_RIGHT + 15, //LIGHT_BASS_LEFT + 15, //LIGHT_BASS_RIGHT }; - const char *dance_leds[NUM_GameController][NUM_GameButton] = { - { - nullptr, nullptr, nullptr, nullptr, - //player start - "/sys/class/leds/itgio::output13/brightness", - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - //left right up down - "/sys/class/leds/itgio::output1/brightness", - "/sys/class/leds/itgio::output0/brightness", - "/sys/class/leds/itgio::output3/brightness", - "/sys/class/leds/itgio::output2/brightness", - }, - { - nullptr, nullptr, nullptr, nullptr, - //player start - "/sys/class/leds/itgio::output12/brightness", - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - //left right up down - "/sys/class/leds/itgio::output5/brightness", - "/sys/class/leds/itgio::output4/brightness", - "/sys/class/leds/itgio::output7/brightness", - "/sys/class/leds/itgio::output6/brightness", - }, + const int player1_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + 13, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 1, //GAME_BUTTON_CUSTOM_01 + 0, //GAME_BUTTON_CUSTOM_02 + 3, //GAME_BUTTON_CUSTOM_03 + 2, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 }; - bool SetLight(const char *filename, bool on) - { - if (filename == nullptr) - return true; - FILE *f = fopen(filename, "w"); - if (f == nullptr) - { - return false; - } - fprintf(f, "%d", on ? 255 : 0); - fclose(f); - return true; - } -} + const int player2_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + 12, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 5, //GAME_BUTTON_CUSTOM_01 + 4, //GAME_BUTTON_CUSTOM_02 + 7, //GAME_BUTTON_CUSTOM_03 + 6, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 + }; -LightsDriver_Linux_ITGIO::LightsDriver_Linux_ITGIO() +} // namespace + +void LightsDriver_Linux_ITGIO::Set(const LightsState *ls) { -} + SetCabinetLights(cabinet_lights, ls); -LightsDriver_Linux_ITGIO::~LightsDriver_Linux_ITGIO() -{ -} - -void LightsDriver_Linux_ITGIO::SetGameControllerLight(const LightsState *ls, GameController c, GameButton gb) -{ - //only push a change in the light iff it's an actual change. - if (ls->m_bGameButtonLights[c][gb] == previousLS.m_bGameButtonLights[c][gb]) - { - return; - } - - if (!SetLight(dance_leds[c][gb], ls->m_bGameButtonLights[c][gb])) - { - //grab the game info for a proper debug log. - const InputScheme *pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; - RString sInputName = pInput->m_szName; - - LOG->Warn("Error setting button light %s", GameButtonToString(pInput, gb).c_str()); - } -} - -void LightsDriver_Linux_ITGIO::Set( const LightsState *ls ) -{ - FOREACH_CabinetLight(light) - { - // Only SetLight if LightsState has changed since previous iteration. - // This reduces unncessary strain on udev. -dguzek - if (ls->m_bCabinetLights[light] == previousLS.m_bCabinetLights[light] ) - { - continue; - } - - if (!SetLight(cabinet_leds[light], ls->m_bCabinetLights[light])) - { - LOG->Warn("Error setting cabinet light %s", - CabinetLightToString(light).c_str()); - return; - } - } - - FOREACH_ENUM(GameController, c) - { - //takes care of each of the player buttons (UDLR) - FOREACH_GameButton_Custom(gb) - { - SetGameControllerLight(ls, c, gb); - } - - //Takes care of the cabinet based player lights. - SetGameControllerLight(ls, c, GAME_BUTTON_START); - } + SetGameControllerLights(GameController_1, player1_lights, ls); + SetGameControllerLights(GameController_2, player1_lights, ls); previousLS = *ls; } /* - * (c) 2020 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -154,4 +133,6 @@ void LightsDriver_Linux_ITGIO::Set( const LightsState *ls ) * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_ITGIO.h b/src/arch/Lights/LightsDriver_Linux_ITGIO.h index b5131b05ec..b5404ba85b 100644 --- a/src/arch/Lights/LightsDriver_Linux_ITGIO.h +++ b/src/arch/Lights/LightsDriver_Linux_ITGIO.h @@ -1,27 +1,26 @@ -/* LightsDriver_Linux_ITGIO: Control ITGIO lights via /sys/class/leds */ - #ifndef LightsDriver_Linux_ITGIO_H #define LightsDriver_Linux_ITGIO_H -#include "arch/Lights/LightsDriver.h" +#include "arch/Lights/LightsDriver_Linux_Leds.h" -class LightsDriver_Linux_ITGIO : public LightsDriver +class LightsDriver_Linux_ITGIO : public LightsDriver_Linux_Leds { -private: - LightsState previousLS; - void SetGameControllerLight(const LightsState *ls, GameController c, GameButton gb); - public: - LightsDriver_Linux_ITGIO(); - virtual ~LightsDriver_Linux_ITGIO(); + LightsDriver_Linux_ITGIO() {} + virtual ~LightsDriver_Linux_ITGIO() {} - virtual void Set( const LightsState *ls ); + virtual void Set(const LightsState *ls); + + virtual const char *GetGameControllerLightFile() + { + return "/sys/class/leds/itgio::output%d/brightness"; + } }; #endif /* - * (c) 2020 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -43,4 +42,6 @@ public: * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_Leds.cpp new file mode 100644 index 0000000000..583d3e5373 --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_Leds.cpp @@ -0,0 +1,163 @@ +#include "global.h" +#include +#if defined(HAVE_UNISTD_H) +#include +#endif +#include +#include + +#if defined(HAVE_FCNTL_H) +#include +#endif + +#include +#include "LightsDriver_Linux_Leds.h" +#include "GameState.h" +#include "Game.h" +#include "RageLog.h" + +bool LightsDriver_Linux_Leds::WriteLight(const char *filename, bool state) +{ + //if we are setting a light that doesn't exist, let the caller know the function was a "success" + //nullptr is used to define that the stepmania light is not mapped by the caller. + if (filename == nullptr) + { + return true; + } + + //LOG->Trace("LED: %s -> %d", filename, state); + + FILE *f = fopen(filename, "w"); + + //if the filename should exist, but doesn't, let the caller know of the failure (if desired) and log it. + if (f == nullptr) + { + LOG->Warn("Failed to set Linux_Led at %s. Check device permissions or udev rules. errno: %d: %s", + filename, errno, strerror(errno)); + return false; + } + + //write and close the file. + fprintf(f, "%d", state ? LINUX_LED_STATE_ON : LINUX_LED_STATE_OFF); + fclose(f); + + return true; +} + +bool LightsDriver_Linux_Leds::IsDance() +{ + pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; + sInputName = pInput->m_szName; + + return sInputName.EqualsNoCase("dance"); +} + +bool LightsDriver_Linux_Leds::IsPump() +{ + pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; + sInputName = pInput->m_szName; + + return sInputName.EqualsNoCase("pump"); +} + +void LightsDriver_Linux_Leds::SetLight(const char *filename, bool previous, bool desired) +{ + //don't overload the linux system if the light has not been changed. + if (previous != desired) + { + WriteLight(filename, desired); + } +} + +void LightsDriver_Linux_Leds::SetCabinetLights(const char *stringArray[], const LightsState *ls) +{ + FOREACH_CabinetLight(light) + { + SetLight(stringArray[light], previousLS.m_bCabinetLights[light], ls->m_bCabinetLights[light]); + } +} + +void LightsDriver_Linux_Leds::SetCabinetLights(const int intArray[], const LightsState *ls) +{ + const char *baseFileLocation = GetGameControllerLightFile(); + + if (baseFileLocation != nullptr) + { + char fileName[LINUX_LED_MAX_DIRECTORY_LENGTH]; + + FOREACH_CabinetLight(light) + { + //valid lights are zero and positive. + if (intArray[light] >= 0) + { + //don't waste sprintf time if we don't need to change the light + if (previousLS.m_bCabinetLights[light] != ls->m_bCabinetLights[light]) + { + sprintf(fileName, baseFileLocation, intArray[light]); + SetLight(fileName, previousLS.m_bCabinetLights[light], ls->m_bCabinetLights[light]); + } + } + } + } +} + +void LightsDriver_Linux_Leds::SetGameControllerLights(GameController gc, const char *stringArray[], const LightsState *ls) +{ + //iterate over all gamebuttons, including the menu/start/etc buttons. + FOREACH_ENUM(GameButton, gb) + { + SetLight(stringArray[gb], previousLS.m_bGameButtonLights[gc][gb], ls->m_bGameButtonLights[gc][gb]); + } +} + +void LightsDriver_Linux_Leds::SetGameControllerLights(GameController gc, const int intArray[], const LightsState *ls) +{ + const char *baseFileLocation = GetGameControllerLightFile(); + + if (baseFileLocation != nullptr) + { + char fileName[LINUX_LED_MAX_DIRECTORY_LENGTH]; + + //iterate over all gamebuttons, including the menu/start/etc buttons. + FOREACH_ENUM(GameButton, gb) + { + //valid lights are zero and positive. + if (intArray[gb] >= 0) + { + //don't waste sprintf time if we don't need to change the light + if (previousLS.m_bGameButtonLights[gc][gb] != ls->m_bGameButtonLights[gc][gb]) + { + sprintf(fileName, baseFileLocation, intArray[gb]); + SetLight(fileName, previousLS.m_bGameButtonLights[gc][gb], ls->m_bGameButtonLights[gc][gb]); + } + } + } + } +} + +/* + * (c) 2020 din + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * i love lamp + */ diff --git a/src/arch/Lights/LightsDriver_Linux_Leds.h b/src/arch/Lights/LightsDriver_Linux_Leds.h new file mode 100644 index 0000000000..1d379e245d --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_Leds.h @@ -0,0 +1,66 @@ +/* LightsDriver_Linux_Leds: Control Linux system lights via /sys/class/leds */ + +#ifndef LightsDriver_Linux_Leds_H +#define LightsDriver_Linux_Leds_H + +#include "arch/Lights/LightsDriver.h" + +class LightsDriver_Linux_Leds : public LightsDriver +{ +private: + static const uint8_t LINUX_LED_STATE_ON = 255; + static const uint8_t LINUX_LED_STATE_OFF = 0; + static const int LINUX_LED_MAX_DIRECTORY_LENGTH = PATH_MAX; + + const InputScheme *pInput; + RString sInputName; + + bool WriteLight(const char *filename, bool state); + +protected: + LightsState previousLS; + + bool IsDance(); + bool IsPump(); + + void SetLight(const char *filename, bool previous, bool desired); + + void SetCabinetLights(const char *stringArray[], const LightsState *ls); + void SetCabinetLights(const int intArray[], const LightsState *ls); + + void SetGameControllerLights(GameController gc, const char *stringArray[], const LightsState *ls); + void SetGameControllerLights(GameController gc, const int intArray[], const LightsState *ls); + +public: + virtual void Set(const LightsState *ls) = 0; + virtual const char *GetGameControllerLightFile() = 0; +}; + +#endif + +/* + * (c) 2020 din + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * i love lamp + */ diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.cpp index 68729ec9e5..eea60a7e4e 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.cpp @@ -10,6 +10,7 @@ #include #endif +#include #include "LightsDriver_Linux_PIUIOBTN_Leds.h" #include "GameState.h" #include "Game.h" @@ -17,75 +18,85 @@ REGISTER_LIGHTS_DRIVER_CLASS2(PIUIOBTN_Leds, Linux_PIUIOBTN_Leds); -namespace { - const char *game_btn_leds[NUM_GameController][NUM_GameButton] = { - { - "/sys/class/leds/piuio::bboutput6/brightness", //P1 GAME_BUTTON_MENULEFT - "/sys/class/leds/piuio::bboutput5/brightness", //P1 GAME_BUTTON_MENURIGHT - nullptr, nullptr, - "/sys/class/leds/piuio::bboutput4/brightness", //P1 GAME_BUTTON_START - "/sys/class/leds/piuio::bboutput7/brightness", //P1 GAME_BUTTON_SELECT - }, - { - "/sys/class/leds/piuio::bboutput2/brightness", //P2 GAME_BUTTON_MENULEFT - "/sys/class/leds/piuio::bboutput1/brightness", //P2 GAME_BUTTON_MENURIGHT - nullptr, nullptr, - "/sys/class/leds/piuio::bboutput0/brightness", //P2 GAME_BUTTON_START - "/sys/class/leds/piuio::bboutput3/brightness", //P2 GAME_BUTTON_SELECT - }, +namespace +{ + const int player1_lights[NUM_GameButton] = { + 6, //GAME_BUTTON_MENULEFT + 5, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + 4, //GAME_BUTTON_START + 7, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + -1, //GAME_BUTTON_CUSTOM_01 + -1, //GAME_BUTTON_CUSTOM_02 + -1, //GAME_BUTTON_CUSTOM_03 + -1, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 }; - bool SetLight(const char *filename, bool on) - { - if (filename == nullptr) - return true; - FILE *f = fopen(filename, "w"); - if (f == nullptr) - { - return false; - } - fprintf(f, "%d", on ? 255 : 0); - fclose(f); - return true; - } -} + const int player2_lights[NUM_GameButton] = { + 2, //GAME_BUTTON_MENULEFT + 1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + 0, //GAME_BUTTON_START + 3, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + -1, //GAME_BUTTON_CUSTOM_01 + -1, //GAME_BUTTON_CUSTOM_02 + -1, //GAME_BUTTON_CUSTOM_03 + -1, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 + }; +} // namespace -LightsDriver_Linux_PIUIOBTN_Leds::LightsDriver_Linux_PIUIOBTN_Leds() +void LightsDriver_Linux_PIUIOBTN_Leds::Set(const LightsState *ls) { -} - -LightsDriver_Linux_PIUIOBTN_Leds::~LightsDriver_Linux_PIUIOBTN_Leds() -{ -} - -void LightsDriver_Linux_PIUIOBTN_Leds::Set( const LightsState *ls ) -{ - const InputScheme *pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; - RString sInputName = pInput->m_szName; - - FOREACH_ENUM(GameController, c) - { - FOREACH_ENUM( GameButton, gb ) - { - if (ls->m_bGameButtonLights[c][gb] == previousLS.m_bGameButtonLights[c][gb]) - { - continue; - } - - if (!SetLight(game_btn_leds[c][gb], ls->m_bGameButtonLights[c][gb])) - { - LOG->Warn("Error setting button light %s", - GameButtonToString(pInput, gb).c_str()); - return; - } - } - } + SetGameControllerLights(GameController_1, player1_lights, ls); + SetGameControllerLights(GameController_2, player2_lights, ls); previousLS = *ls; } /* - * (c) 2020 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -107,4 +118,6 @@ void LightsDriver_Linux_PIUIOBTN_Leds::Set( const LightsState *ls ) * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.h b/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.h index 157533b37c..37fd24793d 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.h +++ b/src/arch/Lights/LightsDriver_Linux_PIUIOBTN_Leds.h @@ -1,26 +1,26 @@ -/* LightsDriver_Linux_PIUIOBTN_Leds: Control PIUIO Button Board lights via /sys/class/leds */ - #ifndef LightsDriver_Linux_PIUIOBTN_Leds_H #define LightsDriver_Linux_PIUIOBTN_Leds_H -#include "arch/Lights/LightsDriver.h" +#include "arch/Lights/LightsDriver_Linux_Leds.h" -class LightsDriver_Linux_PIUIOBTN_Leds : public LightsDriver +class LightsDriver_Linux_PIUIOBTN_Leds : public LightsDriver_Linux_Leds { -private: - LightsState previousLS; - public: - LightsDriver_Linux_PIUIOBTN_Leds(); - virtual ~LightsDriver_Linux_PIUIOBTN_Leds(); + LightsDriver_Linux_PIUIOBTN_Leds() {} + virtual ~LightsDriver_Linux_PIUIOBTN_Leds() {} - virtual void Set( const LightsState *ls ); + virtual void Set(const LightsState *ls); + + virtual const char *GetGameControllerLightFile() + { + return "/sys/class/leds/piuio::bboutput%d/brightness"; + } }; #endif /* - * (c) 2020 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -42,4 +42,6 @@ public: * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp index 6fac181a50..0bf3d7e7e2 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp @@ -18,146 +18,178 @@ REGISTER_LIGHTS_DRIVER_CLASS2(PIUIO_Leds, Linux_PIUIO_Leds); -namespace { - const char *cabinet_leds[NUM_CabinetLight] = { - "/sys/class/leds/piuio::output23/brightness", - "/sys/class/leds/piuio::output26/brightness", - "/sys/class/leds/piuio::output25/brightness", - "/sys/class/leds/piuio::output24/brightness", - "/sys/class/leds/piuio::output10/brightness", - "/sys/class/leds/piuio::output10/brightness", +//NOTE: front usb ports are off by default, index 27 enables them. +//It is currently unmapped. + +namespace +{ + const int cabinet_lights[NUM_CabinetLight] = { + 23, //LIGHT_MARQUEE_UP_LEFT + 26, //LIGHT_MARQUEE_UP_RIGHT + 25, //LIGHT_MARQUEE_LR_LEFT + 24, //LIGHT_MARQUEE_LR_RIGHT + 10, //LIGHT_BASS_LEFT + 10, //LIGHT_BASS_RIGHT }; - const char *dance_leds[NUM_GameController][NUM_GameButton] = { - { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "/sys/class/leds/piuio::output20/brightness", - "/sys/class/leds/piuio::output21/brightness", - "/sys/class/leds/piuio::output18/brightness", - "/sys/class/leds/piuio::output19/brightness", - }, - { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "/sys/class/leds/piuio::output4/brightness", - "/sys/class/leds/piuio::output5/brightness", - "/sys/class/leds/piuio::output2/brightness", - "/sys/class/leds/piuio::output3/brightness", - }, + const int player1_dance_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + -1, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 20, //GAME_BUTTON_CUSTOM_01 + 21, //GAME_BUTTON_CUSTOM_02 + 18, //GAME_BUTTON_CUSTOM_03 + 19, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 }; - const char *pump_leds[NUM_GameController][NUM_GameButton] = { - { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "/sys/class/leds/piuio::output2/brightness", - "/sys/class/leds/piuio::output3/brightness", - "/sys/class/leds/piuio::output4/brightness", - "/sys/class/leds/piuio::output5/brightness", - "/sys/class/leds/piuio::output6/brightness", - }, - { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "/sys/class/leds/piuio::output18/brightness", - "/sys/class/leds/piuio::output19/brightness", - "/sys/class/leds/piuio::output20/brightness", - "/sys/class/leds/piuio::output21/brightness", - "/sys/class/leds/piuio::output22/brightness", - }, + const int player2_dance_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + -1, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 4, //GAME_BUTTON_CUSTOM_01 + 5, //GAME_BUTTON_CUSTOM_02 + 2, //GAME_BUTTON_CUSTOM_03 + 3, //GAME_BUTTON_CUSTOM_04 + -1, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 }; - bool SetLight(const char *filename, bool on) - { - if (filename == nullptr) - return true; - FILE *f = fopen(filename, "w"); - if (f == nullptr) - { - return false; - } - fprintf(f, "%d", on ? 255 : 0); - fclose(f); - return true; - } -} + const int player1_pump_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + -1, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 2, //GAME_BUTTON_CUSTOM_01 + 3, //GAME_BUTTON_CUSTOM_02 + 4, //GAME_BUTTON_CUSTOM_03 + 5, //GAME_BUTTON_CUSTOM_04 + 6, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 + }; -LightsDriver_Linux_PIUIO_Leds::LightsDriver_Linux_PIUIO_Leds() + const int player2_pump_lights[NUM_GameButton] = { + -1, //GAME_BUTTON_MENULEFT + -1, //GAME_BUTTON_MENURIGHT + -1, //GAME_BUTTON_MENUUP + -1, //GAME_BUTTON_MENUDOWN + -1, //GAME_BUTTON_START + -1, //GAME_BUTTON_SELECT + -1, //GAME_BUTTON_BACK + -1, //GAME_BUTTON_COIN + -1, //GAME_BUTTON_OPERATOR + -1, //GAME_BUTTON_EFFECT_UP + -1, //GAME_BUTTON_EFFECT_DOWN + 18, //GAME_BUTTON_CUSTOM_01 + 19, //GAME_BUTTON_CUSTOM_02 + 20, //GAME_BUTTON_CUSTOM_03 + 21, //GAME_BUTTON_CUSTOM_04 + 22, //GAME_BUTTON_CUSTOM_05 + -1, //GAME_BUTTON_CUSTOM_06 + -1, //GAME_BUTTON_CUSTOM_07 + -1, //GAME_BUTTON_CUSTOM_08 + -1, //GAME_BUTTON_CUSTOM_09 + -1, //GAME_BUTTON_CUSTOM_10 + -1, //GAME_BUTTON_CUSTOM_11 + -1, //GAME_BUTTON_CUSTOM_12 + -1, //GAME_BUTTON_CUSTOM_13 + -1, //GAME_BUTTON_CUSTOM_14 + -1, //GAME_BUTTON_CUSTOM_15 + -1, //GAME_BUTTON_CUSTOM_16 + -1, //GAME_BUTTON_CUSTOM_17 + -1, //GAME_BUTTON_CUSTOM_18 + -1, //GAME_BUTTON_CUSTOM_19 + }; + +} // namespace + +void LightsDriver_Linux_PIUIO_Leds::Set(const LightsState *ls) { -} + SetCabinetLights(cabinet_lights, ls); -LightsDriver_Linux_PIUIO_Leds::~LightsDriver_Linux_PIUIO_Leds() -{ -} - -void LightsDriver_Linux_PIUIO_Leds::Set( const LightsState *ls ) -{ - FOREACH_CabinetLight(light) + //gamemode is checked here as gamemode can change during runtime + //...although I'd be impressed if someone wanted to swap from pump to dance + //on a cabinet without shutting down first... + //...including swapping pads from your pump cabinet to your itg cabinet... + if (IsDance()) { - // Only SetLight if LightsState has changed since previous iteration. - // This reduces unncessary strain on udev. -dguzek - if (ls->m_bCabinetLights[light] == previousLS.m_bCabinetLights[light] ) - { - continue; - } - - if (!SetLight(cabinet_leds[light], ls->m_bCabinetLights[light])) - { - LOG->Warn("Error setting cabinet light %s", - CabinetLightToString(light).c_str()); - return; - } + SetGameControllerLights(GameController_1, player1_dance_lights, ls); + SetGameControllerLights(GameController_2, player1_dance_lights, ls); } - - const InputScheme *pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; - RString sInputName = pInput->m_szName; - if (sInputName.EqualsNoCase("dance")) + else if (IsPump()) { - FOREACH_ENUM(GameController, c) - { - FOREACH_GameButton_Custom(gb) - { - if (ls->m_bGameButtonLights[c][gb] == previousLS.m_bGameButtonLights[c][gb]) - { - continue; - } - - if (!SetLight(dance_leds[c][gb], ls->m_bGameButtonLights[c][gb])) - { - LOG->Warn("Error setting button light %s", - GameButtonToString(pInput, gb).c_str()); - return; - } - } - } - } - else if (sInputName.EqualsNoCase("pump")) - { - FOREACH_ENUM(GameController, c) - { - FOREACH_GameButton_Custom(gb) - { - if (ls->m_bGameButtonLights[c][gb] == previousLS.m_bGameButtonLights[c][gb]) - { - continue; - } - - if (!SetLight(pump_leds[c][gb], ls->m_bGameButtonLights[c][gb])) - { - LOG->Warn("Error setting button light %s", - GameButtonToString(pInput, gb).c_str()); - return; - } - } - } - } - else - { - return; + SetGameControllerLights(GameController_1, player1_pump_lights, ls); + SetGameControllerLights(GameController_2, player1_pump_lights, ls); } previousLS = *ls; } /* - * (c) 2014 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -179,4 +211,6 @@ void LightsDriver_Linux_PIUIO_Leds::Set( const LightsState *ls ) * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h index 83e0935f4f..dddf9ce4b1 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h @@ -1,26 +1,27 @@ -/* LightsDriver_Linux_PIUIO_Leds: Control PIUIO lights via /sys/class/leds */ - #ifndef LightsDriver_Linux_PIUIO_Leds_H #define LightsDriver_Linux_PIUIO_Leds_H -#include "arch/Lights/LightsDriver.h" +#include "arch/Lights/LightsDriver_Linux_Leds.h" -class LightsDriver_Linux_PIUIO_Leds : public LightsDriver +class LightsDriver_Linux_PIUIO_Leds : public LightsDriver_Linux_Leds { -private: - LightsState previousLS; - public: - LightsDriver_Linux_PIUIO_Leds(); - virtual ~LightsDriver_Linux_PIUIO_Leds(); + LightsDriver_Linux_PIUIO_Leds() {} + virtual ~LightsDriver_Linux_PIUIO_Leds() {} - virtual void Set( const LightsState *ls ); + virtual void Set(const LightsState *ls); + + virtual const char *GetGameControllerLightFile() + { + + return "/sys/class/leds/piuio::output%d/brightness"; + } }; #endif /* - * (c) 2014 StepMania team + * (c) 2020 din * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -42,4 +43,6 @@ public: * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. - */ + * + * i love lamp + */ \ No newline at end of file diff --git a/src/arch/Lights/LightsDriver_Linux_stac.h b/src/arch/Lights/LightsDriver_Linux_stac.h index a6dc1f9d4a..a46813dbf1 100644 --- a/src/arch/Lights/LightsDriver_Linux_stac.h +++ b/src/arch/Lights/LightsDriver_Linux_stac.h @@ -4,6 +4,7 @@ #define LightsDriver_Linux_stac_H /* +<<<<<<< ours * -------------------------- NOTE -------------------------- * * This driver needs user read/write access to the icedragon.io stac. @@ -16,6 +17,20 @@ * Refer to your distrobution's documentation on how to properly apply a udev rule. * * -------------------------- NOTE -------------------------- +======= + * -------------------------- NOTE -------------------------- + * + * This driver needs user read/write access to the icedragon.io stac. + * This can be achieved by using a udev rule like this: + * + * (player 1 then player 2) + * SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="eb5b", OWNER="dance", GROUP="dance", MODE="0660" + * SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="eb5a", OWNER="dance", GROUP="dance", MODE="0660" + * + * Refer to your distrobution's documentation on how to properly apply a udev rule. + * + * -------------------------- NOTE -------------------------- +>>>>>>> theirs */ #include "arch/Lights/LightsDriver.h"