Ejemplo n.º 1
0
int CAtmoTools::SetChannelAssignment(CAtmoDynData *pDynData, int index)
{
    CAtmoConfig *pAtmoConfig = pDynData->getAtmoConfig();
    CAtmoConnection *pAtmoConnection = pDynData->getAtmoConnection();
    int oldIndex = pAtmoConfig->getCurrentChannelAssignment();

    CAtmoChannelAssignment *ca = pAtmoConfig->getChannelAssignment(index);
    if((ca!=NULL) && (pAtmoConnection!=NULL)) {
        pAtmoConnection->SetChannelAssignment(ca);
        pAtmoConfig->setCurrentChannelAssignment(index);
    }
    return oldIndex;
}
Ejemplo n.º 2
0
ATMO_BOOL CAtmoTools::RecreateConnection(CAtmoDynData *pDynData)
{
	pDynData->LockCriticalSection();
	CLanguage *Lng = new CLanguage;

	CAtmoConnection *current = pDynData->getAtmoConnection();
	CAtmoConfig *atmoConfig = pDynData->getAtmoConfig();
	AtmoConnectionType act = atmoConfig->getConnectionType();
	pDynData->setAtmoConnection(NULL);
	if(current != NULL) 
	{
		current->CloseConnection();
		delete current;
	}

	switch(act)
	{
	case actClassicAtmo:
		{
			CAtmoClassicConnection *tempConnection = new CAtmoClassicConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE)
			{
#if !defined(_ATMO_VLC_PLUGIN_)
				if(atmoConfig->getIgnoreConnectionErrorOnStartup() == ATMO_FALSE)
				{
					char errorMsgBuf[200];
					sprintf(errorMsgBuf,Lng->sMessagesText[26] + "com%d" + Lng->sMessagesText[26] + "%d (0x%x)",
						pDynData->getAtmoConfig()->getArduComport(),
						tempConnection->getLastError(),
						tempConnection->getLastError()
						);
					MessageBox(0,errorMsgBuf,Lng->sMessagesText[3] ,MB_ICONERROR | MB_OK);
				}
#endif
				pDynData->setAtmoConnection(tempConnection);

				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData,
				atmoConfig->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

#if !defined(_ATMO_VLC_PLUGIN_)
	case actDummy:
		{
			// actDummy8,actDummy12,actDummy16
			CAtmoDummyConnection *tempConnection = new CAtmoDummyConnection(pDynData->getResHinstance(),
				atmoConfig);
			if(tempConnection->OpenConnection() == ATMO_FALSE) 
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData, pDynData->getAtmoConfig()->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}
#endif

	case actDMX: 
		{
			// create here your DMX connections... instead of the dummy....
			CAtmoDmxSerialConnection *tempConnection = new CAtmoDmxSerialConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE)
			{
				pDynData->setAtmoConnection(tempConnection);

				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

#if !defined(_ATMO_VLC_PLUGIN_)
	case actNUL: 
		{
			CAtmoNulConnection *tempConnection = new CAtmoNulConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE) 
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}
#endif

	case actMultiAtmo: 
		{
			CAtmoMultiConnection *tempConnection = new CAtmoMultiConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE) 
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

#if !defined(_ATMO_VLC_PLUGIN_)
	case actMondolight: 
		{
			CMondolightConnection *tempConnection = new CMondolightConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE)
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment());

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}
#endif
	case actMoMoLight: 
		{
			CMoMoConnection *tempConnection = new CMoMoConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE)
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

	case actFnordlicht: 
		{
			CFnordlichtConnection *tempConnection = new CFnordlichtConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE)
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

	case actEnttecDMX: 
		{
			CAtmoEntecSerialConnection *tempConnection = new CAtmoEntecSerialConnection( atmoConfig );
			if(tempConnection->OpenConnection() == ATMO_FALSE) 
			{
				pDynData->setAtmoConnection(tempConnection);
				pDynData->UnLockCriticalSection();
				return ATMO_FALSE;
			}
			pDynData->setAtmoConnection(tempConnection);
			pDynData->ReloadZoneDefinitionBitmaps();

			tempConnection->CreateDefaultMapping( atmoConfig->getChannelAssignment(0) );

			CAtmoTools::SetChannelAssignment(pDynData, atmoConfig->getCurrentChannelAssignment() );

			pDynData->UnLockCriticalSection();
			return ATMO_TRUE;
		}

  case actAtmoDuinoV2: {
    CAtmoDuinoV2Connection *tempConnection = new CAtmoDuinoV2Connection(atmoConfig);
    if (tempConnection->OpenConnection() == ATMO_FALSE) {
#if !defined(_ATMO_VLC_PLUGIN_)
      if (atmoConfig->getIgnoreConnectionErrorOnStartup() == ATMO_FALSE)
      {
        char errorMsgBuf[200];
        sprintf(errorMsgBuf, "Failed to open serial port com%d with errorcode: %d (0x%x)",
          pDynData->getAtmoConfig()->getComport(),
          tempConnection->getLastError(),
          tempConnection->getLastError()
          );
        MessageBox(0, errorMsgBuf, "Error", MB_ICONERROR | MB_OK);
      }
#endif
      pDynData->setAtmoConnection(tempConnection);

      pDynData->UnLockCriticalSection();
      return ATMO_FALSE;
    }
    pDynData->setAtmoConnection(tempConnection);
    pDynData->ReloadZoneDefinitionBitmaps();

    tempConnection->CreateDefaultMapping(atmoConfig->getChannelAssignment(0));

    CAtmoTools::SetChannelAssignment(pDynData,
      atmoConfig->getCurrentChannelAssignment());

    pDynData->UnLockCriticalSection();
    return ATMO_TRUE;
  }


	default: 
		{
			pDynData->UnLockCriticalSection();
			return ATMO_FALSE;
		}
	}
}