├── .gitignore
├── AndroidInfraRed.iml
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── obd
│ │ └── infrared
│ │ └── sample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ ├── button_normal.xml
│ ├── button_pressed.xml
│ └── button_states.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── infrared
├── .gitignore
├── build.gradle
├── infrared.iml
├── libs
│ ├── HTCIR.jar
│ └── QRemoteSDK.jar
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── obd
│ │ └── infrared
│ │ ├── InfraRed.java
│ │ ├── detection
│ │ ├── DeviceDetector.java
│ │ ├── IDetector.java
│ │ ├── InfraRedDetector.java
│ │ └── concrete
│ │ │ ├── ActualDetector.java
│ │ │ ├── HtcDetector.java
│ │ │ ├── LeDetector.java
│ │ │ ├── LgDetector.java
│ │ │ └── ObsoleteSamsungDetector.java
│ │ ├── devices
│ │ ├── IrDevice.java
│ │ └── IrFunction.java
│ │ ├── log
│ │ ├── LogToAir.java
│ │ ├── LogToConsole.java
│ │ ├── LogToEditText.java
│ │ └── Logger.java
│ │ ├── patterns
│ │ ├── PatternAdapter.java
│ │ ├── PatternAdapterType.java
│ │ ├── PatternConverter.java
│ │ ├── PatternConverterUtils.java
│ │ └── PatternType.java
│ │ ├── transmit
│ │ ├── TransmitInfo.java
│ │ ├── Transmitter.java
│ │ ├── TransmitterType.java
│ │ └── concrete
│ │ │ ├── ActualTransmitter.java
│ │ │ ├── HtcTransmitter.java
│ │ │ ├── LeTransmitter.java
│ │ │ ├── LgTransmitter.java
│ │ │ ├── LgWithDeviceTransmitter.java
│ │ │ ├── LgWithoutDeviceTransmitter.java
│ │ │ ├── ObsoleteTransmitter.java
│ │ │ └── UndefinedTransmitter.java
│ │ └── utils
│ │ ├── Constants.java
│ │ └── le
│ │ ├── Device.java
│ │ ├── IControl.java
│ │ ├── IDevice.java
│ │ ├── IRAction.java
│ │ └── IRFunction.java
│ └── res
│ └── values
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /.idea
8 | .idea
--------------------------------------------------------------------------------
/AndroidInfraRed.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Infra Red
2 |
3 | Open source project for transmitting signals via IR-blasters on Android devices
4 |
5 | Created in Android Studio
6 |
7 | Supports Samsung, HTC, some LG devices with IR
8 |
9 | Contains:
10 | - SampleApplication
11 | - InfraRed library
12 |
13 | Email: one.button.developer@gmail.com
14 |
15 |
16 | ## Menu
17 |
18 | - **[Basis](#basis)**
19 | - [Basic theory](#basic-theory)
20 | - [Sequence types](#sequence-types)
21 | - [Converting the patterns](#converting-the-patterns)
22 | - **[How to use](#how-to-use)**
23 | - [0. Include the InfraRed library to your project](#0-include-the-infrared-library-to-your-project)
24 | - [1. Add the following permissions to your AndroidManifest.xml](#1-add-the-following-permissions-to-your-androidmanifestxml)
25 | - [2. Initialize logging](#2-initialize-logging)
26 | - [3. Initialize the InfraRed class](#3-initialize-the-infrared-class)
27 | - [4. Initialize the transmitter](#4-initialize-the-transmitter)
28 | - [5. Initialize the raw patterns](#5-initialize-the-raw-patterns)
29 | - [6. Adapt the patterns for the device that is used to transmit the patterns](#6-adapt-the-patterns-for-the-device-that-is-used-to-transmit-the-patterns)
30 | - [7. Implement the start and stop methods](#7-implement-the-start-and-stop-methods)
31 | - [8. Transmit the adapted patterns via IR](#8-transmit-the-adapted-patterns-via-ir)
32 | - [In addition](#in-addition)
33 | - **[What's in the box?](#whats-in-the-box)**
34 | - [Android project - Sample application](#android-project---sample-application)
35 | - [Android library - Infrared](#android-library---infrared)
36 | - [Logging package](#logging-package)
37 | - [Pattern package](#pattern-package)
38 | - [Detection package](#detection-package)
39 | - [Transmit package](#transmit-package)
40 | - [Infrared class](#infrared-class)
41 |
42 | ## Basis
43 |
44 | ### Basic theory
45 |
46 | In order to remotely control a device via IR, you require a transmitter (mobile phone with IR blaster) and a control signal sequence that you want to send. This sequence is the key to the function that the device is supposed to perform (e.g. the function of a TV to turns itself on). The built-in IR receiver of the controlled device analyzes all incoming signals. When they match a pattern of a particular function, the devices calls that function.
47 |
48 | The control signal sequence consists of two parameters: The frequency (in _Hertz_) and the pattern, which is a time sequence of _ON_/_OFF_ signals on the specified carrier frequency. Such patterns can be found on the Internet.
49 |
50 | ### Sequence types
51 |
52 | The pattern is pictured by a sequence of numbers either of the hexadecimal (_HEX_) or the decimal (_DEC_) numeral system.
53 |
54 | Here's an example:
55 |
56 | ```
57 | Frequency:
58 | 33000 Hertz (33KHz)
59 | Patterns:
60 | 0) 0x01f4 0x1c84 0x01f4 0x00c8 or (01f4 1c84 01f4 00c8)
61 | 1) 500 7300 500 200
62 | 2) 17 241 17 7
63 | ```
64 |
65 | The main difference between the patterns in this example is their notation.
66 | Each number in the pattern describes the duration of a single _ON_/_OFF_ signal, only that patterns 0 and 1 describe it in microseconds, while patterns 2 describes it in cycles.
67 |
68 | One cycle always consists of an an _ON_ and an _OFF_ signal (the image below shows cycles with a frequency of 40000 _Hz_).
69 |
70 | 
71 |
72 | ### Converting the patterns
73 |
74 | The length of a single period _T_ in microseconds equals 1 000 000 (1 second in microseconds) divided by the frequency _f_ (in _Hertz_)
75 |
76 | > _T_ = 1 000 000 _ms_ / _f_
77 |
78 | For example
79 |
80 | > _T_ = 1 000 000 _ms_/ 33000 _Hz_ ≈ 30.3 _ms_
81 |
82 | To covert a microsecond pattern to a cycle pattern, divide each value by _T_
83 |
84 | To convert a cycle pattern to a microsecond pattern, simply multiply each value by _T_
85 |
86 | ## How to use
87 |
88 | ### 0. Include the InfraRed library to your project
89 |
90 | - Download the [AndroidInfraRed](https://github.com/OneButtonDeveloper/AndroidInfraRed) project
91 | - Run the project on a device or an emulator
92 | - Find the **infrared-release.aar** file in the project folder _(infrared/build/outputs/aar/infrared-release.aar)_
93 | - Import this file into your own project in Android Studio
94 | _(File > New > New Module... > Import .JAR/.AAR package)_
95 |
96 | **Tip!** Your can download the **infrared-release.aar** file from [releases](https://github.com/OneButtonDeveloper/AndroidInfraRed/releases/latest)
97 |
98 | **Known issue!** One of the project files contains broken characters. Just rename it again.
99 |
100 | ### 1. Add the following permissions to your AndroidManifest.xml
101 |
102 | ```xml
103 |
104 |
105 | ```
106 |
107 | ### 2. Initialize logging
108 |
109 | You can choose between printing your logs to an _EditText_ view ([_LogToEditText_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToEditText.java)), the _LogCat_ console ([_LogToConsole_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToConsole.java)) and not logging at all ([_LogToAir_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToAir.java))
110 |
111 | ```java
112 | // print log messages to EditText
113 | EditText console = (EditText) this.findViewById(R.id.console);
114 | log = new LogToEditText(console, TAG);
115 |
116 | // print Log messages with Log.d(), Log.w(), Log.e() (LogCat)
117 | // LogToConsole log = new LogToConsole(TAG);
118 |
119 | // Turn off logs
120 | // LogToAir log = new LogToAir(TAG);
121 | ```
122 | [_LogToEditText_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToEditText.java) is the default option
123 |
124 | ### 3. Initialize the [**InfraRed**](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java) class
125 |
126 | Create a new [_InfraRed_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java) object with the parameters _Context_ and [_Logger_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/Logger.java)
127 |
128 | ```java
129 | infraRed = new InfraRed(this, log);
130 | ```
131 |
132 | ### 4. Initialize the transmitter
133 |
134 | ```java
135 | TransmitterType transmitterType = infraRed.detect();
136 |
137 | // initialize transmitter by type
138 | infraRed.createTransmitter(transmitterType);
139 | ```
140 |
141 | The "detect()" method returns the [_TransmitterType_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java). Possible values:
142 |
143 | * Actual - The signals will be transmitted by the ConsumerIrManager
144 | * Obsolete - The signals will be transmitted by a Samsung IR service
145 | * HTC - The signals will be transmitted by the HTC IR SDK
146 | * LG, LG_WithOutDevice - The signals will be transmitted by the QRemote SDK
147 | * Undefined - the "empty" implementation will be used to transmitt the signals
148 |
149 | ### 5. Initialize the raw patterns
150 |
151 | ```java
152 | // initialize raw patterns
153 | List rawPatterns = new ArrayList<>();
154 | // Canon
155 | // rawPatterns.add(new PatternConverter(PatternType.Intervals, 33000, 500, 7300, 500, 200));
156 | // Nikon D7100 v.1
157 | rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 1, 105, 5, 1, 75, 1095, 20, 60, 20, 140, 15, 2500, 80, 1));
158 | // Nikon D7100 v.2
159 | rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 77, 1069, 16, 61, 16, 137, 16, 2427, 77, 1069, 16, 61, 16, 137, 16));
160 | // Nikon D7100 v.3
161 | rawPatterns.add(new PatternConverter(PatternType.Intervals, 38000, 2000, 27800, 400, 1600, 400, 3600, 400, 200));
162 | // Nikon D7100 v.3 fromString
163 | rawPatterns.add(PatternConverterUtils.fromString(PatternType.Intervals, 38000, "2000, 27800, 400, 1600, 400, 3600, 400, 200"));
164 | // Nikon D7100 v.3 fromHexString
165 | rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "0x7d0 0x6c98 0x190 0x640 0x190 0xe10 0x190 0xc8"));
166 | // Nikon D7100 v.3 fromHexString without 0x
167 | rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "7d0 6c98 190 640 190 e10 190 c8"));
168 | ```
169 |
170 | The [_PatternConverter_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternConverter.java) can be used to easily define and convert IR patterns between the different patterns types (Cycles and Intervals in ms)
171 |
172 | ### 6. Adapt the patterns for the device that is used to transmit the patterns
173 |
174 | ```java
175 | PatternAdapter patternAdapter = new PatternAdapter(log);
176 |
177 | // initialize TransmitInfoArray
178 | TransmitInfo[] transmitInfoArray = new TransmitInfo[rawPatterns.size()];
179 | for (int i = 0; i < transmitInfoArray.length; i++) {
180 | transmitInfoArray[i] = patternAdapter.createTransmitInfo(rawPatterns.get(i));
181 | }
182 | this.patterns = transmitInfoArray;
183 | ```
184 |
185 | [_PatternAdapter_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapter.java) automatically detects the device's manufacturer (_LG_/_HTC_/_Samsung_) and uses that information to determine how the raw patterns have to be converted in order to be compatible with the transmitter of the used device.
186 |
187 | ### 7. Implement the start and stop methods
188 |
189 | ```java
190 | @Override
191 | protected void onResume() {
192 | super.onResume();
193 | infraRed.start();
194 | }
195 |
196 | @Override
197 | protected void onDestroy() {
198 | super.onDestroy();
199 |
200 | infraRed.stop();
201 |
202 | if (log != null) {
203 | log.destroy();
204 | }
205 | }
206 | ```
207 |
208 | Always call the _start()_ method before transmit IR signals and call the _stop()_ method when you are done.
209 |
210 | It is a **good idea** to call them in the _onCreate_/_onDestroy_ or _onResume_/_onPause_ methods.
211 |
212 |
213 | ### 8. Transmit the adapted patterns via IR
214 |
215 | ```java
216 | private int currentPattern = 0;
217 |
218 | @Override
219 | public void onClick(View v) {
220 | TransmitInfo transmitInfo = patterns[currentPattern++];
221 | if (currentPattern >= patterns.length) currentPattern = 0;
222 | infraRed.transmit(transmitInfo);
223 | }
224 | ```
225 |
226 | Now we can send IR signals ([_TransmitInfo_](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java)) to the device we want to control
227 |
228 | ### In addition
229 |
230 | Examples for the individual steps can be found in this project
231 |
232 | - Step 1 in [AndroidManifest.xml](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/AndroidManifest.xml)
233 | - Steps 2..8 in [MainActivity.java](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/app/src/main/java/com/obd/infrared/sample/MainActivity.java)
234 |
235 | ## What's in the box?
236 |
237 |
238 | ### Android Project - [Sample Application](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/app)
239 |
240 | The sample project gives you an idea how the infrared library is supposed to be used. The project contains an activity ([MainActivity.java](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/app/src/main/java/com/obd/infrared/sample/MainActivity.java)) with a predefined layout ([activity_main.xml](AndroidInfraRed/app/src/main/res/layout/activity_main.xml)). The layout contains a console ([EditText](http://developer.android.com/intl/ru/reference/android/widget/EditText.html)) and a IR button.
241 |
242 | The _onCreate()_ method contains the full initialization of the [InfraRed](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java) library
243 |
244 | When you run the application, the console will show you what is happening inside the library. When you click on the button, the IR blaster on your device will send a IR signal, of course only if your device is supported by the library.
245 |
246 | Please note that you wont get any runtime exceptions because your device is not supported.
247 |
248 | Logging to a [EditText](http://developer.android.com/intl/ru/reference/android/widget/EditText.html) can be quite useful when you want to understand what's happening on your customer's devices. I often send special .apk files to users in order to obtain a log from their devices.
249 |
250 |
251 |
252 | ### Android Library - [**Infrared**](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared)
253 |
254 | This library allows you to easily create raw IR signals in code, to detect device types and adapt raw signals for specific devices, to detect the devices' IR transmitters and to use them to send the adapted IR signals to a devices with a IR receiver.
255 |
256 | The [Library](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared) consists of several packages that are explained below.
257 |
258 |
259 | #### [Logging package](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/log)
260 |
261 | Provides different ways to log data. All classes in this package inherit from the [Logger](AndroidInfraRed/infrared/src/main/java/com/obd/infrared/log/Logger.java) class.
262 |
263 | [LogToConsole](AndroidInfraRed/infrared/src/main/java/com/obd/infrared/log/LogToConsole.java) is useful when your can debug the application on a device that is connected to an IDE with LogCat.
264 |
265 | [LogToEditText](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToEditText.java) can be used to to display the log messages on the user's screen.
266 |
267 | [LogToAir](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/log/LogToAir.java) won't log anything (you can apply this in your application's release version)
268 |
269 |
270 | #### [Pattern package](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/patterns)
271 |
272 | Enum [PatternType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternType.java) tetermines the type of the IR signals in an integer array (a single value in the array is either the number of cycles or the time interval in microseconds).
273 |
274 | The [PatternConverter](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternConverter.java) class allows you to convert patterns from one pattern type to another.
275 |
276 | The [PatternConverterUtils](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternConverterUtils.java) class can be used to create PatternConverter objects from strings containing a pattern in the DEC or HEX numeral system.
277 |
278 | [PatternAdapterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapterType.java) enum contains values that are required to convert raw patterns. It also includes a method that determines which pattern type will be in use on the current device. It returns _ToIntervals_ by default, which will convert all raw patterns to time interval based patterns.
279 |
280 | The [PatternAdapter](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapter.java) class will help you to adapt [PatternConverter](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternConverter.java) instances to [TransmitInfo](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java) objects according to the [PatternAdapterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapterType.java) enum.
281 |
282 |
283 | #### [Detection package](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/detection)
284 |
285 | The [DeviceDetector](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/detection/DeviceDetector.java) class is used to determine the manufacturer of the user's device by checking Android's Build.MANUFACTURER constant. This information is required in order to adapt the IR signals correctly.
286 |
287 | The [InfraRedDetector](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/detection/InfraRedDetector.java) class checks if the devices has a built-in IR blaster. This procedure may vary depending on the IR Blaster, so there are a few different classes for this feature with a common interface named [IDetector](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/detection/IDetector.java). Concrete implementations of the [IDetector](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/detection/IDetector.java) can be found in the _["infrared/detection/concrete"](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/detection/concrete)_ folder.
288 |
289 | [InfraRedDetector](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/detection/InfraRedDetector.java) has a main function _detect()_ that verifies the availability of each initialized detector and returns corresponding [TransmitterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java). The method returns _TransmitterType.Undefined_ if the device is not supported.
290 |
291 |
292 | #### [Transmit package](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/transmit)
293 |
294 | [TransmitterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java) enum contains the supported transmitters which also includes the Undefined transmitter.
295 |
296 | The [TransmitInfo](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java) class contains the adapted IR signal data that will be send by the device's IR blaster.
297 |
298 | The [Transmitter](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/Transmitter.java) class the is general interface type for all transmitters. Concrete implementations of them can be found in the _["infrared/transmit/concrete"](https://github.com/OneButtonDeveloper/AndroidInfraRed/tree/master/infrared/src/main/java/com/obd/infrared/transmit/concrete)_ folder. Each transmitter can implement _start()_ and _stop()_ methods and must have a transmit function that sends the pattern data with a [TransmitInfo](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java).
299 |
300 | A [Transmitter](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/Transmitter.java) can initialize concrete transmitters based on the [TransmitterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java).
301 |
302 |
303 | #### [InfraRed class](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java)
304 |
305 | The [InfraRed](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java) class integrate packages functionality to easily use library.
306 |
307 | 1. Create [InfraRed](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/InfraRed.java) class
308 | 2. Call the _detect()_ method to get the [TransmitterType](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java)
309 | 3. Call the _createTransmitter()_ method to initialize a concrete transmitter
310 | 4. Call the _start()_ method
311 | 5. Send different IR signals ([TransmitInfo](https://github.com/OneButtonDeveloper/AndroidInfraRed/blob/master/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java) objects) with the _transmit()_ function
312 |
313 | **!** Don't forget to call _stop()_ once you are done!
314 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateReleaseSources
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 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | android {
3 | compileSdkVersion 25
4 | buildToolsVersion '26.0.2'
5 |
6 | defaultConfig {
7 | applicationId "com.obd.infrared.sample"
8 | minSdkVersion 9
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | packagingOptions {
22 | exclude 'META-INF/DEPENDENCIES.txt'
23 | exclude 'META-INF/LICENSE.txt'
24 | exclude 'META-INF/NOTICE.txt'
25 | exclude 'META-INF/NOTICE'
26 | exclude 'META-INF/LICENSE'
27 | exclude 'META-INF/DEPENDENCIES'
28 | exclude 'META-INF/notice.txt'
29 | exclude 'META-INF/license.txt'
30 | exclude 'META-INF/dependencies.txt'
31 | exclude 'META-INF/LGPL2.1'
32 | exclude 'AndroidManifest.xml'
33 | }
34 | }
35 | dependencies {
36 | compile fileTree(include: ['*.jar'], dir: 'libs')
37 | compile 'com.android.support:appcompat-v7:25.4.0'
38 | compile project(':infrared')
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/andrew/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/obd/infrared/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.sample;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 |
10 | import com.obd.infrared.InfraRed;
11 | import com.obd.infrared.log.LogToEditText;
12 | import com.obd.infrared.patterns.PatternAdapter;
13 | import com.obd.infrared.patterns.PatternConverter;
14 | import com.obd.infrared.patterns.PatternType;
15 | import com.obd.infrared.transmit.TransmitInfo;
16 | import com.obd.infrared.transmit.TransmitterType;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 |
22 | public class MainActivity extends ActionBarActivity implements View.OnClickListener {
23 |
24 | private LogToEditText log;
25 | private InfraRed infraRed;
26 | private TransmitInfo[] patterns;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | String TAG = "IR";
33 |
34 | Button transmitButton = (Button) this.findViewById(R.id.transmit_button);
35 | transmitButton.setOnClickListener(this);
36 |
37 | // Log messages print to EditText
38 | EditText console = (EditText) this.findViewById(R.id.console);
39 | log = new LogToEditText(console, TAG);
40 |
41 | // Log messages print with Log.d(), Log.w(), Log.e()
42 | // LogToConsole log = new LogToConsole(TAG);
43 |
44 | // Turn off log
45 | // LogToAir log = new LogToAir(TAG);
46 |
47 | infraRed = new InfraRed(this.getApplication(), log);
48 | // detect transmitter type
49 | TransmitterType transmitterType = infraRed.detect();
50 | log.log("TransmitterType: " + transmitterType);
51 |
52 | // initialize transmitter by type
53 | infraRed.createTransmitter(transmitterType);
54 |
55 | // initialize raw patterns
56 | List rawPatterns = new ArrayList<>();
57 |
58 | // Pentax AF
59 | rawPatterns.add(new PatternConverter(PatternType.Cycles, 38000,494,114,38,38,38,38,38,38,38,38,38,38,38,114,38,1));
60 | // Canon
61 | // rawPatterns.add(new PatternConverter(PatternType.Intervals, 33000, 500, 7300, 500, 200));
62 | // rawPatterns.add(new PatternConverter(PatternType.Intervals, 33000, 555, 5250, 555, 7143, 555, 200));
63 | // rawPatterns.add(new PatternConverter(PatternType.Intervals, 33000, 555, 5250, 555, 7143, 555, 1000, 555, 5250, 555, 7143, 555, 1000));
64 |
65 | // // Nikon v.1
66 | // rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 1, 105, 5, 1, 75, 1095, 20, 60, 20, 140, 15, 2500, 80, 1));
67 | // // Nikon v.2
68 | // rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 77, 1069, 16, 61, 16, 137, 16, 2427, 77, 1069, 16, 61, 16, 137, 16));
69 | // // Nikon v.3
70 | // rawPatterns.add(new PatternConverter(PatternType.Intervals, 38000, 2000, 27800, 400, 1600, 400, 3600, 400, 200));
71 | // // Nikon v.3 fromString
72 | // rawPatterns.add(PatternConverterUtils.fromString(PatternType.Intervals, 38000, "2000, 27800, 400, 1600, 400, 3600, 400, 200"));
73 | // // Nikon v.3 fromHexString
74 | // rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "0x7d0 0x6c98 0x190 0x640 0x190 0xe10 0x190 0xc8"));
75 | // // Nikon v.3 fromHexString without 0x
76 | // rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "7d0 6c98 190 640 190 e10 190 c8"));
77 |
78 | logDeviceInfo();
79 |
80 | // adapt the patterns for the device that is used to transmit the patterns
81 | PatternAdapter patternAdapter = new PatternAdapter(log, transmitterType);
82 |
83 | TransmitInfo[] transmitInfoArray = new TransmitInfo[rawPatterns.size()];
84 | for (int i = 0; i < transmitInfoArray.length; i++) {
85 | transmitInfoArray[i] = patternAdapter.createTransmitInfo(rawPatterns.get(i));
86 | }
87 | this.patterns = transmitInfoArray;
88 |
89 | for (TransmitInfo transmitInfo : this.patterns) {
90 | log.log(transmitInfo.toString());
91 | }
92 |
93 | }
94 |
95 | private void logDeviceInfo() {
96 | log.log("BRAND: " + Build.BRAND);
97 | log.log("DEVICE: " + Build.DEVICE);
98 | log.log("MANUFACTURER: " + Build.MANUFACTURER);
99 | log.log("MODEL: " + Build.MODEL);
100 | log.log("PRODUCT: " + Build.PRODUCT);
101 | log.log("CODENAME: " + Build.VERSION.CODENAME);
102 | log.log("RELEASE: " + Build.VERSION.RELEASE);
103 | log.log("SDK_INT: " + Build.VERSION.SDK_INT);
104 | }
105 |
106 |
107 | @Override
108 | protected void onResume() {
109 | super.onResume();
110 | infraRed.start();
111 | }
112 |
113 |
114 | private int currentPattern = 0;
115 |
116 | @Override
117 | public void onClick(View v) {
118 | log.log("Version: " + currentPattern);
119 | TransmitInfo transmitInfo = patterns[currentPattern++];
120 | if (currentPattern >= patterns.length) currentPattern = 0;
121 | infraRed.transmit(transmitInfo);
122 | }
123 |
124 |
125 | @Override
126 | protected void onDestroy() {
127 | super.onDestroy();
128 |
129 | infraRed.stop();
130 |
131 | if (log != null) {
132 | log.destroy();
133 | }
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_normal.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_pressed.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_states.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
21 |
22 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #AA000000
4 | #FFF
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 8sp
4 | 1dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Infra Red Sample
3 | Console:\n
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.0.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | maven {
21 | url "https://maven.google.com"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 19 10:59:57 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/infrared/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/infrared/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion 24
4 | buildToolsVersion '26.0.2'
5 |
6 | defaultConfig {
7 | minSdkVersion 8
8 | targetSdkVersion 24
9 |
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | packagingOptions {
22 | exclude 'AndroidManifest.xml'
23 | }
24 | }
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | compile 'com.android.support:appcompat-v7:24.1.1'
28 | compile files('libs/HTCIR.jar')
29 | compile files('libs/QRemoteSDK.jar')
30 | }
31 | task clearJar(type: Delete) {
32 | delete 'build/outputs/infrared.jar'
33 | }
34 | task makeJar(type: Copy) {
35 | from('build/intermediates/bundles/release/')
36 | into('build/outputs/')
37 | include('classes.jar')
38 | rename('classes.jar', 'infrared.jar')
39 | }
40 |
--------------------------------------------------------------------------------
/infrared/infrared.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateReleaseSources
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 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/infrared/libs/HTCIR.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/infrared/libs/HTCIR.jar
--------------------------------------------------------------------------------
/infrared/libs/QRemoteSDK.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneButtonDeveloper/AndroidInfraRed/078e8764d9312a4354d9e6f763fda8dd776a3643/infrared/libs/QRemoteSDK.jar
--------------------------------------------------------------------------------
/infrared/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/andrew/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/infrared/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/InfraRed.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.util.Log;
6 |
7 | import com.obd.infrared.detection.InfraRedDetector;
8 | import com.obd.infrared.devices.IrDevice;
9 | import com.obd.infrared.log.Logger;
10 | import com.obd.infrared.transmit.TransmitInfo;
11 | import com.obd.infrared.transmit.Transmitter;
12 | import com.obd.infrared.transmit.TransmitterType;
13 |
14 | import java.util.List;
15 |
16 | public class InfraRed {
17 |
18 | // v3.5.2 -> Added duration for transmitting with devices
19 | // v3.5.1 -> Fixed bug with getting Ir functions for Lg and Le
20 | // v3.5 -> Added support for getting ir-devices for Lg and Le
21 | // v3.4 -> Added support for Le Eco devices
22 | private static final String VERSION = "InfraRed v3.5.2";
23 |
24 | private final Context context;
25 | private final Logger logger;
26 |
27 | public InfraRed(@NonNull Context context, @NonNull Logger logger) {
28 | this.context = context;
29 | this.logger = logger;
30 | Log.w("IR", VERSION);
31 | logger.log(VERSION);
32 | }
33 |
34 |
35 | public TransmitterType detect() {
36 | InfraRedDetector detector = new InfraRedDetector(context, logger);
37 | return detector.detect();
38 | }
39 |
40 |
41 | private Transmitter transmitter;
42 | private TransmitterType transmitterType;
43 |
44 | public boolean hasIrDevices() {
45 | return transmitterType.hasIrDevices();
46 | }
47 |
48 | public boolean isReady() {
49 | return transmitter != null && transmitter.isReady();
50 | }
51 |
52 | public void createTransmitter(TransmitterType transmitterType) {
53 | if (transmitter == null) {
54 | try {
55 | this.transmitterType = transmitterType;
56 | transmitter = Transmitter.getTransmitterByType(transmitterType, context, logger);
57 | } catch (Exception e) {
58 | logger.error("Error on create transmitter: " + transmitterType, e);
59 | }
60 | } else {
61 | logger.warning("Transmitter already created!");
62 | }
63 | }
64 |
65 | public boolean transmit(TransmitInfo transmitInfo) {
66 | try {
67 | transmitter.transmit(transmitInfo);
68 | return true;
69 | } catch (Exception e) {
70 | logger.error("Cannot transmit data", e);
71 | return false;
72 | }
73 | }
74 |
75 | public List getDevices() {
76 | if (transmitterType.hasIrDevices()) {
77 | logger.log("getIrDevices");
78 | return transmitter.getIrDevices(logger);
79 | } else {
80 | logger.log("no IrDevices");
81 | return null;
82 | }
83 | }
84 |
85 | public void transmit(int deviceId, int functionId, int duration) {
86 | if (transmitterType.hasIrDevices()) {
87 | transmitter.transmit(deviceId, functionId, duration);
88 | } else {
89 | logger.log("Transmitting by device id " + deviceId + " and function id " + functionId + " with duration " + duration + " not supported");
90 | }
91 | }
92 |
93 | public void start() {
94 | try {
95 | transmitter.start();
96 | } catch (Exception e) {
97 | logger.error("Cannot start transmitter", e);
98 | }
99 | }
100 |
101 | public void stop() {
102 | try {
103 | transmitter.stop();
104 | } catch (Exception e) {
105 | logger.error("Cannot stop transmitter", e);
106 | }
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/DeviceDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection;
2 |
3 | import android.os.Build;
4 |
5 | public class DeviceDetector {
6 |
7 | public static boolean isSamsung() {
8 | return isDevice("SAMSUNG");
9 | }
10 |
11 | public static boolean isLg() {
12 | return isDevice("LG") || isDevice("LGE");
13 | }
14 |
15 | public static boolean isHtc() {
16 | return isDevice("HTC");
17 | }
18 |
19 | public static boolean isLe() {
20 | return isDevice("LE") || isDevice("LEECO") || isDevice("LETV") || isDevice("COOLPAD") || isDevice("LETVITWO");
21 | }
22 |
23 | private static boolean isDevice(String manufactureName) {
24 | return Build.MANUFACTURER.equalsIgnoreCase(manufactureName);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/IDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection;
2 |
3 |
4 | import com.obd.infrared.transmit.TransmitterType;
5 |
6 | public interface IDetector {
7 | boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams);
8 | TransmitterType getTransmitterType();
9 | }
10 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/InfraRedDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection;
2 |
3 | import android.content.Context;
4 | import android.content.pm.ApplicationInfo;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 |
8 | import com.obd.infrared.detection.concrete.ActualDetector;
9 | import com.obd.infrared.detection.concrete.HtcDetector;
10 | import com.obd.infrared.detection.concrete.LeDetector;
11 | import com.obd.infrared.detection.concrete.LgDetector;
12 | import com.obd.infrared.detection.concrete.ObsoleteSamsungDetector;
13 | import com.obd.infrared.log.Logger;
14 | import com.obd.infrared.transmit.TransmitterType;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | public class InfraRedDetector {
20 | public static class DetectorParams {
21 | public final Context context;
22 | public final Logger logger;
23 |
24 | public DetectorParams(Context context, Logger logger) {
25 | this.context = context;
26 | this.logger = logger;
27 | }
28 |
29 |
30 | public boolean hasAnyPackage(String... packageNames) {
31 | PackageManager manager = context.getPackageManager();
32 | List packages = manager.getInstalledApplications(0);
33 | for (ApplicationInfo info : packages) {
34 | for (String packageName : packageNames) {
35 | if (info.packageName.startsWith("com.uei.")) {
36 | logger.log("Package: " + info.packageName);
37 | }
38 | if (info.packageName.contains(packageName)) {
39 | return true;
40 | }
41 | }
42 | }
43 | return false;
44 | }
45 |
46 | }
47 |
48 | protected final DetectorParams detectorParams;
49 | protected final List detectors = new ArrayList<>();
50 |
51 | public InfraRedDetector(Context context, Logger logger) {
52 | this.detectorParams = new DetectorParams(context, logger);
53 |
54 | logger.log("Build.MANUFACTURER: " + Build.MANUFACTURER);
55 |
56 | this.detectors.add(new LgDetector());
57 | this.detectors.add(new HtcDetector());
58 | this.detectors.add(new LeDetector());
59 | this.detectors.add(new ObsoleteSamsungDetector());
60 | this.detectors.add(new ActualDetector());
61 | }
62 |
63 | private TransmitterType detect(DetectorParams detectorParams) {
64 | for (IDetector detector : detectors) {
65 | if (detector.hasTransmitter(detectorParams)) {
66 | return detector.getTransmitterType();
67 | }
68 | }
69 | return TransmitterType.Undefined;
70 | }
71 |
72 | public TransmitterType detect() {
73 | detectorParams.logger.log("Detection started");
74 | TransmitterType transmitterType = detect(detectorParams);
75 | detectorParams.logger.log("Detection result: " + transmitterType);
76 | return transmitterType;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/concrete/ActualDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection.concrete;
2 |
3 | import android.annotation.TargetApi;
4 | import android.hardware.ConsumerIrManager;
5 | import android.os.Build;
6 |
7 | import com.obd.infrared.detection.IDetector;
8 | import com.obd.infrared.detection.InfraRedDetector;
9 | import com.obd.infrared.transmit.TransmitInfo;
10 | import com.obd.infrared.transmit.TransmitterType;
11 |
12 | import static android.content.Context.CONSUMER_IR_SERVICE;
13 |
14 | public class ActualDetector implements IDetector {
15 |
16 | @Override
17 | public boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams) {
18 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && hasActualIR(detectorParams);
19 | }
20 |
21 | @SuppressWarnings("ResourceType")
22 | @TargetApi(Build.VERSION_CODES.KITKAT)
23 | private boolean hasActualIR(InfraRedDetector.DetectorParams detectorParams) {
24 | try {
25 | detectorParams.logger.log("Check CONSUMER_IR_SERVICE");
26 | ConsumerIrManager consumerIrManager = (ConsumerIrManager) detectorParams.context.getSystemService(CONSUMER_IR_SERVICE);
27 | if (consumerIrManager != null && consumerIrManager.hasIrEmitter()) {
28 |
29 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
30 | logCarrierFrequencies(detectorParams, consumerIrManager);
31 | }
32 |
33 | detectorParams.logger.log("CONSUMER_IR_SERVICE: must be included TRANSMIT_IR permission to AndroidManifest.xml");
34 | TransmitInfo transmitInfo = new TransmitInfo(38000, new int[]{100, 100, 100, 100});
35 | consumerIrManager.transmit(transmitInfo.frequency, transmitInfo.pattern);
36 |
37 | detectorParams.logger.log("CONSUMER_IR_SERVICE: hasIrEmitter is true");
38 | return true;
39 | } else {
40 | detectorParams.logger.log("CONSUMER_IR_SERVICE: hasIrEmitter is false");
41 | return false;
42 | }
43 | } catch (Exception e) {
44 | detectorParams.logger.error("On actual transmitter error", e);
45 | return false;
46 | }
47 | }
48 |
49 | @TargetApi(Build.VERSION_CODES.KITKAT)
50 | private void logCarrierFrequencies(InfraRedDetector.DetectorParams detectorParams, ConsumerIrManager consumerIrManager) {
51 | try {
52 | ConsumerIrManager.CarrierFrequencyRange[] carrierFrequencies = consumerIrManager.getCarrierFrequencies();
53 | if (carrierFrequencies != null && carrierFrequencies.length > 0) {
54 | for (ConsumerIrManager.CarrierFrequencyRange carrierFrequencyRange : carrierFrequencies) {
55 | detectorParams.logger.log("carrierFrequencyRange: MIN" + carrierFrequencyRange.getMinFrequency());
56 | detectorParams.logger.log("carrierFrequencyRange: MAX" + carrierFrequencyRange.getMaxFrequency());
57 | }
58 | } else {
59 | detectorParams.logger.log("carrierFrequencies is empty or null");
60 | }
61 | } catch (Exception e) {
62 | detectorParams.logger.error("getCarrierFrequencies", e);
63 | }
64 | }
65 |
66 | @Override
67 | public TransmitterType getTransmitterType() {
68 | return TransmitterType.Actual;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/concrete/HtcDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection.concrete;
2 |
3 | import com.obd.infrared.detection.IDetector;
4 | import com.obd.infrared.detection.InfraRedDetector;
5 | import com.obd.infrared.transmit.TransmitterType;
6 |
7 | public class HtcDetector implements IDetector {
8 |
9 | /**
10 | * Code from samples in HTC IR SDK
11 | */
12 | @Override
13 | public boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams) {
14 | try {
15 | boolean hasPackage = detectorParams.hasAnyPackage("com.htc.cirmodule");
16 | detectorParams.logger.log("Check HTC IR interface: " + hasPackage);
17 | return hasPackage;
18 | } catch (Exception e) {
19 | detectorParams.logger.error("On HTC ir error", e);
20 | return false;
21 | }
22 | }
23 |
24 |
25 | @Override
26 | public TransmitterType getTransmitterType() {
27 | return TransmitterType.HTC;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/concrete/LeDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection.concrete;
2 |
3 | import com.obd.infrared.detection.IDetector;
4 | import com.obd.infrared.detection.InfraRedDetector;
5 | import com.obd.infrared.transmit.TransmitterType;
6 | import com.obd.infrared.utils.Constants;
7 |
8 | /**
9 | * Created by Andrew on 20.10.2017
10 | */
11 |
12 | public class LeDetector implements IDetector {
13 | @Override
14 | public boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams) {
15 | try {
16 | boolean hasPackage = detectorParams.hasAnyPackage(Constants.LE_COOLPAD_IR_SERVICE_PACKAGE, Constants.LE_DEFAULT_IR_SERVICE_PACKAGE_2);
17 | detectorParams.logger.log("Check Le IR interface: " + hasPackage);
18 | return hasPackage;
19 | } catch (Exception e) {
20 | detectorParams.logger.error("On Le ir error", e);
21 | return false;
22 | }
23 | }
24 |
25 | @Override
26 | public TransmitterType getTransmitterType() {
27 | return TransmitterType.Le;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/concrete/LgDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection.concrete;
2 |
3 | import android.os.Build;
4 |
5 | import com.lge.hardware.IRBlaster.IRBlaster;
6 | import com.obd.infrared.detection.DeviceDetector;
7 | import com.obd.infrared.detection.IDetector;
8 | import com.obd.infrared.detection.InfraRedDetector;
9 | import com.obd.infrared.transmit.TransmitterType;
10 |
11 | public class LgDetector implements IDetector {
12 |
13 | private TransmitterType transmitterType = TransmitterType.LG;
14 |
15 | @Override
16 | public boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams) {
17 | try {
18 | detectorParams.logger.log("Check LG: " + DeviceDetector.isLg());
19 | if (DeviceDetector.isLg()) {
20 | // in the Android version 5.1 on LG G4 work ConsumerIRManager
21 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
22 | ActualDetector actualDetector = new ActualDetector();
23 | if (actualDetector.hasTransmitter(detectorParams)) {
24 | transmitterType = TransmitterType.LG_Actual;
25 | return true;
26 | }
27 | }
28 |
29 | boolean isSdkSupported = IRBlaster.isSdkSupported(detectorParams.context);
30 | detectorParams.logger.log("Check LG IRBlaster " + isSdkSupported);
31 | return isSdkSupported;
32 | } else {
33 | return false;
34 | }
35 | } catch (Exception e) {
36 | detectorParams.logger.error("On LG ir detection error", e);
37 | return false;
38 | }
39 | }
40 |
41 | @Override
42 | public TransmitterType getTransmitterType() {
43 | return transmitterType;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/detection/concrete/ObsoleteSamsungDetector.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.detection.concrete;
2 |
3 | import com.obd.infrared.detection.IDetector;
4 | import com.obd.infrared.detection.InfraRedDetector;
5 | import com.obd.infrared.transmit.TransmitterType;
6 |
7 | import java.lang.reflect.Method;
8 |
9 | public class ObsoleteSamsungDetector implements IDetector {
10 |
11 | @SuppressWarnings({"ResourceType", "SpellCheckingInspection", "RedundantArrayCreation"})
12 | @Override
13 | public boolean hasTransmitter(InfraRedDetector.DetectorParams detectorParams) {
14 | try {
15 | detectorParams.logger.log("Check obsolete Samsung IR interface");
16 | Object irdaService = detectorParams.context.getSystemService("irda");
17 | if (irdaService == null) {
18 | detectorParams.logger.log("Not found obsolete Samsung IR service");
19 | return false;
20 | }
21 | detectorParams.logger.log("Got irdaService");
22 | Method write_irsend = irdaService.getClass().getMethod("write_irsend", new Class[]{String.class});
23 | detectorParams.logger.log("Got write_irsend");
24 |
25 | detectorParams.logger.log("Try to send ir command");
26 | write_irsend.invoke(irdaService, "38000,100,100,100,100");
27 | detectorParams.logger.log("Called write_irsend.invoke");
28 | return true;
29 | } catch (Exception e) {
30 | detectorParams.logger.error("On obsolete transmitter error", e);
31 | return false;
32 | }
33 | }
34 |
35 | @Override
36 | public TransmitterType getTransmitterType() {
37 | return TransmitterType.Obsolete;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/devices/IrDevice.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.devices;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class IrDevice {
7 |
8 | private int id;
9 | private String name;
10 | private List functions = new ArrayList<>();
11 |
12 | public IrDevice(int id, String name) {
13 | this.id = id;
14 | this.name = name == null || name.trim().length() <= 0 ? "D:" + id : name.trim();
15 | }
16 |
17 | public int getId() {
18 | return id;
19 | }
20 |
21 | public String getName() {
22 | return name;
23 | }
24 |
25 | public List getFunctions() {
26 | return functions;
27 | }
28 |
29 | public void addFunction(IrFunction function) {
30 | if (function != null)
31 | functions.add(function);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/devices/IrFunction.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.devices;
2 |
3 | public class IrFunction {
4 | private int id;
5 | private String name;
6 | private Boolean isLearned;
7 |
8 | public IrFunction(int id, String name, Boolean isLearned) {
9 | this.id = id;
10 | this.name = name == null || name.trim().length() <= 0 ? "V:" + id : name.trim();
11 | this.isLearned = isLearned;
12 | }
13 |
14 | public int getId() {
15 | return id;
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public Boolean getIsLearned() {
23 | return isLearned;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/log/LogToAir.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.log;
2 |
3 | public class LogToAir extends Logger {
4 |
5 | public LogToAir(String tag) {
6 | super(tag);
7 | }
8 |
9 | @Override
10 | public void log(String message) {
11 | }
12 |
13 | @Override
14 | public void warning(String message) {
15 | }
16 |
17 | @Override
18 | public void error(String description, Exception exception) {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/log/LogToConsole.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.log;
2 |
3 | import android.util.Log;
4 |
5 | public class LogToConsole extends Logger {
6 |
7 | public LogToConsole(String tag) {
8 | super(tag);
9 | }
10 |
11 | @Override
12 | public void log(String message) {
13 | Log.d(tag, message);
14 | }
15 |
16 | @Override
17 | public void warning(String message) {
18 | Log.w(tag, message);
19 | }
20 |
21 | @Override
22 | public void error(String description, Exception exception) {
23 | Log.e(tag, "ERROR { Description: " + description + "; Exception: " + exception.getMessage() + " }");
24 | exception.printStackTrace();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/log/LogToEditText.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.log;
2 |
3 | import android.os.Handler;
4 | import android.widget.EditText;
5 |
6 | import java.util.LinkedList;
7 | import java.util.Queue;
8 |
9 | public class LogToEditText extends Logger {
10 |
11 | protected final EditText textView;
12 | protected final String lineSeparator;
13 |
14 | public LogToEditText(EditText textView, String tag) {
15 | super(tag);
16 | this.textView = textView;
17 | this.lineSeparator = System.getProperty("line.separator");
18 |
19 | runHandler();
20 | }
21 |
22 | private boolean wasDestroyed = false;
23 |
24 | public void destroy() {
25 | wasDestroyed = true;
26 | }
27 |
28 | private void runHandler() {
29 | final Handler handler = new Handler();
30 | handler.postDelayed(new Runnable() {
31 | @Override
32 | public void run() {
33 | boolean hasNew = false;
34 | while (!strings.isEmpty()) {
35 | hasNew = true;
36 | textView.append(strings.remove() + lineSeparator);
37 | }
38 | if (hasNew) {
39 | textView.setSelection(textView.getText().length());
40 | }
41 | if (!wasDestroyed) {
42 | handler.postDelayed(this, 100);
43 | }
44 | }
45 | }, 0);
46 | }
47 |
48 | private final Queue strings = new LinkedList<>();
49 |
50 | @Override
51 | public void log(String message) {
52 | strings.add("DEBUG [" + tag + "]: " + message);
53 | }
54 |
55 | @Override
56 | public void warning(String message) {
57 | strings.add("WARNING [" + tag + "]: " + message);
58 | }
59 |
60 | @Override
61 | public void error(String description, Exception exception) {
62 | strings.add("ERROR [" + tag + "]: ERROR { Description: " + description + "; Exception: " + exception.getMessage() + " }");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/log/Logger.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.log;
2 |
3 | import android.os.Handler;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.InputStreamReader;
7 |
8 | public abstract class Logger {
9 | protected final String tag;
10 |
11 | public Logger(String tag) {
12 | this.tag = tag;
13 | }
14 |
15 | public abstract void log(String message);
16 |
17 | public abstract void warning(String message);
18 |
19 | public abstract void error(String description, Exception exception);
20 |
21 | public void printLogCat(int delay) {
22 | Handler handler = new Handler();
23 | handler.postDelayed(new Runnable() {
24 | @Override
25 | public void run() {
26 | try {
27 | Process process = Runtime.getRuntime().exec("logcat -d");
28 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
29 | String line;
30 | while ((line = bufferedReader.readLine()) != null) {
31 | log(line);
32 | }
33 | } catch (Exception e) {
34 | error("StartWriteLogs", e);
35 | }
36 | }
37 | }, delay);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.patterns;
2 |
3 | import com.obd.infrared.log.Logger;
4 | import com.obd.infrared.transmit.TransmitInfo;
5 | import com.obd.infrared.transmit.TransmitterType;
6 |
7 | public class PatternAdapter {
8 |
9 | private final PatternAdapterType adapterType;
10 | public PatternAdapter(PatternAdapterType adapterType) {
11 | this.adapterType = adapterType;
12 | }
13 |
14 | public PatternAdapter(Logger logger, TransmitterType transmitterType) {
15 | adapterType = PatternAdapterType.getConverterType(transmitterType);
16 | logger.log("ConverterType: " + adapterType);
17 | }
18 |
19 | public TransmitInfo createTransmitInfo(PatternConverter patternConverter) {
20 | return createTransmitInfo(adapterType, patternConverter);
21 | }
22 |
23 | public static TransmitInfo createTransmitInfo(PatternAdapterType converterType, PatternConverter patternConverter) {
24 | int[] pattern;
25 | switch (converterType) {
26 | case ToCycles:
27 | pattern = patternConverter.convertDataTo(PatternType.Cycles);
28 | break;
29 | case ToIntervals:
30 | pattern = patternConverter.convertDataTo(PatternType.Intervals);
31 | break;
32 | case ToCyclesHtcPattern:
33 | pattern = convertToCyclesHtcPattern(patternConverter.convertDataTo(PatternType.Cycles));
34 | break;
35 | case ToObsoleteSamsungString:
36 | Object[] obsoletePattern = createObsoletePattern(patternConverter.getFrequency(), patternConverter.convertDataTo(PatternType.Cycles));
37 | return new TransmitInfo(patternConverter.getFrequency(), obsoletePattern);
38 | default:
39 | throw new IllegalArgumentException("PatternAdapterType " + converterType + " not supported");
40 | }
41 | return new TransmitInfo(patternConverter.getFrequency(), pattern);
42 | }
43 |
44 |
45 | private static Object[] createObsoletePattern(int frequency, int[] cycleCountPattern) {
46 | StringBuilder result = new StringBuilder();
47 | result.append(frequency);
48 | for (Integer i : cycleCountPattern) {
49 | result.append(',');
50 | result.append(i);
51 | }
52 | return new Object[]{result.toString()};
53 | }
54 |
55 | private static int[] convertToCyclesHtcPattern(int[] cycleCountPattern) {
56 | int count = cycleCountPattern.length;
57 | boolean isEven = count % 2 == 0;
58 | if (isEven) {
59 | return cycleCountPattern;
60 | } else {
61 | count += 1;
62 | }
63 |
64 | int[] newPattern = new int[count];
65 | System.arraycopy(cycleCountPattern, 0, newPattern, 0, cycleCountPattern.length);
66 | newPattern[count - 1] = 10;
67 | return newPattern;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/patterns/PatternAdapterType.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.patterns;
2 |
3 | import android.os.Build;
4 |
5 | import com.obd.infrared.detection.DeviceDetector;
6 | import com.obd.infrared.transmit.TransmitterType;
7 |
8 | public enum PatternAdapterType {
9 |
10 | ToCycles,
11 | ToIntervals,
12 | ToObsoleteSamsungString,
13 | ToCyclesHtcPattern;
14 |
15 | public static PatternAdapterType getConverterType(TransmitterType transmitterType) {
16 | if (transmitterType == TransmitterType.Undefined) {
17 | // to make possible easily get pattern duration in ms for play pattern as audio
18 | return PatternAdapterType.ToIntervals;
19 | }
20 | if (DeviceDetector.isSamsung()) {
21 | return getConverterTypeForSamsung();
22 | }
23 | if (DeviceDetector.isLg() || DeviceDetector.isLe()) {
24 | return PatternAdapterType.ToIntervals;
25 | }
26 | if (DeviceDetector.isHtc()) {
27 | return PatternAdapterType.ToCyclesHtcPattern;
28 | }
29 | /**
30 | * {@link android.hardware.ConsumerIrManager#transmit(int, int[])} used microseconds (time intervals)
31 | */
32 | return PatternAdapterType.ToIntervals;
33 | }
34 |
35 |
36 | /**
37 | * http://developer.samsung.com/technical-doc/view.do?v=T000000125
38 | */
39 | private static PatternAdapterType getConverterTypeForSamsung() {
40 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
41 | return PatternAdapterType.ToIntervals;
42 | } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
43 | int lastIdx = Build.VERSION.RELEASE.lastIndexOf(".");
44 | int VERSION_MR = Integer.valueOf(Build.VERSION.RELEASE.substring(lastIdx + 1));
45 | if (VERSION_MR < 3) {
46 | // Before version of Android 4.4.2
47 | return PatternAdapterType.ToCycles;
48 | } else {
49 | // Later version of Android 4.4.3
50 | return PatternAdapterType.ToIntervals;
51 | }
52 | } else {
53 | // Before version of Android 4
54 | return PatternAdapterType.ToObsoleteSamsungString;
55 | }
56 | }
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/patterns/PatternConverter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.patterns;
2 |
3 | public class PatternConverter {
4 |
5 | private final PatternType type;
6 | private final int frequency;
7 | private final int[] data;
8 |
9 | public PatternConverter(PatternType type, int frequency, int... data) {
10 | this.type = type;
11 | this.frequency = frequency;
12 | this.data = data;
13 | }
14 |
15 | public int getFrequency() {
16 | return this.frequency;
17 | }
18 |
19 | /** Convert and return data in @newPatternType */
20 | public int[] convertDataTo(PatternType newPatternType) {
21 | if (newPatternType == type) {
22 | return data;
23 | }
24 |
25 | if (type == PatternType.Intervals && newPatternType == PatternType.Cycles) {
26 | return convertIntervalsToCycles(frequency, data);
27 | }
28 |
29 | if (type == PatternType.Cycles && newPatternType == PatternType.Intervals) {
30 | return convertCyclesToIntervals(frequency, data);
31 | }
32 |
33 | throw new IllegalArgumentException("Unsupported PatternType: " + newPatternType);
34 | }
35 |
36 | public static int[] convertCyclesToIntervals(int frequency, int[] cycles) {
37 | int[] intervals = new int[cycles.length];
38 | int k = 1000000 / frequency;
39 | for (int i = 0; i < intervals.length; i++) {
40 | intervals[i] = cycles[i] * k;
41 | }
42 | return intervals;
43 | }
44 |
45 | public static int[] convertIntervalsToCycles(int frequency, int[] intervals) {
46 | int[] cycles = new int[intervals.length];
47 | int k = 1000000 / frequency;
48 | for (int i = 0; i < cycles.length; i++) {
49 | cycles[i] = intervals[i] / k;
50 | }
51 | return cycles;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/patterns/PatternConverterUtils.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.patterns;
2 |
3 | public class PatternConverterUtils {
4 |
5 | private final static int DEC = 10;
6 | private final static int HEX = 16;
7 |
8 | private static String[] splitLine(String line) {
9 | return line.split("[^xXabcdefABCDEF\\d]+");
10 | }
11 |
12 | private static String removeHexPrefix(String s) {
13 | return s.replaceAll("0x|0X|x|X", "");
14 | }
15 |
16 | private static int[] convertToIntegerArray(String line, int radix) {
17 | String[] data = splitLine(line);
18 | int[] result = new int[data.length];
19 | for (int i = 0; i < result.length; i++) {
20 | result[i] = radix == DEC ? Integer.parseInt(data[i]) : Integer.parseInt(removeHexPrefix(data[i]), radix);
21 | }
22 | return result;
23 | }
24 |
25 | public static PatternConverter fromString(PatternType type, int frequency, String line) {
26 | int[] result = convertToIntegerArray(line, DEC);
27 | return new PatternConverter(type, frequency, result);
28 | }
29 |
30 | public static PatternConverter fromHexString(PatternType type, int frequency, String line) {
31 | int[] result = convertToIntegerArray(line, HEX);
32 | return new PatternConverter(type, frequency, result);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/patterns/PatternType.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.patterns;
2 |
3 | public enum PatternType {
4 | Cycles,
5 | Intervals
6 | }
7 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/TransmitInfo.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit;
2 |
3 | public class TransmitInfo {
4 |
5 | public final int frequency;
6 | public final int[] pattern;
7 | public final Object[] obsoletePattern;
8 |
9 | public TransmitInfo(int frequency, int[] pattern) {
10 | this.frequency = frequency;
11 | this.pattern = pattern;
12 | this.obsoletePattern = null;
13 | }
14 |
15 | public TransmitInfo(int frequency, Object[] pattern) {
16 | this.frequency = frequency;
17 | this.pattern = null;
18 | this.obsoletePattern = pattern;
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | StringBuilder stringBuilder = new StringBuilder("TransmitInfo [").append(frequency).append("]: ");
24 | if (pattern != null) {
25 | stringBuilder.append(" Count:").append(this.pattern.length).append(": ");
26 | for (int v : pattern) {
27 | stringBuilder.append(", ").append(v);
28 | }
29 | } else {
30 | stringBuilder.append(obsoletePattern[0].toString());
31 | }
32 | return stringBuilder.toString();
33 | }
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/Transmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit;
2 |
3 | import android.content.Context;
4 |
5 | import com.obd.infrared.devices.IrDevice;
6 | import com.obd.infrared.log.Logger;
7 | import com.obd.infrared.transmit.concrete.ActualTransmitter;
8 | import com.obd.infrared.transmit.concrete.HtcTransmitter;
9 | import com.obd.infrared.transmit.concrete.LeTransmitter;
10 | import com.obd.infrared.transmit.concrete.LgWithDeviceTransmitter;
11 | import com.obd.infrared.transmit.concrete.LgWithoutDeviceTransmitter;
12 | import com.obd.infrared.transmit.concrete.ObsoleteTransmitter;
13 | import com.obd.infrared.transmit.concrete.UndefinedTransmitter;
14 |
15 | import java.util.List;
16 |
17 | public abstract class Transmitter {
18 | public static Transmitter getTransmitterByType(TransmitterType transmitterType, Context context, Logger logger) {
19 | logger.log("Get transmitter by type: " + transmitterType);
20 | switch (transmitterType) {
21 | case Actual:
22 | return new ActualTransmitter(context, logger);
23 | case Obsolete:
24 | return new ObsoleteTransmitter(context, logger);
25 | case HTC:
26 | return new HtcTransmitter(context, logger);
27 | case LG:
28 | return new LgWithDeviceTransmitter(context, logger);
29 | case Le:
30 | return new LeTransmitter(context, logger);
31 | case LG_WithOutDevice:
32 | return new LgWithoutDeviceTransmitter(context, logger);
33 | case LG_Actual:
34 | return new ActualTransmitter(context, logger);
35 | default:
36 | return new UndefinedTransmitter(context, logger);
37 | }
38 | }
39 |
40 |
41 | protected final Context context;
42 | protected final Logger logger;
43 |
44 | public Transmitter(Context context, Logger logger) {
45 | this.context = context;
46 | this.logger = logger;
47 | }
48 |
49 | public void start() {
50 | }
51 |
52 | public abstract void transmit(TransmitInfo transmitInfo);
53 |
54 | public boolean isReady() {
55 | return true;
56 | }
57 |
58 | public void stop() {
59 | }
60 |
61 | public void transmit(int deviceId, int functionId, int duration) {
62 | throw new RuntimeException("Transmitting by device id " + deviceId + " and function id " + functionId + " with duration " + duration + " not supported");
63 | }
64 |
65 | public List getIrDevices(Logger log) {
66 | throw new RuntimeException("getIrDevices not supported");
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/TransmitterType.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit;
2 |
3 | public enum TransmitterType {
4 | Undefined,
5 | Obsolete, // Samsung
6 | Actual, // ConsumerIRManager
7 | HTC,
8 | Le(true),
9 | LG(true),
10 | LG_WithOutDevice(true),
11 | LG_Actual; // ConsumerIRManager
12 |
13 | private final boolean hasIrDevices;
14 |
15 | TransmitterType() {
16 | this(false);
17 | }
18 |
19 | TransmitterType(boolean hasIrDevices) {
20 | this.hasIrDevices = hasIrDevices;
21 | }
22 |
23 | public boolean hasIrDevices() {
24 | return hasIrDevices;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/ActualTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.hardware.ConsumerIrManager;
6 | import android.os.Build;
7 |
8 | import com.obd.infrared.log.Logger;
9 | import com.obd.infrared.transmit.TransmitInfo;
10 | import com.obd.infrared.transmit.Transmitter;
11 |
12 | import static android.content.Context.CONSUMER_IR_SERVICE;
13 |
14 | public class ActualTransmitter extends Transmitter {
15 |
16 | private final ConsumerIrManager consumerIrManager;
17 |
18 | public ActualTransmitter(Context context, Logger logger) {
19 | super(context, logger);
20 | logger.log("Try to create ActualTransmitter");
21 | this.consumerIrManager = getConsumerIrManager();
22 | logger.log("ActualTransmitter created");
23 | }
24 |
25 | @SuppressWarnings("ResourceType")
26 | @TargetApi(Build.VERSION_CODES.KITKAT)
27 | private ConsumerIrManager getConsumerIrManager() {
28 | return (ConsumerIrManager) context.getSystemService(CONSUMER_IR_SERVICE);
29 | }
30 |
31 | @Override
32 | @TargetApi(Build.VERSION_CODES.KITKAT)
33 | public void transmit(TransmitInfo transmitInfo) {
34 | logger.log("Try to transmit");
35 | consumerIrManager.transmit(transmitInfo.frequency, transmitInfo.pattern);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/HtcTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.os.Handler;
6 | import android.os.Looper;
7 | import android.os.Message;
8 | import android.util.Log;
9 |
10 | import com.htc.circontrol.CIRControl;
11 | import com.htc.htcircontrol.HtcIrData;
12 | import com.obd.infrared.log.Logger;
13 | import com.obd.infrared.transmit.TransmitInfo;
14 | import com.obd.infrared.transmit.Transmitter;
15 |
16 | import java.util.Arrays;
17 | import java.util.UUID;
18 |
19 |
20 | public class HtcTransmitter extends Transmitter {
21 |
22 | private class SendRunnable implements Runnable {
23 | private int frequency;
24 | private int[] frame;
25 |
26 | public SendRunnable(int frequency, int[] frame) {
27 | this.frequency = frequency;
28 | this.frame = frame;
29 | }
30 |
31 | public void run() {
32 | try {
33 | htcControl.transmitIRCmd(new HtcIrData(1, frequency, frame), false);
34 | }
35 | catch(IllegalArgumentException iae) {
36 | logger.error("Run: IllegalArgumentException", iae);
37 | }
38 | catch(Exception e) {
39 | logger.error("Run: Exception", e);
40 | }
41 | }
42 | }
43 |
44 | private static class HtcHandler extends Handler {
45 |
46 | private final Logger logger;
47 | public HtcHandler(Looper looper, Logger logger) {
48 | super(looper);
49 | this.logger = logger;
50 | }
51 |
52 | @Override
53 | public void handleMessage(Message msg)
54 | {
55 | logger.log("HtcHandler.handleMessage:");
56 | logger.log("msg.what: " + msg.what + " arg1: " + msg.arg1 + " arg2: " + msg.arg2);
57 | logger.log("msg.toString: " + msg.toString());
58 |
59 | switch (msg.what) {
60 | case CIRControl.MSG_RET_LEARN_IR:
61 | logger.log("MSG_RET_LEARN_IR");
62 | break;
63 | case CIRControl.MSG_RET_TRANSMIT_IR:
64 | logger.log("MSG_RET_TRANSMIT_IR");
65 | switch(msg.arg1) {
66 | case CIRControl.ERR_IO_ERROR:
67 | logger.log("CIR hardware component is busy in doing early CIR command");
68 | logger.log("Send IR Error=ERR_IO_ERROR");
69 | break;
70 | case CIRControl.ERR_INVALID_VALUE:
71 | logger.log("Send IR Error=ERR_INVALID_VALUE");
72 | break;
73 | case CIRControl.ERR_CMD_DROPPED:
74 | logger.log("SDK might be too busy to send IR key, developer can try later, or send IR key with non-droppable setting");
75 | logger.log("Send IR Error=ERR_CMD_DROPPED");
76 | break;
77 | default:
78 | logger.log("default");
79 | break;
80 | }
81 | break;
82 | case CIRControl.MSG_RET_CANCEL:
83 | logger.log("MSG_RET_CANCEL");
84 | switch(msg.arg1) {
85 | case CIRControl.ERR_IO_ERROR:
86 | logger.log("CIR hardware component is busy in doing early CIR command");
87 | logger.log("Send IR Error=ERR_IO_ERROR");
88 | break;
89 | case CIRControl.ERR_CANCEL_FAIL:
90 | logger.log("CIR hardware component is busy in doing early CIR command");
91 | logger.log("Cancel Error: ERR_CANCEL_FAIL");
92 | break;
93 | default:
94 | logger.log("default");
95 | break;
96 | }
97 | break;
98 | default:
99 | logger.log("global default");
100 | }
101 | }
102 | }
103 |
104 | private final CIRControl htcControl;
105 | private final Handler htcHandler;
106 |
107 | public HtcTransmitter(Context context, Logger logger) {
108 | super(context, logger);
109 |
110 | logger.log("Try to create HtcTransmitter");
111 | htcHandler = new HtcHandler(Looper.getMainLooper(), logger);
112 | htcControl = new CIRControl(context, htcHandler);
113 | logger.log("HtcTransmitter created");
114 | }
115 |
116 | @Override
117 | public void start() {
118 | try {
119 | logger.log("Try to start HTC CIRControl");
120 | htcControl.start();
121 | } catch (Exception e) {
122 | logger.error("On try to start HTC CIRControl", e);
123 | }
124 | }
125 |
126 | @Override
127 | public void transmit(TransmitInfo transmitInfo) {
128 | try {
129 | if (htcControl.isStarted()) {
130 | logger.log("Try to transmit HTC");
131 | htcHandler.post(new SendRunnable(transmitInfo.frequency, transmitInfo.pattern));
132 | } else {
133 | logger.log("htcControl not started");
134 | }
135 | } catch (Exception e) {
136 | logger.error("On try to transmit", e);
137 | }
138 | }
139 |
140 |
141 | @Override
142 | public void stop() {
143 | try {
144 | logger.log("Try to stop HTC CIRControl");
145 | htcControl.stop();
146 | } catch (Exception e) {
147 | logger.error("On try to stop HTC CIRControl", e);
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/LeTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.ComponentName;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.ServiceConnection;
7 | import android.os.Build;
8 | import android.os.IBinder;
9 | import android.os.RemoteException;
10 |
11 | import com.obd.infrared.devices.IrDevice;
12 | import com.obd.infrared.devices.IrFunction;
13 | import com.obd.infrared.log.Logger;
14 | import com.obd.infrared.transmit.TransmitInfo;
15 | import com.obd.infrared.transmit.Transmitter;
16 | import com.obd.infrared.utils.Constants;
17 | import com.obd.infrared.utils.le.Device;
18 | import com.obd.infrared.utils.le.IControl;
19 | import com.obd.infrared.utils.le.IRAction;
20 | import com.obd.infrared.utils.le.IRFunction;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | * Created by Andrew on 20.10.2017
27 | */
28 |
29 | public class LeTransmitter extends Transmitter {
30 |
31 | private ServiceConnection mControlServiceConnection = new ConnectorListener();
32 | private IControl remoteControl;
33 |
34 | public LeTransmitter(Context context, Logger logger) {
35 | super(context, logger);
36 | }
37 |
38 | @Override
39 | public boolean isReady() {
40 | return remoteControl != null;
41 | }
42 |
43 | @Override
44 | public void transmit(TransmitInfo transmitInfo) {
45 | if (isReady()) {
46 | try {
47 | remoteControl.transmit(transmitInfo.frequency, transmitInfo.pattern);
48 | } catch (RemoteException e) {
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
54 | @Override
55 | public void transmit(int deviceId, int functionId, int duration) {
56 | if (isReady()) {
57 | try {
58 | logger.log("Transmitting with device id " + deviceId + " and function id " + functionId + " and duration " + duration);
59 | remoteControl.sendIR(new IRAction(deviceId, functionId, duration));
60 | } catch (Exception e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 |
66 | @Override
67 | public void start() {
68 | final String UEICONTROLPACKAGE = Build.BRAND.contains("Coolpad") ? Constants.LE_COOLPAD_IR_SERVICE_PACKAGE : Constants.LE_DEFAULT_IR_SERVICE_PACKAGE_2;
69 |
70 | try {
71 | Intent controlIntent = new Intent(IControl.DESCRIPTOR);
72 | controlIntent.setClassName(UEICONTROLPACKAGE, "com.uei.control.Service");
73 | context.bindService(controlIntent, this.mControlServiceConnection, Context.BIND_AUTO_CREATE);
74 | } catch (Exception e) {
75 | e.printStackTrace();
76 | }
77 | }
78 |
79 | @Override
80 | public void stop() {
81 | try {
82 | context.unbindService(this.mControlServiceConnection);
83 | remoteControl = null;
84 | } catch (Exception e) {
85 | e.printStackTrace();
86 | }
87 | }
88 |
89 | @Override
90 | public List getIrDevices(Logger logger) {
91 | try {
92 | Device[] devices = remoteControl.getDevices();
93 | logger.log("Devices from LE: " + (devices != null));
94 | List result = new ArrayList<>();
95 | if (devices != null && devices.length > 0) {
96 | logger.log("Devices size: " + devices.length);
97 | for (Device device : devices) {
98 | IrDevice irDevice = new IrDevice(device.Id, device.Name);
99 |
100 | if (device.KeyFunctions != null && device.KeyFunctions.size() > 0) {
101 | for (IRFunction function : device.KeyFunctions) {
102 | IrFunction irFunction = new IrFunction(function.Id, function.Name, function.IsLearned);
103 | irDevice.addFunction(irFunction);
104 | }
105 | result.add(irDevice);
106 | continue;
107 | }
108 |
109 | if (device.Functions != null && device.Functions.length > 0) {
110 | String[] labelsByDevice = remoteControl.getAllFunctionLabelsByDevice(device.Id, device.Functions);
111 | for (int i = 0; i < device.Functions.length; i++) {
112 | IrFunction irFunction = new IrFunction(device.Functions[i], labelsByDevice[i], null);
113 | irDevice.addFunction(irFunction);
114 | }
115 | result.add(irDevice);
116 | }
117 | }
118 | }
119 |
120 | return result;
121 |
122 | } catch (Exception e) {
123 | logger.error("LE", e);
124 | e.printStackTrace();
125 | return null;
126 | }
127 | }
128 |
129 | private class ConnectorListener implements ServiceConnection {
130 | ConnectorListener() {
131 | }
132 |
133 | public void onServiceDisconnected(ComponentName name) {
134 | remoteControl = null;
135 | }
136 |
137 | public void onServiceConnected(ComponentName name, IBinder service) {
138 | remoteControl = new IControl(service);
139 | }
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/LgTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 |
5 | import com.lge.hardware.IRBlaster.Device;
6 | import com.lge.hardware.IRBlaster.IRAction;
7 | import com.lge.hardware.IRBlaster.IRBlaster;
8 | import com.lge.hardware.IRBlaster.IRBlasterCallback;
9 | import com.lge.hardware.IRBlaster.IRFunction;
10 | import com.lge.hardware.IRBlaster.ResultCode;
11 | import com.obd.infrared.devices.IrDevice;
12 | import com.obd.infrared.devices.IrFunction;
13 | import com.obd.infrared.log.Logger;
14 | import com.obd.infrared.transmit.TransmitInfo;
15 | import com.obd.infrared.transmit.Transmitter;
16 | import com.obd.infrared.utils.Constants;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 |
22 | public abstract class LgTransmitter extends Transmitter implements IRBlasterCallback {
23 |
24 | protected final IRBlaster irBlaster;
25 |
26 | public LgTransmitter(Context context, Logger logger) {
27 | super(context, logger);
28 | logger.log("Try to create LG IRBlaster");
29 | irBlaster = IRBlaster.getIRBlaster(context, this);
30 | logger.log("IRBlaster created");
31 | }
32 |
33 | @Override
34 | public void start() {
35 | logger.log("Start not supported in LG IRBlaster");
36 | }
37 |
38 | @Override
39 | public void transmit(TransmitInfo transmitInfo) {
40 | try {
41 | if (isReady) {
42 | beforeSendIr();
43 | logger.log("Try to transmit LG IRBlaster");
44 |
45 | int resultCode = irBlaster.sendIRPattern(transmitInfo.frequency, transmitInfo.pattern);
46 | logger.log("Result: " + ResultCode.getString(resultCode));
47 | } else {
48 | logger.log("LG IRBlaster not ready");
49 | }
50 | } catch (Exception e) {
51 | logger.error("On try to transmit LG IRBlaster", e);
52 | }
53 | }
54 |
55 | @Override
56 | public void transmit(int deviceId, int functionId, int duration) {
57 | try {
58 | if (isReady) {
59 | logger.log("Transmitting with device id " + deviceId + " and function id " + functionId + " and duration " + duration);
60 | irBlaster.sendIR(new IRAction(deviceId, functionId, duration));
61 | } else {
62 | logger.log("LG IRBlaster not ready");
63 | }
64 | } catch (Exception e) {
65 | logger.error("On try to transmit LG IRBlaster", e);
66 | }
67 | }
68 |
69 | protected abstract void beforeSendIr();
70 |
71 | @Override
72 | public void stop() {
73 | try {
74 | logger.log("Try to close LG IRBlaster");
75 | irBlaster.close();
76 | } catch (Exception e) {
77 | logger.error("On try to close LG IRBlaster", e);
78 | }
79 | }
80 |
81 | private boolean isReady = false;
82 |
83 | @Override
84 | public boolean isReady() {
85 | return isReady;
86 | }
87 |
88 | @Override
89 | public void IRBlasterReady() {
90 | isReady = true;
91 | logger.log("LG IRBlaster ready");
92 | }
93 |
94 | @Override
95 | public void learnIRCompleted(int i) {
96 | logger.log("LG IRBlaster.learnIRCompleted : " + i);
97 | }
98 |
99 | @Override
100 | public void newDeviceId(int i) {
101 | logger.log("LG IRBlaster.newDeviceId : " + i);
102 | }
103 |
104 | @Override
105 | public void failure(int i) {
106 | logger.log("LG IRBlaster.failure : " + i);
107 | }
108 |
109 | @Override
110 | public List getIrDevices(Logger logger) {
111 | try {
112 | Device[] devices = irBlaster.getDevices();
113 | List result = new ArrayList<>();
114 | if (devices != null && devices.length > 0) {
115 | logger.log("Devices size: " + devices.length);
116 |
117 | for (Device device : devices) {
118 | IrDevice irDevice = new IrDevice(device.Id, device.Name);
119 |
120 | if (device.KeyFunctions != null && device.KeyFunctions.size() > 0) {
121 | for (IRFunction function : device.KeyFunctions) {
122 | IrFunction irFunction = new IrFunction(function.Id, function.Name, function.IsLearned);
123 | irDevice.addFunction(irFunction);
124 | }
125 | result.add(irDevice);
126 | continue;
127 | }
128 |
129 | if (device.Functions != null && device.Functions.length > 0) {
130 | String[] labelsByDevice = irBlaster.getAllFunctionLabels(device.Id, device.Functions);
131 | for (int i = 0; i < device.Functions.length; i++) {
132 | IrFunction irFunction = new IrFunction(device.Functions[i], labelsByDevice[i], null);
133 | irDevice.addFunction(irFunction);
134 | }
135 | result.add(irDevice);
136 | }
137 | }
138 | }
139 | return result;
140 |
141 | } catch (Exception e) {
142 | e.printStackTrace();
143 | return null;
144 | }
145 | }
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/LgWithDeviceTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 |
5 | import com.lge.hardware.IRBlaster.Device;
6 | import com.lge.hardware.IRBlaster.IRAction;
7 | import com.lge.hardware.IRBlaster.IRFunction;
8 | import com.lge.hardware.IRBlaster.ResultCode;
9 | import com.obd.infrared.log.Logger;
10 |
11 | public class LgWithDeviceTransmitter extends LgTransmitter {
12 |
13 | public LgWithDeviceTransmitter(Context context, Logger logger) {
14 | super(context, logger);
15 | }
16 |
17 | private Device deviceSelected = null;
18 |
19 | @Override
20 | public void IRBlasterReady() {
21 | super.IRBlasterReady();
22 | Device[] mDevices = irBlaster.getDevices();
23 | for (Device device : mDevices) {
24 | if (device.KeyFunctions != null && device.KeyFunctions.size() > 0) {
25 | deviceSelected = device;
26 | break;
27 | }
28 | }
29 | // logDevices(mDevices);
30 | logger.log("LG deviceSelected :" + (deviceSelected != null));
31 |
32 | }
33 |
34 | @SuppressWarnings("unused")
35 | private void logDevices(Device[] mDevices) {
36 | for(Device device: mDevices) {
37 | logger.log("Device ID:" + device.Id + " Name:" + device.Name + " B: " + device.Brand + " T:" + device.DeviceTypeName + " XZ: " + device.origName + " XZ: " + device.transName + " X: " + device.KeyFunctions.size());
38 | if (device.Name.contains("LG")) {
39 | int s = 0;
40 | for (IRFunction k : device.KeyFunctions) {
41 | logger.log("Name: " + k.Name + " id: " + k.Id + " is: " + k.IsLearned);
42 | s++;
43 | if (s > 10) {
44 | break;
45 | }
46 | }
47 | }
48 | }
49 | }
50 |
51 | @Override
52 | protected void beforeSendIr() {
53 | if (deviceSelected != null) {
54 | int resultCode = irBlaster.sendIR(new IRAction(deviceSelected.Id, deviceSelected.KeyFunctions.get(0).Id, 0));
55 | logger.log("Try to IRBlaster.send known IR pattern. Result: " + ResultCode.getString(resultCode));
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/LgWithoutDeviceTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 |
5 | import com.obd.infrared.log.Logger;
6 |
7 | public class LgWithoutDeviceTransmitter extends LgTransmitter {
8 | public LgWithoutDeviceTransmitter(Context context, Logger logger) {
9 | super(context, logger);
10 | }
11 |
12 | @Override
13 | protected void beforeSendIr() {
14 | // Do nothing before send ir command
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/ObsoleteTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 |
5 | import com.obd.infrared.log.Logger;
6 | import com.obd.infrared.transmit.TransmitInfo;
7 | import com.obd.infrared.transmit.Transmitter;
8 |
9 | import java.lang.reflect.InvocationTargetException;
10 | import java.lang.reflect.Method;
11 |
12 |
13 | public class ObsoleteTransmitter extends Transmitter {
14 |
15 |
16 | private final Object irdaService;
17 | private Method write_irsend;
18 |
19 | @SuppressWarnings("ResourceType")
20 | public ObsoleteTransmitter(Context context, Logger logger) {
21 | super(context, logger);
22 | logger.log("Try to create ObsoleteTransmitter");
23 | irdaService = context.getSystemService("irda");
24 | try {
25 | write_irsend = irdaService.getClass().getMethod("write_irsend", new Class[]{String.class});
26 | } catch (NoSuchMethodException e) {
27 | logger.error("ObsoleteTransmitter:NoSuchMethodException", e);
28 | }
29 | logger.log("ObsoleteTransmitter created");
30 | }
31 |
32 | @Override
33 | public void transmit(TransmitInfo transmitInfo) {
34 | try {
35 | write_irsend.invoke(irdaService, transmitInfo.obsoletePattern);
36 | } catch (IllegalAccessException e) {
37 | logger.error("ObsoleteTransmitter:IllegalAccessException", e);
38 | } catch (InvocationTargetException e) {
39 | logger.error("ObsoleteTransmitter:InvocationTargetException", e);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/transmit/concrete/UndefinedTransmitter.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.transmit.concrete;
2 |
3 | import android.content.Context;
4 |
5 | import com.obd.infrared.log.Logger;
6 | import com.obd.infrared.transmit.TransmitInfo;
7 | import com.obd.infrared.transmit.Transmitter;
8 |
9 | public class UndefinedTransmitter extends Transmitter {
10 |
11 | public UndefinedTransmitter(Context context, Logger logger) {
12 | super(context, logger);
13 | logger.warning("Created empty transmitter for undefined type of IR");
14 | }
15 |
16 | @Override
17 | public void transmit(TransmitInfo transmitInfo) {
18 |
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils;
2 |
3 | /**
4 | * Created by Andrew on 10/25/2017
5 | */
6 |
7 | public class Constants {
8 | public static final String LE_COOLPAD_IR_SERVICE_PACKAGE = "com.uei.quicksetsdk.letvitwo";
9 | public static final String LE_DEFAULT_IR_SERVICE_PACKAGE_2 = "com.uei.quicksetsdk.letv";
10 |
11 | /**
12 | * Remote SDC don't have normal way to send signal,
13 | * so using big enough number for duration of ir functions
14 | * */
15 | public static final int DEFAULT_IR_FUNCTION_DURATION_MS = 500;
16 | }
17 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/le/Device.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils.le;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class Device implements Parcelable, IDevice {
10 | public static final Creator CREATOR = new DeviceCreator();
11 | public String Brand = "";
12 | public DeviceTypes DeviceType = DeviceTypes.IRDevice;
13 | public String DeviceTypeName = "";
14 | public int[] Functions = null;
15 | public int Id = 0;
16 | public List KeyFunctions = new ArrayList();
17 | public String Model = "";
18 | public String Name = "";
19 |
20 | static class DeviceCreator implements Creator {
21 | DeviceCreator() {
22 | }
23 |
24 | public Device createFromParcel(Parcel in) {
25 | return new Device(in);
26 | }
27 |
28 | public Device[] newArray(int size) {
29 | return new Device[size];
30 | }
31 | }
32 |
33 | public enum DeviceTypes {
34 | IRDevice
35 | }
36 |
37 | protected Device(Parcel in) {
38 | readFromParcel(in);
39 | }
40 |
41 | public int describeContents() {
42 | return 0;
43 | }
44 |
45 | public void writeToParcel(Parcel dest, int flags) {
46 | }
47 |
48 | public void readFromParcel(Parcel in) {
49 | try {
50 | this.Id = in.readInt();
51 | this.Name = in.readString();
52 | this.Brand = in.readString();
53 | this.Model = in.readString();
54 | this.DeviceTypeName = in.readString();
55 | int count = in.readInt();
56 | resetKeyFunctions();
57 | if (count > 0) {
58 | this.Functions = new int[count];
59 | in.readIntArray(this.Functions);
60 | if (in.dataAvail() > 0) {
61 | try {
62 | Parcelable[] parcelableArray = in.readParcelableArray(IRFunction.class.getClassLoader());
63 | if (parcelableArray != null) {
64 | for (Parcelable pin : parcelableArray) {
65 | this.KeyFunctions.add((IRFunction) pin);
66 | }
67 | }
68 | } catch (Exception ex) {
69 | ex.printStackTrace();
70 | }
71 | }
72 | }
73 | } catch (Exception ex2) {
74 | ex2.printStackTrace();
75 | }
76 | }
77 |
78 | public String toString() {
79 | return this.Name;
80 | }
81 |
82 | public String getName() {
83 | return this.Name;
84 | }
85 |
86 | public String getBrand() {
87 | return this.Brand;
88 | }
89 |
90 | public String getModel() {
91 | return this.Model;
92 | }
93 |
94 | public String getDeviceTypeName() {
95 | return this.DeviceTypeName;
96 | }
97 |
98 | public String getVersion() {
99 | return "";
100 | }
101 |
102 | public int getId() {
103 | return this.Id;
104 | }
105 |
106 | public DeviceTypes getType() {
107 | return this.DeviceType;
108 | }
109 |
110 | private void resetKeyFunctions() {
111 | if (this.KeyFunctions == null) {
112 | this.KeyFunctions = new ArrayList();
113 | } else {
114 | this.KeyFunctions.clear();
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/le/IControl.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils.le;
2 |
3 | import android.os.IBinder;
4 | import android.os.Parcel;
5 | import android.os.RemoteException;
6 |
7 | public class IControl {
8 | public static final String DESCRIPTOR = "com.uei.control.IControl";
9 |
10 | private IBinder controlService = null;
11 |
12 | public IControl(IBinder service) {
13 | this.controlService = service;
14 | }
15 |
16 | public Device[] getDevices() throws RemoteException {
17 | Parcel _data = Parcel.obtain();
18 | Parcel _reply = Parcel.obtain();
19 | try {
20 | _data.writeInterfaceToken(DESCRIPTOR);
21 | this.controlService.transact(8, _data, _reply, 0);
22 | _reply.readException();
23 | Device[] _result = (Device[]) _reply.createTypedArray(Device.CREATOR);
24 | return _result;
25 | } finally {
26 | _reply.recycle();
27 | _data.recycle();
28 | }
29 | }
30 |
31 | public int transmit(int carrierFrequency, int[] pattern) throws RemoteException {
32 | Parcel _data = Parcel.obtain();
33 | Parcel _reply = Parcel.obtain();
34 | int _result = 1;
35 | if (this.controlService != null) {
36 | try {
37 | _data.writeInterfaceToken(DESCRIPTOR);
38 | _data.writeInt(carrierFrequency);
39 | _data.writeIntArray(pattern);
40 | this.controlService.transact(18, _data, _reply, 0);
41 | _reply.readException();
42 | _result = _reply.readInt();
43 | } catch (Exception ex) {
44 | ex.printStackTrace();
45 | } finally {
46 | _reply.recycle();
47 | _data.recycle();
48 | }
49 | }
50 | return _result;
51 | }
52 |
53 | public String[] getAllFunctionLabelsByDevice(int deviceId, int[] functionIds) throws RemoteException {
54 | Parcel _data = Parcel.obtain();
55 | Parcel _reply = Parcel.obtain();
56 | try {
57 | _data.writeInterfaceToken(DESCRIPTOR);
58 | _data.writeInt(deviceId);
59 | _data.writeIntArray(functionIds);
60 | this.controlService.transact(15, _data, _reply, 0);
61 | _reply.readException();
62 | String[] _result = _reply.createStringArray();
63 | return _result;
64 | } finally {
65 | _reply.recycle();
66 | _data.recycle();
67 | }
68 | }
69 |
70 | public int sendIR(IRAction action) throws RemoteException {
71 | Parcel _data = Parcel.obtain();
72 | Parcel _reply = Parcel.obtain();
73 | try {
74 | _data.writeInterfaceToken(DESCRIPTOR);
75 | if (action != null) {
76 | _data.writeInt(1);
77 | action.writeToParcel(_data, 0);
78 | } else {
79 | _data.writeInt(0);
80 | }
81 | this.controlService.transact(1, _data, _reply, 0);
82 | _reply.readException();
83 | int _result = _reply.readInt();
84 | return _result;
85 | } finally {
86 | _reply.recycle();
87 | _data.recycle();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/le/IDevice.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils.le;
2 |
3 | import com.obd.infrared.utils.le.Device.DeviceTypes;
4 |
5 | public interface IDevice {
6 | String getBrand();
7 |
8 | String getDeviceTypeName();
9 |
10 | int getId();
11 |
12 | String getModel();
13 |
14 | String getName();
15 |
16 | DeviceTypes getType();
17 |
18 | String getVersion();
19 | }
20 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/le/IRAction.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils.le;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import com.obd.infrared.transmit.concrete.LeTransmitter;
7 |
8 | public class IRAction implements Parcelable {
9 | public static final Creator CREATOR = new C07691();
10 | public int DeviceId;
11 | public int Duration;
12 | public int Function;
13 |
14 | static class C07691 implements Creator {
15 | C07691() {
16 | }
17 |
18 | public IRAction createFromParcel(Parcel in) {
19 | return new IRAction(in);
20 | }
21 |
22 | public IRAction[] newArray(int size) {
23 | return new IRAction[size];
24 | }
25 | }
26 |
27 | public IRAction(int deviceId, int functionId, int duration) {
28 | this.DeviceId = 0;
29 | this.Function = 0;
30 | this.Duration = 0;
31 | this.DeviceId = deviceId;
32 | this.Function = functionId;
33 | this.Duration = duration;
34 | }
35 |
36 | private IRAction(Parcel in) {
37 | this.DeviceId = 0;
38 | this.Function = 0;
39 | this.Duration = 0;
40 | readFromParcel(in);
41 | }
42 |
43 | public int describeContents() {
44 | return 0;
45 | }
46 |
47 | public void writeToParcel(Parcel dest, int flags) {
48 | try {
49 | dest.writeInt(this.DeviceId);
50 | dest.writeInt(this.Function);
51 | dest.writeInt(this.Duration);
52 | } catch (Exception ex) {
53 | ex.printStackTrace();
54 | }
55 | }
56 |
57 | void readFromParcel(Parcel in) {
58 | try {
59 | this.DeviceId = in.readInt();
60 | this.Function = in.readInt();
61 | this.Duration = in.readInt();
62 | } catch (Exception ex) {
63 | ex.printStackTrace();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/infrared/src/main/java/com/obd/infrared/utils/le/IRFunction.java:
--------------------------------------------------------------------------------
1 | package com.obd.infrared.utils.le;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | public class IRFunction implements Parcelable {
7 | public static final Creator CREATOR = new FunctionCreator();
8 | public int Id;
9 | public boolean IsLearned;
10 | public Short LearnedCode;
11 | public String Name;
12 |
13 | static class FunctionCreator implements Creator {
14 | FunctionCreator() {
15 | }
16 |
17 | public IRFunction createFromParcel(Parcel in) {
18 | return new IRFunction(in);
19 | }
20 |
21 | public IRFunction[] newArray(int size) {
22 | return new IRFunction[size];
23 | }
24 | }
25 |
26 | public IRFunction() {
27 | this.Name = "";
28 | this.Id = 0;
29 | this.IsLearned = false;
30 | this.LearnedCode = Short.valueOf((short) 0);
31 | }
32 |
33 | private IRFunction(Parcel in) {
34 | this.Name = "";
35 | this.Id = 0;
36 | this.IsLearned = false;
37 | this.LearnedCode = Short.valueOf((short) 0);
38 | readFromParcel(in);
39 | }
40 |
41 | public int describeContents() {
42 | return 0;
43 | }
44 |
45 | public void writeToParcel(Parcel dest, int flags) {
46 | }
47 |
48 | public void readFromParcel(Parcel in) {
49 | boolean z = true;
50 | try {
51 | this.Id = in.readInt();
52 | this.Name = in.readString();
53 | if (in.readInt() != 1) {
54 | z = false;
55 | }
56 | this.IsLearned = z;
57 | this.LearnedCode = Short.valueOf((short) in.readInt());
58 | } catch (Exception ex) {
59 | ex.printStackTrace();
60 | }
61 | }
62 |
63 | public String toString() {
64 | return this.Name;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/infrared/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | InfraRed
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':infrared'
2 |
--------------------------------------------------------------------------------