From 3da807a79e1ca4e7e663eea9d483b0a0cd0abd01 Mon Sep 17 00:00:00 2001 From: Furkan OM Date: Tue, 12 Mar 2019 11:27:40 +0300 Subject: [PATCH 1/5] headers off command added to initial command, relative accelerator pedal position command added, pull time decreased --- README.md | 19 ++++++++- .../pires/obd/reader/config/ObdConfig.java | 21 +--------- ...lativeAcceleratorPedalPositionCommand.java | 41 +++++++++++++++++++ .../obd/reader/io/ObdGatewayService.java | 8 ++-- .../com/jetbridge/reactobd2/OBD2Handler.java | 2 +- .../reactobd2/ReactNativeOBD2Package.java | 5 --- package.json | 8 ++-- 7 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 android/src/main/java/com/github/pires/obd/reader/config/RelativeAcceleratorPedalPositionCommand.java diff --git a/README.md b/README.md index 9f2d15f..9da51f7 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,23 @@ $ npm install 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 { + project.configurations.all { + afterEvaluate {project -> + if (project.hasProperty("android")) { + android { + compileSdkVersion 28 + buildToolsVersion '28.0.2' + } + } + } + } +} +```` + # APIs ## ready() This method will check a bluetooth status and prepare to use it. @@ -58,7 +75,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/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/package.json b/package.json index a383787..8102dd1 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.3", "description": "OBDII data transferring for react-native Android.", "license": "MIT", - "author": "JetBridge, LLC.", + "author": "FurkanOM", "main": "index.js", "keywords": [ "react-native", @@ -13,7 +13,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/jetbridge-io/react-native-obd2" + "url": "https://github.com/furkanom/react-native-obd2" }, "dependencies": { }, From 4d6ec4b6d3b9c7302a2cffb1d265db650dc6d96a Mon Sep 17 00:00:00 2001 From: Furkan OM Date: Tue, 12 Mar 2019 11:40:03 +0300 Subject: [PATCH 2/5] commit for publish npm package --- package.json | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8102dd1..9dfdb2d 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,18 @@ ], "repository": { "type": "git", - "url": "https://github.com/furkanom/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" } } From 37cdca7a23ffe009c7fdf4855bde54b487286401 Mon Sep 17 00:00:00 2001 From: Furkan OM Date: Fri, 5 Apr 2019 14:41:59 +0300 Subject: [PATCH 3/5] import bug fixed, readme updated --- README.md | 8 ++++---- example/src/components/OBDReader.js | 23 +++++++++++------------ example/src/components/Settings.js | 7 +++---- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9da51f7..b388d88 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 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 ```` @@ -29,7 +29,7 @@ subprojects { ## 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(); ```` @@ -38,7 +38,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))) @@ -59,7 +59,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); 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 }, }); - From 30a3e02d5a406a64fd98c6e662b23e580f6d33ba Mon Sep 17 00:00:00 2001 From: Furkan OM Date: Fri, 5 Apr 2019 14:46:24 +0300 Subject: [PATCH 4/5] package version changed --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9dfdb2d..0f1d333 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@furkanom/react-native-obd2", - "version": "0.0.3", + "version": "0.0.4", "description": "OBDII data transferring for react-native Android.", "license": "MIT", "author": "FurkanOM", From b77f11629848218e43f268212b40e6eff6307dd4 Mon Sep 17 00:00:00 2001 From: Furkan OM Date: Sun, 2 Jun 2019 13:58:29 +0300 Subject: [PATCH 5/5] android build gradle file updated --- README.md | 12 +++++------- android/build.gradle | 36 ++++++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b388d88..acf392c 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,11 @@ $ react-native link You can edit this block to your own project and put it at the bottom of the **android/build.gradle** ```` subprojects { - project.configurations.all { - afterEvaluate {project -> - if (project.hasProperty("android")) { - android { - compileSdkVersion 28 - buildToolsVersion '28.0.2' - } + afterEvaluate {project -> + if (project.hasProperty("android")) { + android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion } } } 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/package.json b/package.json index 0f1d333..060bb4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@furkanom/react-native-obd2", - "version": "0.0.4", + "version": "0.0.5", "description": "OBDII data transferring for react-native Android.", "license": "MIT", "author": "FurkanOM",