diff --git a/stepmania/src/LightsManager.cpp b/stepmania/src/LightsManager.cpp index 61f351b13d..be18175e21 100644 --- a/stepmania/src/LightsManager.cpp +++ b/stepmania/src/LightsManager.cpp @@ -190,6 +190,9 @@ void LightsManager::Update( float fDeltaTime ) default: ASSERT(0); } + + // apply new light values we set above + m_pDriver->Flush(); } void LightsManager::SetLightMode( LightMode lm ) diff --git a/stepmania/src/arch/Lights/LightsDriver.h b/stepmania/src/arch/Lights/LightsDriver.h index 82ac43aac9..9af130c94c 100644 --- a/stepmania/src/arch/Lights/LightsDriver.h +++ b/stepmania/src/arch/Lights/LightsDriver.h @@ -20,6 +20,7 @@ public: virtual ~LightsDriver() {}; virtual void SetLight( Light light, bool bOn ) = 0; + virtual void Flush() = 0; }; diff --git a/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.cpp b/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.cpp new file mode 100644 index 0000000000..3e2b9c681e --- /dev/null +++ b/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.cpp @@ -0,0 +1,97 @@ +#include "global.h" +/* +----------------------------------------------------------------------------- + Class: LightsDriver_LinuxSerial + + Desc: See header. + + Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "LightsDriver_LinuxSerial.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "adrport.h" + +static int fd = 0; + +LightsDriver_LinuxSerial::LightsDriver_LinuxSerial() +{ + sprintf(sPortName, "/dev/ttyS1", sPortNumber); + + fd = open(sPortName, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd < 0) + RageException::Throw( "open error %d %s\n", errno, strerror(errno) ); + + struct termios my_termios; + tcgetattr(fd, &my_termios); + tcflush(fd, TCIFLUSH); + + my_termios.c_cflag = B2400 | CS8 |CREAD | CLOCAL | HUPCL; + + cfsetospeed(&my_termios, B2400); + tcsetattr(fd, TCSANOW, &my_termios); + + LOG->Info("Lights info:"); + LOG->Info(" new cflag=%08x\n", my_termios.c_cflag); + LOG->Info(" new oflag=%08x\n", my_termios.c_oflag); + LOG->Info(" new iflag=%08x\n", my_termios.c_iflag); + LOG->Info(" new lflag=%08x\n", my_termios.c_lflag); + LOG->Info(" new line=%02x\n", my_termios.c_line); + + WriteString( "Yo", strlen("Yo" ); +} + +LightsDriver_LinuxSerial::~LightsDriver_LinuxSerial() +{ + if (fd > 0) + close(fd); +} + +void WriteString( char* sz, int len ) +{ + int iOut; + if (fd < 1) + { + LOG->Warn("Lights port is not open\n"); + return ; + } + + iOut = write(fd, sz, len); + if (iOut < 0) + { + LOG->Warn("Lights write error %d %s\n", errno, strerror(errno)); + } + + ASSERT( iOut > 0 ); +} + +char g_data[2] = { 0, 0 }; + + +void LightsDriver_LinuxSerial::SetLight( Light light, bool bOn ) +{ + int byte_index = light / 8; + int bit_index = light % 8; + char &data = g_data[byte_index]; + BYTE mask = 0x01 << bit_index; + if( bOn ) + data |= mask; + else + data &= ~mask; + + WriteString( data, sizeof(data) ); +} + +void LightsDriver_LinuxSerial::Flush() +{ + WriteString( data, sizeof(data) ); +} diff --git a/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.h b/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.h new file mode 100644 index 0000000000..d8ec7eff70 --- /dev/null +++ b/stepmania/src/arch/Lights/LightsDriver_LinuxSerial.h @@ -0,0 +1,28 @@ +#ifndef LightsDriver_LinuxSerial_H +#define LightsDriver_LinuxSerial_H +/* +----------------------------------------------------------------------------- + Class: LightsDriver_LinuxSerial + + Desc: Control lights. + + Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "arch/Lights/LightsDriver.h" + +class LightsDriver_LinuxSerial : public LightsDriver +{ +public: + LightsDriver_LinuxSerial(); + virtual ~LightsDriver_LinuxSerial(); + + virtual void SetLight( Light light, bool bOn ); + virtual void Flush(); +}; + + + +#endif diff --git a/stepmania/src/arch/Lights/LightsDriver_Null.h b/stepmania/src/arch/Lights/LightsDriver_Null.h index f95edcfe78..a384c31d2d 100644 --- a/stepmania/src/arch/Lights/LightsDriver_Null.h +++ b/stepmania/src/arch/Lights/LightsDriver_Null.h @@ -20,6 +20,7 @@ public: virtual ~LightsDriver_Null() {}; virtual void SetLight( Light light, bool bOn ) {}; + virtual void Flush() {}; }; diff --git a/stepmania/src/arch/Lights/LightsDriver_Win32Parallel.cpp b/stepmania/src/arch/Lights/LightsDriver_Win32Parallel.cpp index 4e6aa6a533..738ddd1945 100644 --- a/stepmania/src/arch/Lights/LightsDriver_Win32Parallel.cpp +++ b/stepmania/src/arch/Lights/LightsDriver_Win32Parallel.cpp @@ -75,7 +75,14 @@ void LightsDriver_Win32Parallel::SetLight( Light light, bool bOn ) data |= mask; else data &= ~mask; +} - DWORD address = LPT_ADDRESS[lpt]; - PortOut( address, data ); +void LightsDriver_Win32Parallel::Flush() +{ + for( int i=0; i