pir

Top  Previous  Next

The pir namespace allows you to control the PIR-1 and PIR-4 from Lua.

Functions

Return Value

Signature

Description

serials

listpir1()

returns a list of pir1 serials

serials

listpir4()

returns a list of pir4 serials

 

transmit(serial, ccf, bitmask, repeats )

sends an IR signal


stopTransmit(serial)

stops sending an IR signal


keyboard(serial, key1, key2, key3, key4 )

sets the keyboard emulation keys

 

pir.transmit(serial, ccf, bitmask, repeats)

serial should be the serial of the PIR (you can find it on the back of the PIR or use listpir1/listpir4. If you pass an empty string it will send out all PIR's attached to the machine.

bitmask depends on the hardware

PIR-1 Bitmask

1 = Back

2 = Front

3 = Both

PIR-4 Bitmask

1 = Port 1

2 = Port 2

4 = Port 3

8 = Port 4

Note that the PIR-4 will only send out one port at time.

Repeats

Repeats dictates how many times the repeat part of the CCF code will be sent. Note that if the CCF code only consists out of repeat codes and you pass 0 for repeat nothing will be sent. So it's generally a good idea to pass at least 1 here.

 

keyboard(serial, key1, key2, key3, key4)

PIR-1 units have a built-in keyboard emulator and can send one of 4 keys depending on which of the contacts was closed. To set what keypress, if any, should be generated use this function. Note that serial must match a connected PIR-1 otherwise this function will fail.

 

Key

Code

Key

Code

a

4

Return

40

b

5

Escape

41

c

6

Backspace

42

d

7

Tab

43

e

8

Space

44

f

9

-

45

g

10

=

46

h

11

[

47

i

12

]

48

j

13

\

49

k

14

;

51

l

15

'

52

m

16

`

53

n

17

,

54

o

18

.

55

p

19

/

56

q

20

Capslock

57

r

21

F1

58

s

22

F2

59

t

23

F3

60

u

24

F4

61

v

25

F5

62

w

26

F6

63

x

27

F7

64

y

28

F8

65

z

29

F9

66

1

30

F10

67

2

31

F11

68

3

32

F12

69

4

33

Right Arrow

79

5

34

Left Arrow

80

6

35

Down Arrow

81

7

36

Up Arrow

82

8

37

Num Lock

83

9

38

Page Up

75

0

39

Page Down

78

 

This is only an excerpt of the scan code table. The full version can be found here (http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf)

 

Setting the key values to 0 will suppress any key presses from being generated.

Example

local pir1s = pir.listpir1()

 

table.print(pir1s)

for i,serial in pairs(pir1s) do

    print(serial, pir.keyboard(serial, 0,0,0,0))

end