//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: DeviceDI.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of DeviceDI.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "DeviceDI.h" #include "..\..\LgLib\Version.h" CDeviceDI::CDeviceDI() { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceDI::CDeviceDI") ); } CDeviceDI::~CDeviceDI() { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceDI::~CDeviceDI") ); } void CDeviceDI::SetCount( int nCount ) { m_arrInput.RemoveAll(); for( INT i = 0; i < nCount; i++ ) { m_arrInput.AddEmpty(); m_arrInput[i].bOn = FALSE; m_arrInput[i].bNC = FALSE; m_arrInput[i].bFirstTime = TRUE; } PostGetState(); } BOOL CDeviceDI::SetDirectInput( CDirectInput *pDirectInput, int nBit ) { ASSERT( nBit < m_arrInput.GetCount() ); if( nBit >= m_arrInput.GetCount() ) return FALSE; return m_arrInput[nBit].arrDirectInput.Add( pDirectInput ); } void CDeviceDI::PostEnable( BOOL bEnable, int nBit ) { DDIEVENT event; event.id = DDIC_ENABLE; event.bEnable = bEnable; event.nBit = nBit; m_Queue.Push( event ); } void CDeviceDI::PostGetState() { DDIEVENT event; event.id = DDIC_GET_STATE; m_Queue.Push( event ); } void CDeviceDI::SetBit( int nBit, BOOL bOn ) { LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDeviceDI::SetBit"), _T("%d %d"), nBit, bOn ); ASSERT( nBit < m_arrInput.GetCount() ); if( nBit >= m_arrInput.GetCount() ) return; if( !m_arrInput[nBit].bFirstTime && m_arrInput[nBit].bOn == bOn ) return; m_arrInput[nBit].bFirstTime = FALSE; m_arrInput[nBit].bOn = bOn; for( INT i = 0; i < m_arrInput[nBit].arrDirectInput.GetCount(); i++ ) m_arrInput[nBit].arrDirectInput[i]->PostOn( m_arrInput[nBit].bNC ? !bOn : bOn ); } BOOL CDeviceDI::GetBit( int nBit ) { ASSERT( nBit < m_arrInput.GetCount() ); if( nBit >= m_arrInput.GetCount() ) return FALSE; return m_arrInput[nBit].bOn; } void CDeviceDI::SetNC( int nBit, BOOL bNC ) { ASSERT( nBit < m_arrInput.GetCount() ); if( nBit >= m_arrInput.GetCount() ) return; m_arrInput[nBit].bNC = bNC; }