From 2c708d0086bec6ca24301306aca42427520a222f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 29 Aug 2014 20:36:43 -0400 Subject: [PATCH 1/3] add PIUIO_Leds driver The mappings in this driver are specific to the piuio kernel driver, but once lights mapping is possible this could be made into a generic leds class driver. --- src/Makefile.am | 3 +- .../Lights/LightsDriver_Linux_PIUIO_Leds.cpp | 155 ++++++++++++++++++ .../Lights/LightsDriver_Linux_PIUIO_Leds.h | 42 +++++ 3 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp create mode 100644 src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h diff --git a/src/Makefile.am b/src/Makefile.am index b1c3be4934..e74dc76ce1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -299,7 +299,8 @@ if LINUX arch/InputHandler/InputHandler_Linux_PIUIO.cpp arch/InputHandler/InputHandler_Linux_PIUIO.h Lights += arch/Lights/LightsDriver_LinuxWeedTech.cpp arch/Lights/LightsDriver_LinuxWeedTech.h \ - arch/Lights/LightsDriver_Linux_PIUIO.cpp arch/Lights/LightsDriver_Linux_PIUIO.h + arch/Lights/LightsDriver_Linux_PIUIO.cpp arch/Lights/LightsDriver_Linux_PIUIO.h \ + arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp arch/Lights/LightsDriver_Linux_PIUIO_Leds.h MemoryCard += arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp arch/MemoryCard/MemoryCardDriverThreaded_Linux.h diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp new file mode 100644 index 0000000000..47b65843c9 --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp @@ -0,0 +1,155 @@ +#include "global.h" +#include +#include +#include +#include +#include +#include +#include "LightsDriver_Linux_PIUIO_Leds.h" +#include "GameState.h" +#include "Game.h" +#include "RageLog.h" + +REGISTER_SOUND_DRIVER_CLASS2(PIUIO_Leds, Linux_PIUIO_Leds); + +namespace { + const char *cabinet_leds[NUM_CabinetLight] = { + "/sys/class/leds/piuio::output23", + "/sys/class/leds/piuio::output26", + "/sys/class/leds/piuio::output25", + "/sys/class/leds/piuio::output24", + "/sys/class/leds/piuio::output10", + "/sys/class/leds/piuio::output10", + }; + + const char *dance_leds[NUM_GameController][NUM_GameButton] = { + { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "/sys/class/leds/piuio::output20", + "/sys/class/leds/piuio::output21", + "/sys/class/leds/piuio::output18", + "/sys/class/leds/piuio::output19", + }, + { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "/sys/class/leds/piuio::output4", + "/sys/class/leds/piuio::output5", + "/sys/class/leds/piuio::output2", + "/sys/class/leds/piuio::output3", + }, + }; + + const char *pump_leds[NUM_GameController][NUM_GameButton] = { + { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "/sys/class/leds/piuio::output2", + "/sys/class/leds/piuio::output3", + "/sys/class/leds/piuio::output4", + "/sys/class/leds/piuio::output5", + "/sys/class/leds/piuio::output6", + }, + { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "/sys/class/leds/piuio::output18", + "/sys/class/leds/piuio::output19", + "/sys/class/leds/piuio::output20", + "/sys/class/leds/piuio::output21", + "/sys/class/leds/piuio::output22", + }, + }; + + bool SetLight(const char *filename, bool on) + { + FILE *f = fopen(filename, "w"); + if (f == NULL) + { + return false; + } + fprintf(f, "%d", on ? 255 : 0); + fclose(f); + return true; + } +} + +LightsDriver_Linux_PIUIO_Leds::LightsDriver_Linux_PIUIO_Leds() +{ +} + +LightsDriver_Linux_PIUIO_Leds::~LightsDriver_Linux_PIUIO_Leds() +{ +} + +void LightsDriver_Linux_PIUIO_Leds::Set( const LightsState *ls ) +{ + FOREACH_CabinetLight(light) + { + if (!SetLight(cabinet_leds[light], ls->m_bCabinetLights[light])) + { + LOG->Warn("Error setting cabinet light %s", + CabinetLightToString(light).c_str()); + return; + } + } + + const InputScheme *pInput = &GAMESTATE->GetCurrentGame()->m_InputScheme; + RString sInputName = pInput->m_szName; + if (sInputName.EqualsNoCase("dance")) + { + FOREACH_ENUM(GameController, c) + { + FOREACH_GameButton_Custom(gb) + { + 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 (!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; + } +} + +/* + * (c) 2014 StepMania team + * 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. + */ diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h new file mode 100644 index 0000000000..f5f0cfab0f --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.h @@ -0,0 +1,42 @@ +/* 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" + +class LightsDriver_Linux_PIUIO_Leds : public LightsDriver +{ +public: + LightsDriver_Linux_PIUIO_Leds(); + virtual ~LightsDriver_Linux_PIUIO_Leds(); + + virtual void Set( const LightsState *ls ); +}; + +#endif + +/* + * (c) 2014 StepMania team + * 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. + */ From 7a4c107e1a6870bf9e5a10ceed56187c86bd728c Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 29 Aug 2014 21:53:06 -0400 Subject: [PATCH 2/3] don't set lights for nonexistent lights duh. --- src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp index 47b65843c9..e72121417a 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp @@ -60,6 +60,8 @@ namespace { bool SetLight(const char *filename, bool on) { + if (filename == NULL) + return true; FILE *f = fopen(filename, "w"); if (f == NULL) { From b8122e6e50712596fad801ff101e2fc50fb9e31c Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 29 Aug 2014 21:53:22 -0400 Subject: [PATCH 3/3] point at the right file in the filesystem --- .../Lights/LightsDriver_Linux_PIUIO_Leds.cpp | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp index e72121417a..78f7285d54 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp @@ -14,47 +14,47 @@ REGISTER_SOUND_DRIVER_CLASS2(PIUIO_Leds, Linux_PIUIO_Leds); namespace { const char *cabinet_leds[NUM_CabinetLight] = { - "/sys/class/leds/piuio::output23", - "/sys/class/leds/piuio::output26", - "/sys/class/leds/piuio::output25", - "/sys/class/leds/piuio::output24", - "/sys/class/leds/piuio::output10", - "/sys/class/leds/piuio::output10", + "/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", }; const char *dance_leds[NUM_GameController][NUM_GameButton] = { { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "/sys/class/leds/piuio::output20", - "/sys/class/leds/piuio::output21", - "/sys/class/leds/piuio::output18", - "/sys/class/leds/piuio::output19", + "/sys/class/leds/piuio::output20/brightness", + "/sys/class/leds/piuio::output21/brightness", + "/sys/class/leds/piuio::output18/brightness", + "/sys/class/leds/piuio::output19/brightness", }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "/sys/class/leds/piuio::output4", - "/sys/class/leds/piuio::output5", - "/sys/class/leds/piuio::output2", - "/sys/class/leds/piuio::output3", + "/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 char *pump_leds[NUM_GameController][NUM_GameButton] = { { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "/sys/class/leds/piuio::output2", - "/sys/class/leds/piuio::output3", - "/sys/class/leds/piuio::output4", - "/sys/class/leds/piuio::output5", - "/sys/class/leds/piuio::output6", + "/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", }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "/sys/class/leds/piuio::output18", - "/sys/class/leds/piuio::output19", - "/sys/class/leds/piuio::output20", - "/sys/class/leds/piuio::output21", - "/sys/class/leds/piuio::output22", + "/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", }, };