コード例 #1
0
ファイル: instruments.cpp プロジェクト: openhpi1/openhpitest
bool cInstruments::CreateInstrument( const std::string& name )
{
    std::string cname;
    SaHpiUint32T num;
    bool rc = DisassembleNumberedObjectName( name, cname, num );
    if ( !rc ) {
        return false;
    }

    if ( cname == cControl::classname ) {
        if ( !GetControl( num ) ) {
            m_controls[num] = new cControl( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cSensor::classname ) {
        if ( !GetSensor( num ) ) {
            m_sensors[num] = new cSensor( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cInventory::classname ) {
        if ( !GetInventory( num ) ) {
            m_invs[num] = new cInventory( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cWatchdog::classname ) {
        if ( !GetWatchdog( num ) ) {
            m_wdts[num] = new cWatchdog( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cAnnunciator::classname ) {
        if ( !GetAnnunciator( num ) ) {
            m_anns[num] = new cAnnunciator( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cDimi::classname ) {
        if ( !GetDimi( num ) ) {
            m_dimis[num] = new cDimi( m_handler, m_resource, num );
            return true;
        }
    }
    if ( cname == cFumi::classname ) {
        if ( !GetFumi( num ) ) {
            m_fumis[num] = new cFumi( m_handler, m_resource, num );
            return true;
        }
    }

    return false;
}
コード例 #2
0
// create the handle with a known PortID
KCBHANDLE SensorManager::OpenSensorByPortID( _In_z_ const WCHAR* wcPortID )
{
    AutoLock sensorLock( m_csSensorLock );
    AutoLock handleLock( m_csHandleLock );

    auto pSensor = GetSensor( wcPortID );
    if( nullptr == pSensor )
    {
        return KCB_INVALID_HANDLE;
    }
    
    // get a handle for this port id
    KCBHANDLE kcbHandle = GetHandle( pSensor->GetPortID() );

    // open the default streams
    pSensor->Open();

    return kcbHandle;
}
コード例 #3
0
ファイル: instruments.cpp プロジェクト: openhpi1/openhpitest
bool cInstruments::RemoveInstrument( const std::string& name )
{
    std::string classname;
    SaHpiUint32T num;
    bool rc = DisassembleNumberedObjectName( name, classname, num );
    if ( !rc ) {
        return false;
    }

    if ( classname == cControl::classname ) {
        cControl * ctrl = GetControl( num );
        if ( ctrl ) {
            m_controls.erase( num );
            delete ctrl;
            return true;
        }
    }
    if ( classname == cSensor::classname ) {
        cSensor * sen = GetSensor( num );
        if ( sen ) {
            m_sensors.erase( num );
            delete sen;
            return true;
        }
    }
    if ( classname == cInventory::classname ) {
        cInventory * inv = GetInventory( num );
        if ( inv ) {
            m_invs.erase( num );
            delete inv;
            return true;
        }
    }
    if ( classname == cWatchdog::classname ) {
        cWatchdog * wdt = GetWatchdog( num );
        if ( wdt ) {
            m_wdts.erase( num );
            delete wdt;
            return true;
        }
    }
    if ( classname == cAnnunciator::classname ) {
        cAnnunciator * ann = GetAnnunciator( num );
        if ( ann ) {
            m_anns.erase( num );
            delete ann;
            return true;
        }
    }
    if ( classname == cDimi::classname ) {
        cDimi * dimi = GetDimi( num );
        if ( dimi ) {
            m_dimis.erase( num );
            delete dimi;
            return true;
        }
    }
    if ( classname == cFumi::classname ) {
        cFumi * fumi = GetFumi( num );
        if ( fumi ) {
            m_fumis.erase( num );
            delete fumi;
            return true;
        }
    }

    return false;
}
コード例 #4
0
bool CSensorManager::UpdateSensor(uint id, float newValue, bool isSetter, bool forceUpdateClient)
{
	CSensor * sensor = GetSensor(id);

	if (NULL == sensor)
		return false;

	const bool isValueChanged = (sensor->GetValue() != newValue);
	if (true == isValueChanged)
	{
		// update memory record
		sensor->SetValue(newValue);

		// update data base record -------------------------------------------------

		uint startTime = GetTickCount();
		{
			const size_t sensorID = sensor->GetID();
			/*
			string query = u_string_format(
			"UPDATE `sensors` SET `numeric_val`=%f WHERE `id`=%d; INSERT INTO `sensor_history` (sensor_id, value) VALUES('%d', '%f')",
			newValue, sensor->GetID(), sensor->GetID(), newValue);

			m_dataBase->Query(NULL, query.c_str());
			*/
			string query = u_string_format("UPDATE `sensors` SET `numeric_val` = %f WHERE `id` = %d;",
				newValue, sensorID);

			m_dataBase->Query(NULL, query.c_str());

			query = u_string_format("INSERT INTO `sensor_history` (`sensor_id`, `value`) VALUES(%d, %f)",
				sensorID, newValue);

			m_dataBase->Query(NULL, query.c_str());
		}

		printf("Sensor (id:%d, path:%s) value updated to %f\n", sensor->GetID(), sensor->GetPath(), newValue);
		//	printf("DB update time = %d msec\n", (GetTickCount() - startTime));
	}

	// send client command -----------------------------------------------------

	if (forceUpdateClient || (isValueChanged && isSetter))
	{
		const char * sensorPath = sensor->GetPath();

		// FIXME: hack
		if (sensorPath == strstr(sensorPath, "arduino"))
		{
			// FIXME: hack
			const char *pinName = strstr(sensorPath, "/pin/");
			if (NULL != pinName)
			{
				pinName += 5;

				// FIXME: hack
				IAbstractSocket * socket = g_server->GetArduinoSocket((const byte *)"\x0\x1\x2\x3\x4\x5\x6\x7", 8);
				if (NULL != socket)
				{
					SetPinValue *pinSetter = NEW SetPinValue(pinName, (byte)sensor->GetValue());

					CCommandManager * cmdMgr = g_server->GetCommandManager();
					cmdMgr->SendCommand(socket, pinSetter);
				}
			}
		}
	}
	
	return true;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: rodonjohn/tutorial-oculus
void Render()
{
    // Update our time
    static float t = 0.0f;
    t += ( float )XM_PI * 0.0125f;

	//ビュー行列をOculus Riftの回転に合わせて回転する
	float yaw,pitch,roll;
	GetSensor(&yaw,&pitch ,&roll);
	XMVECTOR Eye = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );	//カメラの位置
	XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 5.0f, 0.0f );	//カメラの注視先
	XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );	//カメラの真上のベクトル
	g_View = XMMatrixLookAtLH( Eye, At, Up ) *  XMMatrixRotationY(yaw) * XMMatrixRotationX(pitch) * XMMatrixRotationZ(-roll) ;

	//プロジェクション行列を作成
	g_Projection = XMMatrixPerspectiveFovLH( XM_PIDIV2, WIDTH / (FLOAT)(HEIGHT*2), 0.01f, 100.0f );

	//プロジェクション行列をずらす値の計算
	float viewCenter = g_hmdInfo.HScreenSize * 0.25f;
	float eyeProjectionShift = viewCenter - g_hmdInfo.LensSeparationDistance*0.5f;
	float projectionCenterOffset = 4.0f * eyeProjectionShift / g_hmdInfo.HScreenSize;

	//ビュー行列をずらす値の計算
	float halfIPD = g_hmdInfo.InterpupillaryDistance * 0.5f;

	//画面のクリアをするときの色
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // R,G,B,A の順番

	//レンダーターゲットの設定
	g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetViewOculus , g_pDepthStencilView );

	//画面のクリア・深度バッファクリア
	g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetViewOculus, ClearColor );
	g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

	//トポロジ(描画の法則?)を設定
    g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

	for(int i=0;i<2;i++)
	{
		//ビューポートの設定
		D3D11_VIEWPORT vp;
		vp.Width = WIDTH/2;
		vp.Height = HEIGHT;
		vp.MinDepth = 0.0f;
		vp.MaxDepth = 1.0f;
		vp.TopLeftX = i*WIDTH/2;
		vp.TopLeftY = 0;
		g_pImmediateContext->RSSetViewports( 1, &vp );

		// コンスタントバッファの更新
		// シェーダーに渡す際に転置行列にされてしまうためあらかじめ転置行列にしておく
		ConstantBuffer cb;
		cb.mView = XMMatrixTranspose( g_View * XMMatrixTranslation(i==0?halfIPD:-halfIPD,0.0f,0.0f) );
		cb.mProjection = XMMatrixTranspose( g_Projection * XMMatrixTranslation(i==0?projectionCenterOffset:-projectionCenterOffset,0.0f,0.0f) );

		//頂点シェーダーとピクセルシェーダーのセット
		g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
		g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
		g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );
		g_pImmediateContext->PSSetShaderResources( 0, 1, &g_pTextureRV );
		g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerLinear );

		//頂点バッファとインデックスバッファのセット
		UINT stride = sizeof(SimpleVertex), offset = 0;
		g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );
		g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );

		//キューブの描画
		//ワールド行列を変えることでボックスを適当に配置
		//1つめ (0,0,5)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,0,10);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//2つめ (0,4,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,8,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//3つめ (0,-4,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(0,-8,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//4つめ (-4,0,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(-8,0,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );

		//5つめ (4,0,0)の位置
		g_World = XMMatrixRotationY(t) * XMMatrixRotationX(t/5) * XMMatrixTranslation(8,0,0);
		cb.mWorld = XMMatrixTranspose( g_World );
		g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
		g_pImmediateContext->DrawIndexed( 36, 0, 0 );
	}


	//---------------------------------------------
	//--Oculus Rift用に画面を歪ませて描画する処理--
	//---------------------------------------------

	//レンダーターゲットの設定
	g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );

	//レンダーターゲットのクリア
	float ClearColor_[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; // R,G,B,A の順番
	g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor_ );

	//トポロジ(描画の法則?)を設定
	g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );

	// 頂点シェーダー用コンスタントバッファの更新
	ConstantBuffer cb;
	cb.mWorld = XMMatrixIdentity();
	cb.mView = XMMatrixIdentity();
	cb.mProjection = XMMatrixIdentity();
	g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );

	// 設定
	UINT stride = sizeof(SimpleVertex), offset = 0;
	g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
	g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
	g_pImmediateContext->PSSetShader( g_pPixelShaderOculus, NULL, 0 );
	g_pImmediateContext->PSSetShaderResources( 0, 1, &g_pShaderResViewOculus );
	g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerLinear );
	g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pConstantBufferOculus );

	//Oculusのデバイスから定数を計算する
	OculusRiftSettings ocrSet;
		
	//ゆがみ定数
	ocrSet.HmdWarpParam.x = g_hmdInfo.DistortionK[0];
	ocrSet.HmdWarpParam.y = g_hmdInfo.DistortionK[1];
	ocrSet.HmdWarpParam.z = g_hmdInfo.DistortionK[2];
	ocrSet.HmdWarpParam.w = g_hmdInfo.DistortionK[3];

	//色補正の定数(追加部分)
	ocrSet.ChromAbParam.x = g_hmdInfo.ChromaAbCorrection[0];
	ocrSet.ChromAbParam.y = g_hmdInfo.ChromaAbCorrection[1];
	ocrSet.ChromAbParam.z = g_hmdInfo.ChromaAbCorrection[2];
	ocrSet.ChromAbParam.w = g_hmdInfo.ChromaAbCorrection[3];

	//スケールの計算
	float as = (float)WIDTH/(float)HEIGHT;	//アスペクト比
	float r = 1.0f;							//最大半径(倍率?)
	//float r = 1.0f + (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize);	//rに関してはこっちのほうが正しいんだろうけどでかすぎる気もする。
	float rsq   = r*r;
	float scale = r * (g_hmdInfo.DistortionK[0] + g_hmdInfo.DistortionK[1] * rsq + g_hmdInfo.DistortionK[2] * rsq * rsq + g_hmdInfo.DistortionK[3] * rsq * rsq * rsq);
	float scaleFactor = 1/scale;

	ocrSet.Scale.x = (0.5/2) * scaleFactor;
	ocrSet.Scale.y = (0.5/2) * scaleFactor * as;
	ocrSet.ScaleIn.x = (2/0.5); 
	ocrSet.ScaleIn.y = (2/0.5) / as;

	//================左目の描画===============
	//ビューポートの設定
	D3D11_VIEWPORT vp;
	vp.Width = WIDTH/2;
	vp.Height = HEIGHT;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	g_pImmediateContext->RSSetViewports( 1, &vp );
	//左目用の頂点バッファの指定
	g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBufferOculusL, &stride, &offset );
	//スクリーンの中央位置
	ocrSet.ScreenCenter.x = 0.25f;
	ocrSet.ScreenCenter.y = 0.5f;
	//レンズの中央位置
	ocrSet.LensCenter.x = ocrSet.ScreenCenter.x + (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize)/4;	//修正
	ocrSet.LensCenter.y = 0.5f;
	g_pImmediateContext->UpdateSubresource( g_pConstantBufferOculus, 0, NULL, &ocrSet, 0, 0 );
	g_pImmediateContext->Draw( 4, 0);

	//================右目の描画================
	vp.TopLeftX = WIDTH/2;
	vp.TopLeftY = 0;
	g_pImmediateContext->RSSetViewports( 1, &vp );
	//右目用の頂点バッファの指定
	g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBufferOculusR, &stride, &offset );
	//スクリーンの中央位置
	ocrSet.ScreenCenter.x = 0.75;
	ocrSet.ScreenCenter.y = 0.5f;
	//レンズの中央位置
	ocrSet.LensCenter.x = ocrSet.ScreenCenter.x - (1.0f - 2.0f*g_hmdInfo.LensSeparationDistance/g_hmdInfo.HScreenSize)/4;	//修正
	ocrSet.LensCenter.y = 0.5f;
	g_pImmediateContext->UpdateSubresource( g_pConstantBufferOculus, 0, NULL, &ocrSet, 0, 0 );
	g_pImmediateContext->Draw( 4, 0);


    // 画面の表示(垂直同期をとる)
    g_pSwapChain->Present( 1, 0 );
}