Skip to content

Commit

Permalink
Fix incorrect battery readings by delaying the read of the battery le…
Browse files Browse the repository at this point in the history
…vel by 20ms when the Bluetooth connection is established. Also re-read the battery level when activating the power fragment.
  • Loading branch information
Rob Riggs committed Apr 28, 2016
1 parent e07058c commit d261678
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Expand Up @@ -3,13 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.mobilinkd.tncconfig"
android:versionCode="8"
android:versionName="1.1.2" >
android:versionName="1.1.3" >

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="21" />
android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" ></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
2 changes: 1 addition & 1 deletion project.properties
Expand Up @@ -11,7 +11,7 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-21
target=Google Inc.:Google APIs:23
android.library.reference.1=../gridlayout_v7
android.library.reference.2=../android-numberpicker/library
android.library=false
Expand Down
4 changes: 2 additions & 2 deletions res/values/strings.xml
Expand Up @@ -73,8 +73,8 @@
<string name="about_content">
Mobilinkd TNC Configuration Utility\n
For Mobilinkd TNC1 and TNC2 devices\n
Version 1.1.2 &#8211; 2015-02-07\n\n
Copyright &#169; 2015 Mobilinkd LLC.\n
Version 1.1.3 &#8211; 2016-04-27\n\n
Copyright &#169; 2013-2016 Mobilinkd LLC.\n
Chicago, Illinois, USA\n\n
This software is released under the Apache Software License 2.0\n\n
Credit to:\n
Expand Down
1 change: 0 additions & 1 deletion src/com/mobilinkd/tncconfig/Avr109.java
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down
22 changes: 21 additions & 1 deletion src/com/mobilinkd/tncconfig/BluetoothTncService.java
Expand Up @@ -121,6 +121,8 @@ public class BluetoothTncService {
new byte[] { (byte)0xc0, 0x06, 0x50, (byte)0xC0 };
private static final byte[] TNC_SAVE_EEPROM =
new byte[] { (byte)0xc0, 0x06, 0x2a, (byte)0xC0 };
private static final byte[] TNC_GET_BATTERY_LEVEL =
new byte[] { (byte)0xc0, 0x06, 0x06, (byte)0xC0 };

/**
* Constructor. Prepares a new Bluetooth session.
Expand Down Expand Up @@ -154,7 +156,10 @@ private synchronized void setState(int state) {
mState = state;

// Give the new state to the Handler so the UI Activity can update
mHandler.obtainMessage(TncConfig.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
Message msg = mHandler.obtainMessage(TncConfig.MESSAGE_STATE_CHANGE, state, -1);
// Without a delay, battery level is incorrect on newer devices.
// This is due to the electrical characteristics of the TNC2.
mHandler.sendMessageDelayed(msg, 20);
}

/**
Expand Down Expand Up @@ -257,6 +262,21 @@ public void getAllValues()
r.write(TNC_GET_ALL_VALUES);
}

public void getBatteryLevel()
{
if (D) Log.d(TAG, "getBatteryLevel()");

// Create temporary object
ConnectedThread r;
// Synchronize a copy of the ConnectedThread
synchronized (this) {
if (mState != STATE_CONNECTED) return;
r = mConnectedThread;
}

r.write(TNC_GET_BATTERY_LEVEL);
}

public boolean isConnected() {
return mState == STATE_CONNECTED;
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/mobilinkd/tncconfig/TncConfig.java
Expand Up @@ -509,6 +509,9 @@ public void onClick(View view) {
mPowerButton = (Button) findViewById(R.id.powerButton);
mPowerButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {

mTncService.getBatteryLevel();

FrameLayout fragmentView = (FrameLayout) findViewById(R.id.fragment_view);

FragmentManager fragmentManager = getSupportFragmentManager();
Expand Down Expand Up @@ -848,7 +851,7 @@ public void onKissDialogResume(KissFragment dialog) {
public void onModemDialogUpdate(ModemFragment dialog) {
if(D) Log.i(TAG, "onModemDialogPause()");
if(D) Log.i(TAG, "DCD: " + dialog.getDcd());
if(D) Log.i(TAG, "Has ConnTrack" + dialog.hasConnTrack());
if(D) Log.i(TAG, "Has ConnTrack: " + dialog.hasConnTrack());
if(D && dialog.hasConnTrack()) Log.i(TAG, "ConnTrack: " + dialog.getConnTrack());
if(D) Log.i(TAG, "Verbose: " + dialog.getVerbose());

Expand Down

0 comments on commit d261678

Please sign in to comment.