📄 yc2440test.cpp
字号:
// yc2440test.cpp : Defines the entry point for the application.
//
#include "windows.h"
#include <ceddk.h>
#include <nled.h>
#include "resource.h"
#include "winceKBhook.h"
BOOL CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define NLED_MAX_LED_CETK 7
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//
// Holds the open file handle to NLeddrvr driver
HANDLE g_hNLeddrvr = NULL;
HWND hDialogWnd = NULL;
//------------------------------------------------------------------------------
// Local Variables
static UINT g_cLEds = 0;
static BOOL ledThreadRunning = FALSE;
static HANDLE hLedThread = NULL;
static UINT currStyle = 0;
static UINT KBDMAP[][2]={
{IDC_K1,38},
{IDC_K2,39},
{IDC_K3,40},
{IDC_K4,37},
{IDC_K5,27},
{IDC_K6,13}
};
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: InitializeTests
//
// This function initializes the set of tests. It maps the memory to the
// registers.
//
// Parameters:
// None.
//
// Returns:
// TRUE if the memory map succeeds; FALSE if the memory map fails.
//
//------------------------------------------------------------------------------
static BOOL InitializeTests(void)
{
UINT32 bytesWritten=0;
g_hNLeddrvr = CreateFile(TEXT("NLD1:"), // name of device
GENERIC_READ | GENERIC_WRITE, // desired access
FILE_SHARE_READ | FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
FILE_FLAG_RANDOM_ACCESS, // flags/attributes
NULL); // template file (ignored)
if (g_hNLeddrvr == NULL) {
RETAILMSG(1,(TEXT("main.cpp: InitializeTests():CreateFile(NLeddrvr): Unable to open file! \r\n")));
return 0;
}
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: FinishTests
//
// This function performs the clean up after the tests have finished.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
static VOID FinishTests(void)
{
// Close the file handle
if (g_hNLeddrvr != NULL) {
CloseHandle(g_hNLeddrvr);
RETAILMSG(1,(TEXT("main.cpp: FinishTests():CloseHandle(NLeddrvr): Closed file handle! \r\n")));
}
if(hLedThread)
{
CloseHandle(hLedThread);
hLedThread = NULL;
}
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrGetCountInfoTest
//
// Get the total number of Notification LED(s) supported in system
//
// Parameters:
// uiMsg
// [in] to determine if the shell wants to execute the test.
// tpParam
// [in] Ignored.
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
int NLeddrvrGetCountInfoTest(UINT uMsg)
{
UINT nId = NLED_COUNT_INFO_ID;
NLED_COUNT_INFO NledCountInfo = {0};
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledCountInfo, // out buffer
sizeof(NLED_COUNT_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if (!NledCountInfo.cLeds) {
return -1;
}
g_cLEds = NledCountInfo.cLeds;
return 0;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrGetSupportsInfoTest
//
// Get Notification LED(s) supports information
//
// Parameters:
// uiMsg
// [in] to determine if the shell wants to execute the test.
// tpParam
// [in] Ignored.
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
int NLeddrvrGetSupportsInfoTest(UINT uMsg)
{
if (!g_cLEds) {
return -1;
}
UINT nId = NLED_SUPPORTS_INFO_ID;
NLED_SUPPORTS_INFO NledSupportsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
for (UINT i=0; i<g_cLEds; i++) {
NledSupportsInfo[i].LedNum = i;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledSupportsInfo[i], // out buffer
sizeof(NLED_SUPPORTS_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
}
return 0;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrOnTest
//
// Set Notification LED(s) to 'Off' state
//
// Parameters:
// uiMsg
// [in] to determine if the shell wants to execute the test.
// tpParam
// [in] Ignored.
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
int GetLedStatus(int index)
{
NLED_SETTINGS_INFO NledGettingsInfo;
UINT nId = NLED_SETTINGS_INFO_ID;
NledGettingsInfo.LedNum = index;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledGettingsInfo, // out buffer
sizeof(NLED_SETTINGS_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return 0;
}
return NledGettingsInfo.OffOnBlink;
}
int NLeddrvrOnTest(UINT uMsg)
{
if (!g_cLEds) {
return -1;
}
UINT nId = NLED_SETTINGS_INFO_ID;
int RetVal = IDNO;
NLED_SETTINGS_INFO NledSettingsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
NLED_SETTINGS_INFO NledSetInfoCmp[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
/* for (UINT i=0; i<g_cLEds; i++)*/UINT i=uMsg; { // Set LED(s) to 'On'
NledSettingsInfo[i].LedNum = i;
NledSettingsInfo[i].OffOnBlink = 1;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_SETDEVICE, // I/O control code
&NledSettingsInfo[i], // in buffer
sizeof(NLED_SETTINGS_INFO), // in buffer size
NULL, // out buffer
0, // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
NledSetInfoCmp[i].LedNum = i;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledSetInfoCmp[i], // out buffer
sizeof(NLED_SETTINGS_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if (NledSetInfoCmp[i].OffOnBlink != NledSettingsInfo[i].OffOnBlink) {
return -1;
}
}
return 0;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrBlinkTest
//
// Set Notification LED(s) to 'Blink' state with specified 'On' and 'Off' times.
//
// Parameters:
// uiMsg
// [in] to determine if the shell wants to execute the test.
// tpParam
// [in] Ignored.
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
int NLeddrvrBlinkTest(UINT uMsg)
{
if (!g_cLEds) {
return -1;
}
UINT nId = NLED_SETTINGS_INFO_ID;
int RetVal = IDNO;
NLED_SETTINGS_INFO NledSettingsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
NLED_SETTINGS_INFO NledSetInfoCmp[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
/*for (UINT x=0; x<2; x++)*/ {
/*for (UINT i=0; i<g_cLEds; i++)*/UINT i=uMsg; { // Set LED(s) to 'Blink'
NledSettingsInfo[i].LedNum = i;
NledSettingsInfo[i].OffOnBlink = 2;
NledSettingsInfo[i].OnTime = 500000;
NledSettingsInfo[i].OffTime = 100000;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_SETDEVICE, // I/O control code
&NledSettingsInfo[i], // in buffer
sizeof(NLED_SETTINGS_INFO), // in buffer size
NULL, // out buffer
0, // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledSetInfoCmp[i], // out buffer
sizeof(NLED_SETTINGS_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if ((NledSetInfoCmp[i].OffOnBlink != NledSettingsInfo[i].OffOnBlink) ||
(NledSetInfoCmp[i].OnTime != NledSettingsInfo[i].OnTime) ||
(NledSetInfoCmp[i].OffTime != NledSettingsInfo[i].OffTime)) {
return -1;
}
}
}
return 0;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrOffTest
//
// Set Notification LED(s) to 'Off' state
//
// Parameters:
// uiMsg
// [in] to determine if the shell wants to execute the test.
// tpParam
// [in] Ignored.
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
int NLeddrvrOffTest(UINT uMsg)
{
if (!g_cLEds) {
return -1;
}
UINT nId = NLED_SETTINGS_INFO_ID;
int RetVal = IDNO;
NLED_SETTINGS_INFO NledSettingsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
NLED_SETTINGS_INFO NledSetInfoCmp[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
/*for (UINT i=0; i<g_cLEds; i++)*/UINT i=uMsg; { // Set LED(s) to 'Off'
NledSettingsInfo[i].LedNum = i;
NledSettingsInfo[i].OffOnBlink = 0;
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_SETDEVICE, // I/O control code
&NledSettingsInfo[i], // in buffer
sizeof(NLED_SETTINGS_INFO), // in buffer size
NULL, // out buffer
0, // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if (!DeviceIoControl(
g_hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledSetInfoCmp[i], // out buffer
sizeof(NLED_SETTINGS_INFO), // out buffer size
0, // number of bytes returned
NULL
)) {
return -1;
}
if (NledSetInfoCmp[i].OffOnBlink != NledSettingsInfo[i].OffOnBlink) {
return -1;
}
}
return 0;
}
DWORD LedThread(PVOID arg)
{
UINT style = *((UINT*)arg);
int dly=100;
while(ledThreadRunning)
{
if(style == IDC_WATERLED2)
{
dly=100;
NLeddrvrOnTest(0);
Sleep(dly);
NLeddrvrOffTest(0);
NLeddrvrOnTest(1);
Sleep(dly);
NLeddrvrOffTest(1);
NLeddrvrOnTest(2);
Sleep(dly);
NLeddrvrOffTest(2);
NLeddrvrOnTest(3);
Sleep(dly);
NLeddrvrOffTest(3);
}
else if(style == IDC_HOURSELED)
{
dly=200;
NLeddrvrOffTest(1);
NLeddrvrOffTest(3);
NLeddrvrOnTest(0);
NLeddrvrOnTest(2);
Sleep(dly);
NLeddrvrOffTest(0);
NLeddrvrOffTest(2);
NLeddrvrOnTest(1);
NLeddrvrOnTest(3);
Sleep(dly);
}
else
Sleep(1000);
}
hLedThread = NULL;
return (DWORD)0;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DialogBoxParam(
hInstance,
(LPCTSTR) MAKEINTRESOURCE(IDD_DIALOG1) ,
NULL,
DialogProc,
1
);
return 0;
}
int ProcessKeyMessage(WPARAM wParam,PKBDLLHOOKSTRUCT lpKBD)
{
UINT lparam = ((wParam&1)<<31)|(lpKBD->scanCode<<16)|1;
return SendMessage(hDialogWnd,wParam,lpKBD->vkCode,(LPARAM)lparam);
}
UINT GetKeyIDC(UINT vKey)
{
for(int i=0;i<6;i++)
{
if(KBDMAP[i][1] == vKey)
return KBDMAP[i][0];
}
return 0;
}
BOOL CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_INITDIALOG:
RETAILMSG(1,(TEXT("DialogProc WM_INITDIALOG\r\n")));
InitializeTests();
NLeddrvrGetCountInfoTest(0);
hDialogWnd = hwndDlg;
SetKBHook();
SetFocus(NULL);
return 1;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_LED1:
case IDC_LED2:
case IDC_LED3:
case IDC_LED4:
if(ledThreadRunning)
{
ledThreadRunning = FALSE;
if(hLedThread)
{
CloseHandle(hLedThread);
hLedThread = NULL;
}
}
if(GetLedStatus(LOWORD(wParam)-IDC_LED1) == 0)
NLeddrvrOnTest(LOWORD(wParam)-IDC_LED1);
else if(GetLedStatus(LOWORD(wParam)-IDC_LED1) == 1)
NLeddrvrBlinkTest(LOWORD(wParam)-IDC_LED1);
else
NLeddrvrOffTest(LOWORD(wParam)-IDC_LED1);
SetFocus(NULL);
return TRUE;
case IDC_WATERLED2:
case IDC_HOURSELED:
if(ledThreadRunning == FALSE)
{
currStyle = LOWORD(wParam);
ledThreadRunning = TRUE;
hLedThread = CreateThread(NULL,NULL,LedThread,PVOID(&currStyle),NULL,NULL);
}
else
{
ledThreadRunning = FALSE;
Sleep(1000);
if(hLedThread)
{
CloseHandle(hLedThread);
hLedThread = NULL;
}
if(currStyle != LOWORD(wParam))
{
currStyle = LOWORD(wParam);
ledThreadRunning = TRUE;
hLedThread = CreateThread(NULL,NULL,LedThread,PVOID(&currStyle),NULL,NULL);
}
}
SetFocus(NULL);
return TRUE;
case IDOK:
return TRUE;
case IDCANCEL:
FinishTests();
DestroyWindow(hwndDlg);
return TRUE;
}
break;
case WM_KEYDOWN:
case WM_KEYUP:
{
WCHAR strbuf[64];
EnableWindow(GetDlgItem(hwndDlg, GetKeyIDC(LOWORD(wParam))), uMsg == WM_KEYDOWN?TRUE:FALSE);
wsprintf(strbuf,TEXT("vkey %d,keydata %x\r\n"),LOWORD(wParam),lParam);
RETAILMSG(1,(TEXT("%s"),strbuf));
SendDlgItemMessage(hwndDlg,IDC_EDIT1,EM_SETSEL,-1,(LPARAM)-1);
SendDlgItemMessage (hwndDlg, IDC_EDIT1, EM_REPLACESEL, 0,
(LPARAM)(LPCTSTR)strbuf);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_ACTIVATE:
break;
}
return (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -