📄 unit2.pas
字号:
unit Unit2;
interface
uses
Windows,Forms,Dialogs, activeX, DirectShow9, Classes,Graphics{,ExceptionLog};
const
IID_Daljinsko:TGUID='{5B1FA1FB-4023-4950-818E-7B4BC8834258}';
IID_GetSampleDaljinsko:TGUID='{9490E589-6B17-44EC-9435-5E3587F9FBCE}';
type
EventData=Record
id:Longint;
h:THandle;
unused:Array[0..7] of Byte;
end;
SecondThread = class(TThread)
public
procedure PreLoop();
procedure PostLoop();
protected
procedure Execute; override;
private
function GetBit(Bit:Byte;var BitVal:Byte):Boolean;
public
enum:ICreateDevEnum;
pEnumCat:IEnumMoniker;
pMonker:IMoniker;
cFetched:Longint;
pPropBag:IPropertyBag;
varName:OleVariant;
card:Cardinal;
bFilter:IBaseFilter;
ret:Cardinal;
buf:Byte;
pt:Array[1..$19]of Byte;
pControl:IKsControl;
KsProp:IKsPropertySet;
KSEv:TKSIDENTIFIER;
ED:EventData;
Affinity:DWORD;
StartTime, CurrentTime,EndTime, TimerRes:Int64;
data:Array[0..63]of Int64;
dataSize:Byte;
LastVal:Byte;
t:TRect;
end;
implementation
uses Unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure SecondThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ SecondThread }
procedure SecondThread.Execute;
label Loop1;
var T:DWORD;
begin
PreLoop();
Loop1:
LastVal:=2;
dataSize:=1;
pt[1]:=$12;
QueryPerformanceFrequency(TimerRes);
self.Priority := tpTimeCritical;
T:=WaitForSingleObject(ED.h,INFINITE);
if (T<>0)Then
goto Loop1;
QueryPerformanceCounter(StartTime);
EndTime := Round(StartTime + (0.025 * TimerRes)); // 14 * 1.778mS(clock) = 24.892mS => 25 mS => 0.025S
Assert(KsProp.Get(IID_GetSampleDaljinsko,AMPROPERTY_PIN_CATEGORY,@pt,Sizeof(pt),buf,1,ret)=0,'KsProp.Get didn''t return 0');
if (buf<>0) then
begin
goto Loop1;
end;
repeat
Assert(KsProp.Get(IID_GetSampleDaljinsko,AMPROPERTY_PIN_CATEGORY,@pt,Sizeof(pt),buf,1,ret)=0,'KsProp.Get didn''t return 0');
QueryPerformanceCounter(CurrentTime);
if (buf <> LastVal) then
begin
data[dataSize]:= CurrentTime;
LastVal := buf;
inc (dataSize);
end;
until ((CurrentTime > EndTime)or(dataSize > 63));
self.Priority := tpNormal;
if (dataSize = 1) then
begin
// Unit1.Form1.Label1.Caption:= 'Value: KeyUp';
end
else
begin
data[0]:= data[1] - Round((0.000889) * TimerRes);
StartTime:= data[0];
end;
Synchronize(PostLoop);
goto Loop1;
end;
procedure SecondThread.PreLoop();
begin
//
end;
function SecondThread.GetBit(Bit:Byte;var BitVal:Byte):Boolean;
function GetAtPosition(pos:Int64):Byte;
var c,ret:Byte;
begin
ret:=0;
for c := 0 to dataSize - 1 do
begin
if (data[c] > pos) then
break;
ret := ret xor 1;
end;
result:=ret;
end;
var pos1_4,pos3_4:Byte;
begin
pos1_4:=GetAtPosition(StartTime + (Round(0.001778 * TimerRes) * Bit) + Round(0.0004445 * TimerRes)); // 0.0004445 * 1 / 4
pos3_4:=GetAtPosition(StartTime + (Round(0.001778 * TimerRes) * Bit) + Round(0.0013335 * TimerRes)); // 0.001778 * 3 / 4
if (pos1_4=pos3_4) then
begin
result:=false;
exit;
end;
if (pos3_4<>0) then
BitVal:=0
else
BitVal:=1;
result:=True;
end;
procedure SecondThread.PostLoop();
var Count:Integer;
Value:Longword;
BitVal:Byte;
TSt,TSt2:String;
begin
if(dataSize = 1)then
begin
//Unit1.Form1.Label1.Caption:= 'Value: KeyUp.';
exit;
end;
t.Left:=0;
t.Top:=0;
t.Right:=800;
t.Bottom:=110;
BitVal:=1;
Unit1.form1.Image1.Canvas.FillRect(t);
Unit1.form1.Image1.Canvas.Pen.Color := clGray;
for Count := 0 to 13 do
begin
Unit1.form1.Image1.Canvas.Pixels[Round(((Count+ 0.25) * 0.00179) * 20000),40]:=clBlue;
Unit1.form1.Image1.Canvas.Pixels[Round(((Count+ 0.75) * 0.00179) * 20000),40]:=clGreen;
Unit1.form1.Image1.Canvas.MoveTo(Round(((Count + 1) * 0.00179) * 20000),0);
Unit1.form1.Image1.Canvas.LineTo(Round(((Count + 1) * 0.00179) * 20000),110);
end;
Unit1.form1.Image1.Canvas.Pen.Color := clBlue;
for Count := 0 to dataSize - 1 do
begin
if (Count=0) then
Unit1.form1.Image1.Canvas.MoveTo(0, 105)
else
begin
Unit1.form1.Image1.Canvas.LineTo(Round(((data[Count] - StartTime) / TimerRes) * 20000), 5 + (100 * BitVal));
BitVal := BitVal xor 1;
Unit1.form1.Image1.Canvas.LineTo(Round(((data[Count] - StartTime) / TimerRes) * 20000), 5 + (100 * BitVal));
end;
end;
Unit1.form1.Image1.Canvas.LineTo(550, 5 + (100 * BitVal));
if (dataSize < 1) then
begin
Unit1.Form1.Label1.Caption:= 'Value: Error decoding.';
exit;
end;
Value := 0;
TSt:='';
for Count := 0 to 13 do
begin
if (GetBit(Count,BitVal)=False) then
begin
Unit1.Form1.Label1.Caption:= 'Value: Error decoding.';
exit;
end;
if (BitVal <> 0) then
begin
Value := Value or (1 shl Count );
TSt := TSt + '1';
end
else
TSt := TSt + '0';
end;
Str(Value,TSt2);
Unit1.Form1.Label1.Caption:= 'Value: ' + TSt + #13 + #10 + TSt2;
Unit1.Form1.Button1.Enabled := True;
end;
(*
8722 rec
9490 close
8466 |<
9234 stop
9746 >|
8978 <<
10002 >||
10258 >>
1042 /\
1554 <
10514 enter
530 >
2066 \/
10770 vol+
6418 vol-
4370 back
11026 ch+
2333 ch-
6674 1
4626 2
2578 3
6930 4
4882 5
2834 6
7186 7
5138 8
3090 9
7442 full screen
5394 0
3346 recall
7698 tv
5650 video
3602 home
7954 dvd
5906 picture
3858 dvd/menu
8210 radio
6162 music
4114 mute
*)
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -