VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/DcsCfg/DcsCfgTouch.c
blob: 35530527399420bc24c165a20806202cf600e248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** @file
DCS configuration. Touch devices.

Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov
Copyright (c) 2016. VeraCrypt, Mounir IDRASSI 

This program and the accompanying materials
are licensed and made available under the terms and conditions
of the GNU Lesser General Public License, version 3.0 (LGPL-3.0).

The full text of the license may be found at
https://opensource.org/licenses/LGPL-3.0
**/

#include <Library/CommonLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>

#include "DcsCfg.h"

//////////////////////////////////////////////////////////////////////////
// Touch
//////////////////////////////////////////////////////////////////////////
UINTN       TouchIndex = 0;

void TouchPrintDevicePath(EFI_HANDLE handle) {
	EFI_ABSOLUTE_POINTER_PROTOCOL*		absio = NULL;
	EfiPrintDevicePath(handle);
	TouchGetIO(handle, &absio);
	if (absio != NULL) {
		EFI_STATUS              res;
		EFI_ABSOLUTE_POINTER_STATE		aps;
		SetMem(&aps, sizeof(aps), 0);
		res = absio->GetState(absio, &aps);
		OUT_PRINT(L" - X[%lld,%lld] Y[%lld,%lld] Z[%lld,%lld] A[0x%x] S[%r (%lld,%lld,%lld), 0x%x]",
			absio->Mode->AbsoluteMinX, absio->Mode->AbsoluteMaxX,
			absio->Mode->AbsoluteMinY, absio->Mode->AbsoluteMaxY,
			absio->Mode->AbsoluteMinZ, absio->Mode->AbsoluteMaxZ,
			absio->Mode->Attributes,
			res, aps.CurrentX, aps.CurrentY, aps.CurrentZ, aps.ActiveButtons
			);
	}
}

void TouchPrintDevicePathByIndex(UINTN touchIndex) {
	OUT_PRINT(L"%V%d%N ", touchIndex);
	TouchPrintDevicePath(gTouchHandles[touchIndex]);
}

void TouchPrintDevicePaths(CHAR16* msg) {
	UINTN i;
	OUT_PRINT(msg);
	for (i = 0; i < gTouchCount; ++i) {
		TouchPrintDevicePathByIndex(i);
		OUT_PRINT(L"\n");
	}
}

VOID
PrintTouchList() {
	InitTouch();
	TouchPrintDevicePaths(L"%HTouch handles%N\n");
}

VOID
TestTouch() {
	EFI_ABSOLUTE_POINTER_PROTOCOL*		absio = NULL;
	EFI_HANDLE					handle;
	EFI_STATUS              res;

	InitTouch();
	if (TouchIndex >= gTouchCount) return;
	handle = gTouchHandles[TouchIndex];
	EfiPrintDevicePath(handle);
	TouchGetIO(handle, &absio);
	if (absio != NULL) {
		EFI_ABSOLUTE_POINTER_STATE		aps;
		EFI_EVENT		events[2];
		UINTN EventIndex;

		events[0] = gST->ConIn->WaitForKey;
		events[1] = absio->WaitForInput;
		do {
			gBS->WaitForEvent(2, events, &EventIndex);
			SetMem(&aps, sizeof(aps), 0);
			res = absio->GetState(absio, &aps);
			OUT_PRINT(L" S[%r (%lld,%lld,%lld), 0x%x]",
				res, aps.CurrentX, aps.CurrentY, aps.CurrentZ, aps.ActiveButtons
				);
		} while (EventIndex == 1);
	}
}