summaryrefslogtreecommitdiff
path: root/external/plyer/platforms/android/irblaster.py
diff options
context:
space:
mode:
Diffstat (limited to 'external/plyer/platforms/android/irblaster.py')
-rw-r--r--external/plyer/platforms/android/irblaster.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/external/plyer/platforms/android/irblaster.py b/external/plyer/platforms/android/irblaster.py
new file mode 100644
index 0000000..6c44717
--- /dev/null
+++ b/external/plyer/platforms/android/irblaster.py
@@ -0,0 +1,54 @@
+from jnius import autoclass
+
+from plyer.facades import IrBlaster
+from plyer.platforms.android import activity, SDK_INT, ANDROID_VERSION
+
+if SDK_INT >= 19:
+ Context = autoclass('android.content.Context')
+ ir_manager = activity.getSystemService(Context.CONSUMER_IR_SERVICE)
+else:
+ ir_manager = None
+
+
+class AndroidIrBlaster(IrBlaster):
+ def _exists(self):
+ if ir_manager and ir_manager.hasIrEmitter():
+ return True
+ return False
+
+ @property
+ def multiply_pulse(self):
+ '''Android 4.4.3+ uses microseconds instead of period counts
+ '''
+ return not (SDK_INT == 19 and
+ int(str(ANDROID_VERSION.RELEASE).rsplit('.', 1)[-1]) < 3)
+
+ def _get_frequencies(self):
+ if not ir_manager:
+ return None
+
+ if hasattr(self, '_frequencies'):
+ return self._frequencies
+
+ ir_frequencies = ir_manager.getCarrierFrequencies()
+ if not ir_frequencies:
+ return []
+
+ frequencies = []
+ for freqrange in ir_frequencies:
+ freq = (freqrange.getMinFrequency(), freqrange.getMaxFrequency())
+ frequencies.append(freq)
+
+ self._frequencies = frequencies
+ return frequencies
+
+ def _transmit(self, frequency, pattern, mode):
+ if self.multiply_pulse and mode == 'period':
+ pattern = self.periods_to_microseconds(frequency, pattern)
+ elif not self.multiply_pulse and mode == 'microseconds':
+ pattern = self.microseconds_to_periods(frequency, pattern)
+ ir_manager.transmit(frequency, pattern)
+
+
+def instance():
+ return AndroidIrBlaster()