Skip to content

Commit

Permalink
UART API exposed for other apps, e.g. Tasker. Support library v.22.1.…
Browse files Browse the repository at this point in the history
…1, build tools 22.0.1.

The app is still using ActionBarActivity instead of AppCompatActivity.
  • Loading branch information
philips77 committed Apr 29, 2015
1 parent e1e2d72 commit fe23ee9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="nrf-logger-v2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
<orderEntry type="library" exported="" name="achartengine-1.1.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="module" module-name="dfu" exported="" />
</component>
</module>
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "no.nordicsemi.android.nrftoolbox"
minSdkVersion 18
targetSdkVersion 22
versionCode 31
versionName "1.13.0"
versionCode 32
versionName "1.13.1"
}
buildTypes {
release {
Expand All @@ -20,7 +20,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(':..:DFULibrary:dfu')
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/nrf-logger-v2.0.jar')
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="no.nordicsemi.android.nrftoolbox"
android:installLocation="auto"
android:versionCode="31"
android:versionName="1.13.0" >
android:versionCode="32"
android:versionName="1.13.1" >

<uses-sdk
android:minSdkVersion="18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
public static final String BROADCAST_UART_RX = "no.nordicsemi.android.nrftoolbox.uart.BROADCAST_UART_RX";
public static final String EXTRA_DATA = "no.nordicsemi.android.nrftoolbox.uart.EXTRA_DATA";

/** A broadcast message with this action and the message in {@link Intent#EXTRA_TEXT} will be sent t the UART device. */
private final static String ACTION_SEND = "no.nordicsemi.android.nrftoolbox.uart.ACTION_SEND";
/** A broadcast message with this action is triggered when a message is received from the UART device. */
private final static String ACTION_RECEIVE = "no.nordicsemi.android.nrftoolbox.uart.ACTION_RECEIVE";
/** Action send when user press the DISCONNECT button on the notification. */
private final static String ACTION_DISCONNECT = "no.nordicsemi.android.nrftoolbox.uart.ACTION_DISCONNECT";

private final static int NOTIFICATION_ID = 349; // random
Expand Down Expand Up @@ -79,16 +84,16 @@ protected BleManager<UARTManagerCallbacks> initializeManager() {
public void onCreate() {
super.onCreate();

final IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_DISCONNECT);
registerReceiver(mDisconnectActionBroadcastReceiver, filter);
registerReceiver(mDisconnectActionBroadcastReceiver, new IntentFilter(ACTION_DISCONNECT));
registerReceiver(mIntentBroadcastReceiver, new IntentFilter(ACTION_SEND));
}

@Override
public void onDestroy() {
// when user has disconnected from the sensor, we have to cancel the notification that we've created some milliseconds before using unbindService
cancelNotification();
unregisterReceiver(mDisconnectActionBroadcastReceiver);
unregisterReceiver(mIntentBroadcastReceiver);

super.onDestroy();
}
Expand Down Expand Up @@ -118,10 +123,15 @@ public void onDataReceived(final String data) {
final Intent broadcast = new Intent(BROADCAST_UART_RX);
broadcast.putExtra(EXTRA_DATA, data);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);

// send the data received to other apps, e.g. the Tasker
final Intent globalBroadcast = new Intent(ACTION_RECEIVE);
globalBroadcast.putExtra(Intent.EXTRA_TEXT, data);
sendBroadcast(globalBroadcast);
}

@Override
public void onDataSent(String data) {
public void onDataSent(final String data) {
Logger.a(getLogSession(), "\"" + data + "\" sent");

final Intent broadcast = new Intent(BROADCAST_UART_TX);
Expand Down Expand Up @@ -181,4 +191,16 @@ public void onReceive(final Context context, final Intent intent) {
}
};

/**
* Broadcast receiver that listens for {@link #ACTION_SEND} from other apps. Sends the String content of the {@link Intent#EXTRA_TEXT} extra to the remote device.
*/
private BroadcastReceiver mIntentBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
Logger.i(getLogSession(), "[Broadcast] Disconnect action pressed");
final String message = intent.getStringExtra(Intent.EXTRA_TEXT);
mManager.send(message);
}
};

}

0 comments on commit fe23ee9

Please sign in to comment.