Debian Codegraph @

plyer/facades/irblaster.py

raw symbols SCIP
1 '''
2 IrBlaster
3 ============
4
5 The :class:`IrBlaster` provides access to public methods by which your device
6 can act as a remote and could be used to control your TV, AC, Music Player,
7 Projectors, Set top box or anything that can be controlled by a remote.
8
9 .. note::
10 - On Android your app needs the TRANSMIT_IR permission which allows an
11 application to use the device's IR transmitter, If available.
12
13 Simple Examples
14 ---------------
15
16 To get transmit an IR sequence::
17
18 >>> from plyer import irblaster
19 >>> irblaster.transmit(frequency, pattern, mode)
20
21 To get frequencies::
22
23 >>> irblaster.frequencies
24
25 To check if IrBlaster exists::
26
27 >>> irblaster.exists()
28 True/False
29
30 Supported Platforms
31 -------------------
32 Android
33
34 '''
35
36
37 class IrBlaster:
38 '''
39 Infrared blaster facade.
40 '''
41
42 @staticmethod
43 def periods_to_microseconds(frequency, pattern):
44 '''
45 Convert a pattern from period counts to microseconds.
46 '''
47 period = 1000000. / frequency
48 return [period * x for x in pattern]
49
50 @staticmethod
51 def microseconds_to_periods(frequency, pattern):
52 '''
53 Convert a pattern from microseconds to period counts.
54 '''
55 period = 1000000. / frequency
56 return [x / period for x in pattern]
57
58 @property
59 def frequencies(self):
60 '''
61 Property which contains a list of frequency ranges
62 supported by the device in the form:
63
64 [(from1, to1),
65 (from2, to2),
66 ...
67 (fromN, toN)]
68 '''
69 return self.get_frequencies()
70
71 def get_frequencies(self):
72 return self._get_frequencies()
73
74 def transmit(self, frequency, pattern, mode='period'):
75 '''
76 Transmit an IR sequence.
77
78 :parameters:
79 `frequency`: int
80 Carrier frequency for the IR transmission.
81 `pattern`: list[int]
82 Burst pair pattern to transmit.
83 `mode`: str, defaults to 'period'
84 Specifies the format of the pattern values.
85 Can be 'period' or 'microseconds'.
86 '''
87 return self._transmit(frequency, pattern, mode)
88
89 def exists(self):
90 '''
91 Check if the device has an infrared emitter.
92 '''
93 return self._exists()
94
95 # private
96
97 def _get_frequencies(self):
98 raise NotImplementedError()
99
100 def _transmit(self, frequency, pattern, mode):
101 raise NotImplementedError()
102
103 def _exists(self):
104 raise NotImplementedError()