From ea8833bf1c916a69c837d78245712c8cf9cca0c4 Mon Sep 17 00:00:00 2001 From: Kevin Slaughter Date: Thu, 8 Jul 2004 11:46:20 +0000 Subject: [PATCH] Weeder Technologies WTDIO-M now fully functioning. --- stepmania/src/Makefile.am | 5 +- stepmania/src/arch/Lights/LightsDriver.cpp | 4 + .../Lights/LightsDriver_LinuxWeedTech.cpp | 180 ++++++++++++++++++ .../arch/Lights/LightsDriver_LinuxWeedTech.h | 2 +- stepmania/src/arch/arch_linux.h | 2 + 5 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index bff2e3eaa8..63a2db8543 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -116,9 +116,8 @@ MovieTexture += arch/MovieTexture/MovieTexture_FFMpeg.cpp arch/MovieTexture/Movi endif Lights = arch/Lights/LightsDriver.cpp arch/Lights/LightsDriver.h \ - arch/Lights/LightsDriver_SystemMessage.cpp arch/Lights/LightsDriver_SystemMessage.h -# arch/Lights/LightsDriver_LinuxWeedTech.cpp arch/Lights/LightsDriver_LinuxWeedTech.h -# arch/Lights/Linux_SerialPort.c arch/Lights/Linux_SerialPort.h + arch/Lights/LightsDriver_SystemMessage.cpp arch/Lights/LightsDriver_SystemMessage.h \ + arch/Lights/LightsDriver_LinuxWeedTech.cpp arch/Lights/LightsDriver_LinuxWeedTech.h MemoryCard = arch/MemoryCard/MemoryCardDriver.cpp arch/MemoryCard/MemoryCardDriver.h \ arch/MemoryCard/MemoryCardDriverThreaded.cpp arch/MemoryCard/MemoryCardDriverThreaded.h diff --git a/stepmania/src/arch/Lights/LightsDriver.cpp b/stepmania/src/arch/Lights/LightsDriver.cpp index 15301cf4af..de91b0b698 100644 --- a/stepmania/src/arch/Lights/LightsDriver.cpp +++ b/stepmania/src/arch/Lights/LightsDriver.cpp @@ -14,6 +14,10 @@ LightsDriver *MakeLightsDriver(CString driver) if(!driver.CompareNoCase("Parallel")) ret = new LightsDriver_Win32Parallel; #endif if(!driver.CompareNoCase("SystemMessage")) ret = new LightsDriver_SystemMessage; + +#ifdef LINUX + if(!driver.CompareNoCase("WeedTech")) ret = new LightsDriver_LinuxWeedTech; +#endif if(!driver.CompareNoCase("Null") || !ret ) { if( driver.CompareNoCase("Null") ) diff --git a/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp b/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp new file mode 100644 index 0000000000..6eb2e85804 --- /dev/null +++ b/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp @@ -0,0 +1,180 @@ +#include "global.h" +#include +#include +#include +#include +#include +#include +#include +#include "LightsDriver_LinuxWeedTech.h" +#include "RageLog.h" + +// Begin serial driver // +static int fd = -1; +static LightsState CurLights; + +inline void SerialClose() +{ + if(fd!=1) {close(fd);} +} + +inline void SerialOut(const char *str, int len) +{ + if(fd!=-1) { + write(fd,str,len); + usleep(4000); + } +} + +inline void SerialOpen() +{ + // Make sure we've not already opened the port + SerialClose(); + + // Open a fresh instance.. + fd = open("/dev/ttyS0", O_WRONLY | O_NOCTTY | O_NDELAY); + if(fd < 0) {LOG->Warn("Error opening serial port for lights. Error:: %d %s", errno, strerror(errno));} + else { + struct termios my_termios; + tcgetattr(fd, &my_termios); + tcflush(fd, TCIFLUSH); + my_termios.c_cflag = B9600 | CS8 | CLOCAL | HUPCL; + + cfsetospeed(&my_termios, B9600); + tcsetattr(fd, TCSANOW, &my_termios); + } + return; +} +// End serial driver // + + + +/* Module maps + MODULE #A + Channel A: Marquee (Up-Left) + Channel B: Marquee (Up-Right) + Channel C: Marquee (Down-Left) + Channel D: Marquee (Down-Right) + Channel E: MenuButtons (P1) + Channel F: MenuButtons (P2) + Channel G: Bass (Left) + Channel H: Bass (Right) + Channel I: DancePad P1-Up + Channel J: DancePad P1-Down + Channel K: DancePad P1-Left + Channel L: DancePad P1-Right + Channel M: DancePad P2-Up + Channel N: DancePad P2-Down + + MODULE #B + Channel A: DancePad P2-Left + Channel B: DancePad P2-Right + Channel C: + Channel D: + Channel E: + Channel F: + Channel G: + Channel H: + Channel I: + Channel J: + Channel K: + Channel L: + Channel M: + Channel N: +*/ + + +LightsDriver_LinuxWeedTech::LightsDriver_LinuxWeedTech() +{ + // Open port + SerialOpen(); + + // Disable device echoing + char strinit[5]={'A','X','0',0x0d,0x00}; + SerialOut(strinit,5); + strinit[0]='B'; + SerialOut(strinit,5); + return; +} + +LightsDriver_LinuxWeedTech::~LightsDriver_LinuxWeedTech() +{ + // Turn off all lights + char strkill[5]={'A','W','0',0x0d,0x00}; + SerialOut(strkill,5); + strkill[0]='B'; + SerialOut(strkill,5); + + // Close port + SerialClose(); + return; +} + +void LightsDriver_LinuxWeedTech::Set(const LightsState *ls) +{ + // Re-used var's + char str[6]={0x00,0x00,0x00,'1',0x0d,0x00}; + bool bOn = false; + + { + FOREACH_CabinetLight( cl ) + { + // Only send the command if the light has changed states (on/off) + bOn = ls->m_bCabinetLights[cl]; + if(bOn != CurLights.m_bCabinetLights[cl]) { + if(cl == LIGHT_MARQUEE_UP_LEFT) {str[0] = 'A'; str[2] = 'A';} + else if(cl == LIGHT_MARQUEE_UP_RIGHT) {str[0] = 'A'; str[2] = 'B';} + else if(cl == LIGHT_MARQUEE_LR_LEFT) {str[0] = 'A'; str[2] = 'C';} + else if(cl == LIGHT_MARQUEE_LR_RIGHT) {str[0] = 'A'; str[2] = 'D';} + else if(cl == LIGHT_BUTTONS_LEFT) {str[0] = 'A'; str[2] = 'E';} + else if(cl == LIGHT_BUTTONS_RIGHT) {str[0] = 'A'; str[2] = 'F';} + else if(cl == LIGHT_BASS_LEFT) {str[0] = 'A'; str[2] = 'G';} + else if(cl == LIGHT_BASS_RIGHT) {str[0] = 'A'; str[2] = 'H';} + + + if(bOn) {str[1]='L';} + else {str[1]='H';} + + if(str[0]!=0x00) { + SerialOut(str, 6); + str[0]=0x00; + } + CurLights.m_bCabinetLights[cl] = bOn; + } + } + } + + FOREACH_GameController( gc ) + { + FOREACH_GameButton( gb ) + { + // Only send the command if the light has changed states (on/off) + bool bOn = ls->m_bGameButtonLights[gc][gb]; + if(bOn != CurLights.m_bGameButtonLights[gc][gb]) { + if(gc == GAME_CONTROLLER_1) { + if(gb == DANCE_BUTTON_LEFT) {str[0] = 'A'; str[2] = 'I';} + if(gb == DANCE_BUTTON_RIGHT) {str[0] = 'A'; str[2] = 'J';} + if(gb == DANCE_BUTTON_UP) {str[0] = 'A'; str[2] = 'K';} + if(gb == DANCE_BUTTON_DOWN) {str[0] = 'A'; str[2] = 'L';} + } + else if(gc == GAME_CONTROLLER_2) { + if(gb == DANCE_BUTTON_LEFT) {str[0] = 'A'; str[2] = 'M';} + if(gb == DANCE_BUTTON_RIGHT) {str[0] = 'A'; str[2] = 'N';} + if(gb == DANCE_BUTTON_UP) {str[0] = 'B'; str[2] = 'A';} + if(gb == DANCE_BUTTON_DOWN) {str[0] = 'B'; str[2] = 'B';} + } + + if(bOn) {str[1]='L';} + else {str[1]='H';} + + if(str[0]!=0x00) { + SerialOut(str, 6); + str[0]=0x00; + } + CurLights.m_bGameButtonLights[gc][gb] = bOn; + } + } + } + + return; +} diff --git a/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.h b/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.h index 15c5081b8e..27f4b891a2 100644 --- a/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.h +++ b/stepmania/src/arch/Lights/LightsDriver_LinuxWeedTech.h @@ -6,7 +6,7 @@ #ifndef LightsDriver_LinuxWeedTech_H #define LightsDriver_LinuxWeedTech_H -#include "LightsDriver.h" +#include "arch/Lights/LightsDriver.h" class LightsDriver_LinuxWeedTech : public LightsDriver { diff --git a/stepmania/src/arch/arch_linux.h b/stepmania/src/arch/arch_linux.h index 92c0d003ca..8b7b6f9783 100644 --- a/stepmania/src/arch/arch_linux.h +++ b/stepmania/src/arch/arch_linux.h @@ -19,6 +19,8 @@ #include "ArchHooks/ArchHooks_Unix.h" +#include "Lights/LightsDriver_LinuxWeedTech.h" + #include "MemoryCard/MemoryCardDriverThreaded_Linux.h" #endif