//============================================================================== int g_ResetFrameCounter(){ if( !x_iPortIO_Granted ) return 1; PortOutput( LPT_CONTROL, RESET_ON); Sleep(1); PortOutput( LPT_CONTROL, GATE_OFF); x_iCounterStarted = 0; x_iPrevFrame = 0; return 0; }
//============================================================================== int g_CloseFrameCounter(){ if( !x_iPortIO_Granted ) return 1; // restore the state x_iPortIO_Granted = 0; // It is safer to output fixed (not saved) values in case the program // did not exit normally on the previous run PortOutput( LPT_CONTROL, LPT_CTL_DFLT); PortOutput( ECP_ECTRL, ECP_ECTL_DFLT); // PortOutput( LPT_CONTROL, x_iCtlSave); // PortOutput( ECP_ECTRL, x_iEcpSave); x_iCounterStarted = 0; return 0; }
//============================================================================== int CEyeTrack::ConnectISCAN( ){ int iRet; if( IsRunning() ) { CP_printf("Error in m_InitSerialThread()! Thread is already running.\n"); return 1; } iRet = g_SysGrantIO( LPT_BASE ); if( iRet ) { iPortIO_Granted = 0; printf("Error: Cannot grant I/O access, error: %d\n", iRet ); return 1; } iPortIO_Granted = 1; PortOutput( LPT_CONTROL, RESET_ON); Sleep(1); PortOutput( LPT_CONTROL, GATE_OFF); Sleep(1); PortOutput( LPT_CONTROL, GATE_ON); CP_printf("Connecting to %s port\n", x_aszComNames[ m_iComPortIdx-1]); iRet = m_Serial.connect(x_aszComNames[ m_iComPortIdx-1], m_iBaudRate, m_iSerialParity); if(iRet) { CP_printf("Error in m_InitSerialThread, m_Serial.connect() failed\n"); return 1; } m_ReadCount = 0; m_iMissCount = 0; m_nMissedFrames = 0; m_iPrevFrame = 0; m_iReportSync = 1; // report next sync // Init sliding buffer SetBuffer(sizeof(IScanFrameStruct), ISCAN_BUFFER_SIZE); ResetBuffer(); ResetTime(); m_StartReadingThread( ); if( !IsRunning() ) { CP_printf("Error in m_InitSerialThread()! CreateThread() failed.\n"); PortOutput( LPT_CONTROL, GATE_OFF); RemoveBuffer(); return 1; } CP_printf("Connected ISCAN\n"); CP_printf("Expected number of parameters: %d\n", N_DATA_ITEMS); return 0; }
//============================================================================== int g_StopFrameCounter(){ if( !x_iPortIO_Granted ) return 1; if( !x_iCounterStarted ) return 2; PortOutput( LPT_CONTROL, GATE_OFF); Sleep(20); // enough to finish 60Hz frames CP_printf("Frame counter stopped. Total N frames = %d\n", x_GetFrameCount() ); x_iCounterStarted = 0; return 0; }
//============================================================================== int g_StartFrameCounter(){ if( !x_iPortIO_Granted ) return 1; if( x_iCounterStarted ) return 2; g_ResetFrameCounter(); Sleep(1); PortOutput( LPT_CONTROL, GATE_ON); x_iCounterStarted = 1; return 0; }
//============================================================================== int CEyeTrack::DisconnectISCAN(){ if( iPortIO_Granted ) { PortOutput( LPT_CONTROL, GATE_OFF); } //Terminate thread m_StopReadingThread( 500 ); // thread stop time msec m_Serial.disconnect(); RemoveBuffer(); CP_printf("Disconnected ISCAN\n"); return 0; }
//============================================================================== int g_InitFrameCounter(){ int iValue; if( g_SysGrantIO( LPT_BASE ) ) return 1; if( g_SysGrantIO( ECP_AFIFO ) ) return 1; x_iCtlSave = PortInput(LPT_CONTROL); x_iEcpSave = PortInput(ECP_ECTRL); iValue = x_iEcpSave & 0x1F; // keep lower 5 bits, clear upper 3 iValue = iValue | 0x20; // set mode 1 - bidirectional, PS2 PortOutput( ECP_ECTRL, iValue); x_iPortIO_Granted = 1; x_iCounterStarted = 0; g_ResetFrameCounter(); return 0; }