diff --git a/src/CMakeData-arch.cmake b/src/CMakeData-arch.cmake index 4804c3766b..d16968c4a5 100644 --- a/src/CMakeData-arch.cmake +++ b/src/CMakeData-arch.cmake @@ -179,12 +179,14 @@ source_group("Arch Specific\\\\Loading Window" list(APPEND SMDATA_ARCH_LIGHTS_SRC "arch/Lights/LightsDriver.cpp" "arch/Lights/LightsDriver_Export.cpp" "arch/Lights/LightsDriver_SextetStream.cpp" - "arch/Lights/LightsDriver_SystemMessage.cpp") + "arch/Lights/LightsDriver_SystemMessage.cpp" + "arch/Lights/LightsDriver_HidBlueDot.cpp") list(APPEND SMDATA_ARCH_LIGHTS_HPP "arch/Lights/LightsDriver.h" "arch/Lights/LightsDriver_Export.h" "arch/Lights/LightsDriver_SextetStream.h" "arch/Lights/LightsDriver_SystemMessage.h" - "arch/Lights/SextetUtils.h") + "arch/Lights/SextetUtils.h" + "arch/Lights/LightsDriver_HidBlueDot.h") # TODO: Confirm if Apple can use the export. if(NOT APPLE) diff --git a/src/arch/Lights/LightsDriver_HidBlueDot.cpp b/src/arch/Lights/LightsDriver_HidBlueDot.cpp new file mode 100644 index 0000000000..7ff7993cb6 --- /dev/null +++ b/src/arch/Lights/LightsDriver_HidBlueDot.cpp @@ -0,0 +1,74 @@ +#include "global.h" +#include "RageLog.h" +#include "LightsDriver_HidBlueDot.h" + +REGISTER_LIGHTS_DRIVER_CLASS(HidBlueDot); + +LightsDriver_HidBlueDot::LightsDriver_HidBlueDot() +{ + memset(m_iCabData, 0x00, sizeof(m_iCabData)); + memset(m_iPadData, 0x00, sizeof(m_iPadData)); + + m_iCabData[1] = 0x01; + m_iPadData[1] = 0x02; + + // Open the device using the VID, PID, + // and optionally the Serial number. + handle = hid_open(VID, PID, NULL); + + if (!handle) { + LOG->Warn("HID BlueDot device not found."); + hid_exit(); + return; + } +} + +LightsDriver_HidBlueDot::~LightsDriver_HidBlueDot() +{ + // Close the device + hid_close(handle); + + // Finalize the hidapi library + hid_exit(); +} + +void LightsDriver_HidBlueDot::SetPadLight(PadLightIndex index, bool value) +{ + m_iPadData[2] &= ~(1 << index); + m_iPadData[2] |= (1 << index); +}; + +void LightsDriver_HidBlueDot::SetCabinetLight(CabinetLightIndex index, bool value) +{ + m_iCabData[2] &= ~(1 << index); + m_iCabData[2] |= (1 << index); +}; + +void LightsDriver_HidBlueDot::Set(const LightsState *ls) +{ + if (!handle) + return; + + //! Set cabinet lights. + SetCabinetLight(m_Marquee_UpLeft, ls->m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT]); + SetCabinetLight(m_Marquee_UpRight, ls->m_bCabinetLights[LIGHT_MARQUEE_UP_RIGHT]); + SetCabinetLight(m_Marquee_LwLeft, ls->m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT]); + SetCabinetLight(m_Marquee_LwRight, ls->m_bCabinetLights[LIGHT_MARQUEE_LR_RIGHT]); + SetCabinetLight(m_Buttons_Left, ls->m_bGameButtonLights[PLAYER_1][GAME_BUTTON_START]); + SetCabinetLight(m_Buttons_Right, ls->m_bGameButtonLights[PLAYER_2][GAME_BUTTON_START]); + SetCabinetLight(m_Bass, ls->m_bCabinetLights[LIGHT_BASS_LEFT] || ls->m_bCabinetLights[LIGHT_BASS_RIGHT]); + + hid_write(handle, (unsigned char *)&m_iCabData, 3); + + //! Set pad lights. + SetPadLight(m_PadP1_Left, ls->m_bGameButtonLights[PLAYER_1][DANCE_BUTTON_LEFT]); + SetPadLight(m_PadP1_Right, ls->m_bGameButtonLights[PLAYER_1][DANCE_BUTTON_RIGHT]); + SetPadLight(m_PadP1_Up, ls->m_bGameButtonLights[PLAYER_1][DANCE_BUTTON_UP]); + SetPadLight(m_PadP1_Down, ls->m_bGameButtonLights[PLAYER_1][DANCE_BUTTON_DOWN]); + SetPadLight(m_PadP2_Left, ls->m_bGameButtonLights[PLAYER_2][DANCE_BUTTON_LEFT]); + SetPadLight(m_PadP2_Right, ls->m_bGameButtonLights[PLAYER_2][DANCE_BUTTON_RIGHT]); + SetPadLight(m_PadP2_Up, ls->m_bGameButtonLights[PLAYER_2][DANCE_BUTTON_UP]); + SetPadLight(m_PadP2_Down, ls->m_bGameButtonLights[PLAYER_2][DANCE_BUTTON_DOWN]); + + hid_write(handle, (unsigned char *)&m_iPadData, 3); +} diff --git a/src/arch/Lights/LightsDriver_HidBlueDot.h b/src/arch/Lights/LightsDriver_HidBlueDot.h new file mode 100644 index 0000000000..0738f7bd56 --- /dev/null +++ b/src/arch/Lights/LightsDriver_HidBlueDot.h @@ -0,0 +1,49 @@ +#ifndef LightsDriver_HidBlueDot_H +#define LightsDriver_HidBlueDot_H + +#include "arch/Lights/LightsDriver.h" +#include "hidapi.h" + +#define VID 0x04BD +#define PID 0xBD + +class LightsDriver_HidBlueDot : public LightsDriver +{ +private: + enum CabinetLightIndex + { + m_Marquee_UpLeft = 0x01, + m_Marquee_UpRight = 0x02, + m_Marquee_LwLeft = 0x04, + m_Marquee_LwRight = 0x08, + m_Buttons_Left = 0x10, + m_Buttons_Right = 0x20, + m_Bass = 0x40, + }; + + enum PadLightIndex + { + m_PadP1_Up = 0x01, + m_PadP1_Down = 0x02, + m_PadP1_Left = 0x04, + m_PadP1_Right = 0x08, + m_PadP2_Up = 0x10, + m_PadP2_Down = 0x20, + m_PadP2_Left = 0x40, + m_PadP2_Right = 0x80 + }; + + uint8_t m_iCabData[3]; + uint8_t m_iPadData[3]; + hid_device* handle; + + void SetPadLight(PadLightIndex index, bool value); + void SetCabinetLight(CabinetLightIndex index, bool value); +public: + LightsDriver_HidBlueDot(); + virtual ~LightsDriver_HidBlueDot(); + + virtual void Set( const LightsState *ls ); +}; + +#endif