DWORD CGPSAPIReader::read()
{
   const DWORD DRIVER_READ_TIMEOUT = 3000;
   const DWORD MAXIMUM_AGE = 5000; 

   GPS_POSITION gpsPosition = {0};
   gpsPosition.dwVersion = GPS_VERSION_1;
   gpsPosition.dwSize = sizeof(gpsPosition);
#ifdef GPSID_FIX   
   BYTE gpsPositionRaw[376] = {0};
   GPS_POSITION* pGpsLocation = (GPS_POSITION*)gpsPositionRaw;
      pGpsLocation->dwVersion = GPS_VERSION_1;
         pGpsLocation->dwSize = sizeof(gpsPositionRaw);
#endif   

   DWORD dwRet = 0;
   while (WAIT_TIMEOUT == WaitForSingleObject(m_hStopEvent, 0)) {
      
      if (WAIT_OBJECT_0 == (dwRet = WaitForSingleObject(
                               m_hNewLocationData, DRIVER_READ_TIMEOUT))) {
         
         if (ERROR_SUCCESS == (dwRet = GPSGetPosition(
                                  m_hDevice, &gpsPosition, MAXIMUM_AGE, 0))) {
            processPosition(&gpsPosition);
         }
#ifdef GPSID_FIX         
         else if (ERROR_INVALID_PARAMETER == dwRet)
         {
            coreprintln("Look like a GPSID_FIX client");
            if (ERROR_SUCCESS == (dwRet = m_gps.GPSGetPosition(
                                     m_hDevice, pGpsLocation, MAXIMUM_AGE, 0)))
            {
               processPosition(pGpsLocation);
            }
            else
            {
               coreprintln("GPSGetPosition ret: 0x%lx", dwRet);
            }            
         }
#endif
         else {
            coreprintln("GPSGetPosition ret: 0x%lx", dwRet);
         }
      } else if(WAIT_TIMEOUT == dwRet) {
         coreprintln("NewLocationData wait TIMEOUT");
         
         // still no data. process the bad gps output.
         gpsPosition.dwValidFields = 0;
         processPosition(&gpsPosition);
      } else {
         coreprintln("NewLocationData wait FAILED: 0x%lx\n", dwRet);
      }
   }	

   return 0;
}
示例#2
0
void ColorHexagon::
pointerMotion(Event& event)
{
    Point pos = event.getWidgetPoint().getPoint();
    if (processPosition(pos))
        notifyColorChanged();
}
示例#3
0
void ColorHexagon::
pointerButtonDown(Event& event)
{
    Point pos = event.getWidgetPoint().getPoint();
    if (processPosition(pos))
    {
        notifyColorChanged();
        isDragging = true;
    }
}
示例#4
0
void SensorManager::triggerMeasures()
{
	m_sensorPosition->measure();
	m_sensorPressure->measure();

	if ( m_sensorPosition->isNewDataAvailable() ||
		 m_sensorPressure->isNewDataAvailable() )
	{
		m_position = roundData(processPosition(m_sensorPosition->getData()), 0.005);
		m_pressure = roundData(processPressure(m_sensorPressure->getData()), 0.1);

		if (m_direction == INCREASING)
		{
			if (m_position > m_maxPosition)
			{
				m_diffPosition = m_position - m_maxPosition;
				m_maxPosition += m_diffPosition;
				m_sensorData.position += m_diffPosition;
			}

			if (m_position == 0.5)
			{
				m_direction = DECREASING;
			}
		}
		else
		{
			if (m_position == 0.0)
			{
				m_maxPosition = 0.0;
				m_direction = INCREASING;
			}
		}
		m_sensorData.pressure = m_pressure;

		notify();
	}
}