diff --git a/README.md b/README.md index 9f2d15f..acf392c 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,30 @@ React-native OBD-II reader designed to connect with Bluetooth Elm327 OBD reader. # How to install Run below link on your project root folder. ```` -$ npm install react-native-obd2 --save +$ npm install @furkanom/react-native-obd2 --save $ react-native link ```` +# For version compatibility +You can edit this block to your own project and put it at the bottom of the **android/build.gradle** +```` +subprojects { + afterEvaluate {project -> + if (project.hasProperty("android")) { + android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + } + } + } +} +```` + # APIs ## ready() This method will check a bluetooth status and prepare to use it. ```` -const obd2 = require('react-native-obd2'); +const obd2 = require('@furkanom/react-native-obd2'); ... obd2.ready(); ```` @@ -21,7 +36,7 @@ obd2.ready(); This method brings available bluetooth device information including name and address. The result is array type of maps which consist of "name" and "address". ### Example ```` -const obd2 = require('react-native-obd2'); +const obd2 = require('@furkanom/react-native-obd2'); ... obd2.getBluetoothDeviceNameList() .then((nameList) => console.log('Bluetooth device list : ' + JSON.stringify(nameList))) @@ -42,7 +57,7 @@ The data is flow to your listeners. Therfore you have to set your listenr named ### Example ```` -const obd2 = require('react-native-obd2'); +const obd2 = require('@furkanom/react-native-obd2'); ... componentDidMount() { this.obdLiveDataListener = DeviceEventEmitter.addListener('obd2LiveData', this.obdLiveData); @@ -58,7 +73,7 @@ const obd2 = require('react-native-obd2'); Hey stop it! ## Listeners -### 'obd2bluetoothStatus' +### 'obd2bluetoothStatus' for getting bluetooth device status. JSON key | Type | Description diff --git a/android/build.gradle b/android/build.gradle index 063a6d6..e190934 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,22 +1,34 @@ +def safeExtGet(prop, fallback) { + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +} + +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.0.1' + } +} + apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion safeExtGet('compileSdkVersion', 26) + buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3') defaultConfig { - minSdkVersion 16 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - ndk { - abiFilters "armeabi-v7a", "x86" - } + minSdkVersion safeExtGet('minSdkVersion', 16) + targetSdkVersion safeExtGet('targetSdkVersion', 26) + } + lintOptions { + abortOnError false } } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.github.pires:obd-java-api:1.0' - compile "com.facebook.react:react-native:+" + implementation 'com.facebook.react:react-native:+' + implementation "com.github.pires:obd-java-api:1.0" } diff --git a/android/src/main/java/com/github/pires/obd/reader/config/ObdConfig.java b/android/src/main/java/com/github/pires/obd/reader/config/ObdConfig.java index 9e2a692..27a8f2c 100755 --- a/android/src/main/java/com/github/pires/obd/reader/config/ObdConfig.java +++ b/android/src/main/java/com/github/pires/obd/reader/config/ObdConfig.java @@ -42,41 +42,22 @@ public static ArrayList getCommands() { // Control cmds.add(new ModuleVoltageCommand()); - cmds.add(new EquivalentRatioCommand()); - cmds.add(new DistanceMILOnCommand()); - cmds.add(new DtcNumberCommand()); - cmds.add(new TimingAdvanceCommand()); - cmds.add(new TroubleCodesCommand()); - cmds.add(new VinCommand()); // Engine cmds.add(new LoadCommand()); cmds.add(new RPMCommand()); cmds.add(new RuntimeCommand()); - cmds.add(new MassAirFlowCommand()); cmds.add(new ThrottlePositionCommand()); + cmds.add(new RelativeAcceleratorPedalPositionCommand()); // Fuel cmds.add(new FindFuelTypeCommand()); cmds.add(new ConsumptionRateCommand()); - // cmds.add(new AverageFuelEconomyObdCommand()); - //cmds.add(new FuelEconomyCommand()); cmds.add(new FuelLevelCommand()); - // cmds.add(new FuelEconomyMAPObdCommand()); - // cmds.add(new FuelEconomyCommandedMAPObdCommand()); - cmds.add(new FuelTrimCommand(FuelTrim.LONG_TERM_BANK_1)); - cmds.add(new FuelTrimCommand(FuelTrim.LONG_TERM_BANK_2)); - cmds.add(new FuelTrimCommand(FuelTrim.SHORT_TERM_BANK_1)); - cmds.add(new FuelTrimCommand(FuelTrim.SHORT_TERM_BANK_2)); - cmds.add(new AirFuelRatioCommand()); - cmds.add(new WidebandAirFuelRatioCommand()); cmds.add(new OilTempCommand()); // Pressure - cmds.add(new BarometricPressureCommand()); cmds.add(new FuelPressureCommand()); - cmds.add(new FuelRailPressureCommand()); - cmds.add(new IntakeManifoldPressureCommand()); // Temperature cmds.add(new AirIntakeTemperatureCommand()); diff --git a/android/src/main/java/com/github/pires/obd/reader/config/RelativeAcceleratorPedalPositionCommand.java b/android/src/main/java/com/github/pires/obd/reader/config/RelativeAcceleratorPedalPositionCommand.java new file mode 100644 index 0000000..8cfa924 --- /dev/null +++ b/android/src/main/java/com/github/pires/obd/reader/config/RelativeAcceleratorPedalPositionCommand.java @@ -0,0 +1,41 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.github.pires.obd.reader.config; + +import com.github.pires.obd.commands.PercentageObdCommand; +import com.github.pires.obd.enums.AvailableCommandNames; + +/** + * Read the throttle position in percentage. + * + */ +public class RelativeAcceleratorPedalPositionCommand extends PercentageObdCommand { + + /** + * Default ctor. + */ + public RelativeAcceleratorPedalPositionCommand() { + super("01 5A"); + } + + public RelativeAcceleratorPedalPositionCommand(RelativeAcceleratorPedalPositionCommand other) { + super(other); + } + + /** {@inheritDoc} */ + @Override + public String getName() { + return AvailableCommandNames.REL_THROTTLE_POS.getValue(); + } + +} diff --git a/android/src/main/java/com/github/pires/obd/reader/io/ObdGatewayService.java b/android/src/main/java/com/github/pires/obd/reader/io/ObdGatewayService.java index 361bda3..cc34475 100755 --- a/android/src/main/java/com/github/pires/obd/reader/io/ObdGatewayService.java +++ b/android/src/main/java/com/github/pires/obd/reader/io/ObdGatewayService.java @@ -14,6 +14,7 @@ import android.util.Log; import com.facebook.react.bridge.ReactApplicationContext; +import com.github.pires.obd.commands.protocol.HeadersOffCommand; import com.github.pires.obd.commands.protocol.EchoOffCommand; import com.github.pires.obd.commands.protocol.LineFeedOffCommand; import com.github.pires.obd.commands.protocol.ObdResetCommand; @@ -121,10 +122,10 @@ private void startObdConnection() throws IOException { // Let's configure the connection. Log.d(TAG, "Queueing jobs for connection configuration.."); queueJob(new ObdCommandJob(new ObdResetCommand())); - + //Below is to give the adapter enough time to reset before sending the commands, otherwise the first startup commands could be ignored. try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } - + queueJob(new ObdCommandJob(new HeadersOffCommand())); queueJob(new ObdCommandJob(new EchoOffCommand())); /* @@ -133,9 +134,10 @@ private void startObdConnection() throws IOException { * TODO this can be done w/o having to queue jobs by just issuing * command.run(), command.getResult() and validate the result. */ + queueJob(new ObdCommandJob(new HeadersOffCommand())); queueJob(new ObdCommandJob(new EchoOffCommand())); queueJob(new ObdCommandJob(new LineFeedOffCommand())); - queueJob(new ObdCommandJob(new TimeoutCommand(62))); + // Get protocol from preferences // final String protocol = prefs.getString(ConfigActivity.PROTOCOLS_LIST_KEY, "AUTO"); diff --git a/android/src/main/java/com/jetbridge/reactobd2/OBD2Handler.java b/android/src/main/java/com/jetbridge/reactobd2/OBD2Handler.java index 32a3a1f..e54b343 100644 --- a/android/src/main/java/com/jetbridge/reactobd2/OBD2Handler.java +++ b/android/src/main/java/com/jetbridge/reactobd2/OBD2Handler.java @@ -77,7 +77,7 @@ public void run() { queueCommands(); } // run again in period defined in preferences - new Handler().postDelayed(mQueueCommands, 1000); + new Handler().postDelayed(mQueueCommands, 400); } }; diff --git a/android/src/main/java/com/jetbridge/reactobd2/ReactNativeOBD2Package.java b/android/src/main/java/com/jetbridge/reactobd2/ReactNativeOBD2Package.java index 38c0724..d68faf1 100644 --- a/android/src/main/java/com/jetbridge/reactobd2/ReactNativeOBD2Package.java +++ b/android/src/main/java/com/jetbridge/reactobd2/ReactNativeOBD2Package.java @@ -19,11 +19,6 @@ public List createNativeModules(ReactApplicationContext reactConte return modules; } - @Override - public List> createJSModules() { - return Collections.emptyList(); - } - @Override public List createViewManagers(ReactApplicationContext reactContext) { List result = new ArrayList(); diff --git a/example/src/components/OBDReader.js b/example/src/components/OBDReader.js index 962180e..d0ff9ee 100644 --- a/example/src/components/OBDReader.js +++ b/example/src/components/OBDReader.js @@ -32,7 +32,7 @@ import SharedPreference from 'react-native-sp'; import AppEventEmitter from '../services/AppEventEmitter'; -const obd2 = require('react-native-obd2'); +const obd2 = require('@furkanom/react-native-obd2'); const SensorManager = require('NativeModules').SensorManager; const Color = require('../utils/Color'); @@ -54,7 +54,7 @@ export default class OBDReader extends Component { btSelectedDeviceAddress: '', obdStatus: 'disconnected', debug : '-', - obd2Data : { } + obd2Data : { } }; this.sensorOrientation = this.sensorOrientation.bind(this); @@ -164,7 +164,7 @@ export default class OBDReader extends Component { this.setState({ isStartLiveData: true, }); - + SensorManager.startOrientation(1000); this.listenerOrientation = DeviceEventEmitter.addListener('Orientation', this.sensorOrientation); obd2.setMockUpMode(isMockUpMode); @@ -205,7 +205,7 @@ export default class OBDReader extends Component { .then((nameList) => { console.log('Bluetooth device list : ' + JSON.stringify(nameList)); this.setState({btDeviceList : nameList}); - + }) .catch((e) => { console.log('Get device name error : ' + e) @@ -219,7 +219,7 @@ export default class OBDReader extends Component { runMenu(value) { switch(value) { - case 1 : + case 1 : this.startLiveData(); break; case 2 : @@ -243,7 +243,7 @@ export default class OBDReader extends Component { return ( - + @@ -287,7 +287,7 @@ export default class OBDReader extends Component { { cmdData.map((item, index) => ( - @@ -330,4 +330,3 @@ const styles = StyleSheet.create({ color: Color.BLACK } }); - diff --git a/example/src/components/Settings.js b/example/src/components/Settings.js index 8c77d87..235ce37 100644 --- a/example/src/components/Settings.js +++ b/example/src/components/Settings.js @@ -33,7 +33,7 @@ import Category from './widget/PreferenceCategory'; import CheckBoxPreference from './widget/CheckBoxPreference'; import ListPreference from './widget/ListPreference'; -const obd2 = require('react-native-obd2'); +const obd2 = require('@furkanom/react-native-obd2'); const Color = require('../utils/Color'); const Constant = require('../utils/Constant'); @@ -76,7 +76,7 @@ export default class Settings extends Component { render() { return( - + + onSelected={(index) => { this.setState({ selectedBTDeviceIndex : index @@ -123,4 +123,3 @@ const styles = StyleSheet.create({ borderColor: Color.SETTING_BORDER_COLOR }, }); - diff --git a/package.json b/package.json index a383787..060bb4e 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "react-native-obd2", - "version": "0.0.2", + "name": "@furkanom/react-native-obd2", + "version": "0.0.5", "description": "OBDII data transferring for react-native Android.", "license": "MIT", - "author": "JetBridge, LLC.", + "author": "FurkanOM", "main": "index.js", "keywords": [ "react-native", @@ -13,10 +13,18 @@ ], "repository": { "type": "git", - "url": "https://github.com/jetbridge-io/react-native-obd2" + "url": "git+https://github.com/furkanom/react-native-obd2.git" }, - "dependencies": { + "dependencies": {}, + "devDependencies": {}, + "bugs": { + "url": "https://github.com/furkanom/react-native-obd2/issues" }, - "devDependencies": { + "homepage": "https://github.com/furkanom/react-native-obd2#readme", + "directories": { + "example": "example" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" } }