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

📄 test_pad_com.cpp

📁 ps1开发设计资料
💻 CPP
字号:
// test_pad_com.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <assert.h>

#include "serial.h"
#include "psxPadDriver.h"

//////////////////////////////////////////////////////////////////
// serial device
//////////////////////////////////////////////////////////////////
serialCL serial;


/////////////////////////////////////////////////////////////////////////
// Main program
/////////////////////////////////////////////////////////////////////////

// ---------------------------------------------------------------------------------------
// continuousRead
// ---------------------------------------------------------------------------------------

void continuousRead()
{
	unsigned char data;
	unsigned char dataPsx[7];
	unsigned long l=0;
	psxPad pad;

	while(1){
		data=0x00;	// read request
		if(serial.write(&data, 1) != SERIAL_SUCCESS)
			printf("Serial port WRITE error\n");
		l=7; // wait 7 bytes
		if(serial.forceRead(dataPsx, l) != SERIAL_SUCCESS)
			printf("Serial port READ error\n");	
		// display data as pad buttons correspondance
		updatePsxPadData(&pad, dataPsx);
		psxPrintOneLine(&pad);
	}
} // continuousRead

// ---------------------------------------------------------------------------------------
// main
// ---------------------------------------------------------------------------------------

int main(int argc, char* argv[])
{	
	unsigned char data;
	unsigned char dataPsx[7];
	unsigned long l=0;
	psxPad pad;

	// welcome message
	printf("**** PSX PAD TESTING ****\n");

	// Configure serial port
	if(serial.open() != SERIAL_SUCCESS)
		printf("Serial port OPEN error\n");

	data=0x00;	// read request
	if(serial.write(&data, 1) != SERIAL_SUCCESS)
		printf("Serial port WRITE error\n");

	l=7; // wait 7 bytes
	if(serial.forceRead(dataPsx, l) != SERIAL_SUCCESS) {
		printf("Serial port READ error\n");
	}
	/*
	// print bytes received
	for(unsigned long i=0;i<l && i<7; i++){
		printf("0x%x\n", dataPsx[i]);
	}
	*/
	// display data as pad buttons correspondance
	updatePsxPadData(&pad, dataPsx);
	psxPrint(&pad);
	printf("\n");
	continuousRead();
	// exit the program
	return 0;
}


/////////////////////////////////////////////////////////////////////////
// Basic test for 68hc11 board with an embedded serial loopback program
/////////////////////////////////////////////////////////////////////////

// ---------------------------------------------------------------------------------------
// basicTest
// ---------------------------------------------------------------------------------------

void basicTest(unsigned char v)
{
	unsigned long l=0;
	unsigned char bufs[1];
	unsigned char bufr[1];

	printf("%d\n", v);
	bufs[0]=v;
	if(serial.write(bufs, 1) != SERIAL_SUCCESS)
		printf("Serial port WRITE error\n");
	l=1;
	if(serial.forceRead(bufr, l) != SERIAL_SUCCESS) {
		printf("Serial port READ error\n");
	}
	printf("  %d\n", bufr[0]);
}

// ---------------------------------------------------------------------------------------
// main2
// ---------------------------------------------------------------------------------------

int main2(int argc, char* argv[])
{
	unsigned char bufs[20]="\ncall B600\n";
	if(serial.open() != SERIAL_SUCCESS)
		printf("Serial port OPEN error\n");
	for(unsigned char i=0; i<255;i++)
		basicTest(i);
	return 0;
} // main2

⌨️ 快捷键说明

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