├── .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 | 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 | ![Difference between sequences](http://s8.postimg.org/s9s4dxumd/91598ad1_1766_469e_8731_99f70f606864.jpg) 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 | 8 | 9 | 10 | 11 | 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 |