⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfid.cpp

📁 可捕捉到硬體的三軸的值
💻 CPP
字号:
// Array_Buffer.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "RFID.h"
// AccelerometerTest.cpp : Defines the entry point for the console application.
//

#include "stdio.h"
#include "windows.h"
#include "phidget21.h"

double past_samples[10] ,initpast[3];
int asd1 = 0;
D3DXVECTOR3 pos;
int __stdcall AttachHandler(CPhidgetHandle IFK, void *userptr)
{
	//printf("Attach handler ran!\n");
	return 0;
}

int __stdcall DetachHandler(CPhidgetHandle IFK, void *userptr)
{
	//printf("Detach handler ran!\n");
	return 0;
}

int __stdcall ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
{
	//printf("Error handler ran!\n");
	return 0;
}

void display_generic_properties(CPhidgetHandle phid)
{
	int sernum, version;
	const char *deviceptr;
	CPhidget_getDeviceType(phid, &deviceptr);
	CPhidget_getSerialNumber(phid, &sernum);
	CPhidget_getDeviceVersion(phid, &version);

	//printf("%s\n", deviceptr);
	//printf("Version: %8d SerialNumber: %10d\n", version, sernum);
	return;
}

int __stdcall ACC_AccelChangeHandler(CPhidgetAccelerometerHandle WGT, void *userptr, int Index, double Value)
{
	past_samples[Index] = (past_samples[Index] * 0.90) + (Value * 0.10);
	if(asd1<93)
		asd1++;
	if(asd1 > 89 && asd1 < 93)
		initpast[Index] = past_samples[Index];
	//printf("%6f  ", past_samples[Index] - initpast[Index]);
	//if (Index == 2) printf("\n");
	return 0;
}


int test_accel()
{
	int result;
	const char *err;

	CPhidgetAccelerometerHandle ACC = 0;

	CPhidgetAccelerometer_create(&ACC);

	CPhidget_set_OnAttach_Handler((CPhidgetHandle)ACC, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)ACC, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)ACC, ErrorHandler, NULL);

	CPhidgetAccelerometer_set_OnAccelerationChange_Handler(ACC, ACC_AccelChangeHandler, NULL);

	CPhidget_open((CPhidgetHandle)ACC, -1);

	//Wait for 10 seconds, otherwise exit
	if(result = CPhidget_waitForAttachment((CPhidgetHandle)ACC, 10000))
	{
		CPhidget_getErrorDescription(result, &err);
		//printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	display_generic_properties((CPhidgetHandle) ACC);

	//printf("And reading ...\n");

	CPhidgetAccelerometer_setAccelerationChangeTrigger(ACC, 0, 0.000);
	CPhidgetAccelerometer_setAccelerationChangeTrigger(ACC, 1, 0.000);

	//scanf("%d", past_samples[0]);

	//return 0;
}

/*int __cdecl main(int argc, char* argv[])
{
	asd1 = 0;
	test_accel();
	return 0;
}*/

ChannelType channelType;
	
extern "C" __declspec( dllexport ) ChannelType* __cdecl GetType() {
	ZeroMemory(channelType.name, 80);
	StringCbCopy(channelType.name,  79, RFID_NAME); 
	channelType.version			= RFID_VERSION;
	channelType.guid			= RFID_GUID;
	channelType.baseguid		= VECTOR_GUID;
	channelType.minimumEdition 	= EDITION_LEVEL_ALL;		// All Quest3D Editions

	return &channelType;
}

RFIDDLL_EXPORTS

RFID::RFID() {
	SetChannelName(RFID_NAME);
	//TODO: Add construction logic here
}

RFID::~RFID()
{
	//TODO:: Add destruction logic here
}


// Overlodaed save channel
bool RFID::SaveChannel(A3dFileSaver& saver) {
	if(!A3d_Channel::SaveChannel(saver))
		return false;
	//TODO: Add your logic to save persistent data here
	return true;
}

bool RFID::LoadChannel(A3dFileLoader& loader, A3d_ChannelGroup *group) {
	if(!A3d_Channel::LoadChannel(loader, group))
		return false;
	//TODO: Add your logic to load persistent data here
	return true;
}

void RFID::DoDependencyInit(A3d_List* currentDependList) {
	//Include Visual Studio 2005 runtime libraries	
	AddDLLDepend("MSVCR80.DLL", currentDependList);
	AddDLLDepend("MSVCP80.DLL", currentDependList);
	AddDLLDepend("MSVCM80.DLL", currentDependList);
	AddDLLDepend("Microsoft.VC80.CRT.manifest", currentDependList);
}

void RFID::CallChannel()
{
	//TODO: Add call channel logic here
	if(asd1 == 0)
	{
		asd1 = 0;
		test_accel();
	}
	pos.x = past_samples[0] - initpast[0];
	pos.y = past_samples[1] - initpast[1];
	pos.z = past_samples[2] - initpast[2];
	SetVector(pos);
	engine->DMsg(pos.x);
	engine->DMsg(pos.y);
	engine->DMsg(pos.z);
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -