Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion sensorhub-android-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

description = 'OSH Android App'
ext.details = 'OSH app for Android'
ext.details = 'OSH app for Android'

repositories {
// maven {
Expand Down Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation project(':sensorhub-android-polar')
implementation project(':sensorhub-android-wardriving')
implementation project(':sensorhub-android-controller')
implementation project(':sensorhub-android-template')
implementation project(':sensorhub-driver-android')
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'com.github.tony19:logback-android:3.0.0'
Expand Down Expand Up @@ -59,8 +60,24 @@ android {
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName rootProject.version
applicationId "com.georobotix.android"
}

//https://developer.android.com/build/build-variants#groovy
// flavorDimensions += "version" // maybe dont need
// productFlavors {
// create("free") {
// dimension = "version"
// applicationIdSuffix = ".free"
// buildConfigField("boolean", "IS_PREMIUM", "false")
// }
// create("premium") {
// dimension = "version"
// applicationIdSuffix = ".premium"
// buildConfigField("boolean", "IS_PREMIUM", "true")
// }
// }

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
Expand Down Expand Up @@ -94,5 +111,6 @@ android {
excludes += ["META-INF/INDEX.LIST"]
}
}

}

25 changes: 25 additions & 0 deletions sensorhub-android-app/res/xml/pref_sensors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,29 @@
android:entryValues="@array/sos_option_values"
android:defaultValue="@array/sos_option_defaults"
android:layout="@layout/preference_list_item"/>

<!-- TEMPLATE DRIVER -->
<SwitchPreferenceCompat
android:key="template_enabled"
android:defaultValue="false"
android:summary="Enable streaming of template driver"
android:title="Template Driver Data"
android:layout="@layout/preference_switch_item" />

<Preference
android:key="template_device_address"
android:visible="false"
android:title="Select template Device"
android:summary="Tap to select or enter device address"
android:layout="@layout/preference_list_item" />

<MultiSelectListPreference
android:key="template_options"
android:visible="false"
android:title="Template Driver Output Options"
android:summary="Options for pushing sensor data"
android:entries="@array/sos_option_list"
android:entryValues="@array/sos_option_values"
android:defaultValue="@array/sos_option_defaults"
android:layout="@layout/preference_list_item"/>
</PreferenceScreen>
22 changes: 19 additions & 3 deletions sensorhub-android-app/src/org/sensorhub/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package org.sensorhub.android;

import static android.content.ContentValues.TAG;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
Expand Down Expand Up @@ -89,6 +87,7 @@
import org.sensorhub.impl.sensor.meshtastic.control.TextMessageControl;
import org.sensorhub.impl.sensor.polar.PolarConfig;
import org.sensorhub.impl.sensor.ste.STERadPagerConfig;
import org.sensorhub.impl.sensor.template.TemplateConfig;
import org.sensorhub.impl.sensor.trupulse.SimulatedDataStream;
import org.sensorhub.impl.sensor.trupulse.TruPulseConfig;
import org.sensorhub.impl.sensor.trupulse.TruPulseWithGeolocConfig;
Expand Down Expand Up @@ -166,7 +165,8 @@ enum Sensors {
PolarHRMonitor,
Kestrel,
Wardriving,
Controller
Controller,
Template
}

private final ServiceConnection sConn = new ServiceConnection()
Expand Down Expand Up @@ -554,6 +554,19 @@ public boolean verify(String arg0, SSLSession arg1) {
if (isSosServiceEnabled) {
sensorhubConfig.add(sosConfig);
}

// Template Driver
enabled = prefs.getBoolean("template_enabled", false);
if (enabled) {
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.id = "TEMPLATE_DRIVER_";
templateConfig.name = "Template [" + deviceName + "]";
templateConfig.autoStart = true;
templateConfig.lastUpdated = ANDROID_SENSORS_LAST_UPDATED;
templateConfig.uid_extension = prefs.getString("uid_extension", "");
sensorhubConfig.add(templateConfig);
}

}

protected void addSosTConfig(SensorConfig sensorConf, String user, String pwd)
Expand Down Expand Up @@ -889,6 +902,9 @@ boolean isPushingSensor(Sensors sensor) {
} else if (Sensors.Controller.equals(sensor)) {
return prefs.getBoolean("controller_enabled", false)
&& prefs.getStringSet("controller_options", Collections.emptySet()).contains("PUSH_REMOTE");
} else if (Sensors.Template.equals(sensor)) {
return prefs.getBoolean("template_enabled", false)
&& prefs.getStringSet("template_options", Collections.emptySet()).contains("PUSH_REMOTE");
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@
public class SensorsFragment extends PreferenceFragmentCompat {

private static final String[][] SWITCH_DEPENDENTS = {
{"accel_enabled", "accel_options"},
{"gyro_enabled", "gyro_options"},
{"mag_enabled", "mag_options"},
{"accel_enabled", "accel_options"},
{"gyro_enabled", "gyro_options"},
{"mag_enabled", "mag_options"},
{"orient_quat_enabled", "orient_quat_options"},
{"orient_euler_enabled","orient_euler_options"},
{"gps_enabled", "gps_options"},
{"netloc_enabled", "netloc_options"},
{"cam_enabled", "cam_options", "video_codec", "video_framerate", "video_preset", "camera_select"},
{"video_roll_enabled", "video_roll_options"},
{"audio_enabled", "audio_options", "audio_codec", "audio_samplerate", "audio_bitrate"},
{"meshtastic_enabled", "meshtastic_device_address", "meshtastic_options"},
{"polar_enabled", "polar_device_address", "polar_options"},
{"kestrel_enabled", "kestrel_device_address", "kestrel_options"},
{"trupulse_enabled", "trupulse_datasource", "trupulse_options", "trupulse_device_address", "trupulse_simu"},
{"angel_enabled", "angel_address", "angel_options"},
{"flirone_enabled", "flir_options"},
{"gps_enabled", "gps_options"},
{"netloc_enabled", "netloc_options"},
{"cam_enabled", "cam_options", "video_codec", "video_framerate", "video_preset", "camera_select"},
{"video_roll_enabled", "video_roll_options"},
{"audio_enabled", "audio_options", "audio_codec", "audio_samplerate", "audio_bitrate"},
{"meshtastic_enabled", "meshtastic_device_address", "meshtastic_options"},
{"polar_enabled", "polar_device_address", "polar_options"},
{"kestrel_enabled", "kestrel_device_address", "kestrel_options"},
{"trupulse_enabled", "trupulse_datasource", "trupulse_options", "trupulse_device_address", "trupulse_simu"},
{"angel_enabled", "angel_address", "angel_options"},
{"flirone_enabled", "flir_options"},
{"ste_radpager_enabled","ste_radpager_options"},
{"wardriving_enabled", "wardriving_options"},
{"controller_enabled", "controller_options"},
{"template_enabled", "template_device_address", "template_options"},

};

Expand All @@ -64,6 +65,7 @@ public class SensorsFragment extends PreferenceFragmentCompat {
"polar_device_address",
"kestrel_device_address",
"trupulse_device_address",
"template_device_address"
};

private ArrayList<String> frameRateList = new ArrayList<>();
Expand Down
21 changes: 21 additions & 0 deletions sensorhub-android-template/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.sensorhub.impl.sensor.wardriving">

<!-- WiFi scanning -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<!-- Location required for WiFi/BLE scan results on Android 6+ -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- Nearby WiFi devices permission for Android 13+ -->
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />

<!-- BLE scanning -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

</manifest>
91 changes: 91 additions & 0 deletions sensorhub-android-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Template Driver Integration

## 1. Add the Template Module
- Duplciate the template directory
- Rename it appropriately

## 2. Add dependency to App Module:
- In 'sensorhub-android-app' `build.gradle` we need to include the project as a dependency:
```groovy
implementation project(':sensorhub-android-template')
```
## 3. Add Preferences UI
- In `res/xml/pref_sensors.xml`, add:
```xml
<SwitchPreferenceCompat
android:key="template_enabled"
android:defaultValue="false"
android:summary="Enable streaming of template driver"
android:title="Template Driver Data"
android:layout="@layout/preference_switch_item" />

<MultiSelectListPreference
android:key="template_options"
android:visible="false"
android:title="Template Driver Output Options"
android:summary="Options for pushing sensor data"
android:entries="@array/sos_option_list"
android:entryValues="@array/sos_option_values"
android:defaultValue="@array/sos_option_defaults"
android:layout="@layout/preference_list_item"/>
```

- In `SensorsFragment.java`, include the "enabled" and "options" in the SWITCH_DEPENDENTS map.
-
- **Note:** If the driver uses BLE to connect you must also add the ability to select the devices 'BLE Address' (Examples: Kestrel, Trupulse, Meshtastic,+ Polar)
- Add device selection:
```xml
<Preference
android:key="template_device_address"
android:visible="false"
android:title="Select Device"
android:summary="Tap to select or enter device address"
android:layout="@layout/preference_list_item" />
```
- In `SensorsFragment.java`, include the "template_device_address" under the BT_DEVICE_PREF_KEYS

## 4. Update `MainActivity`
- Import the drivers Config class
`import org.sensorhub.impl.sensor.template.TemplateConfig;`
- Add to `Sensors Enum`
```
Template
```

- Enable Push check
Update `isPushingSensors(Sensors sensor)`:
```
if (Sensors.Template.equals(sensor)) {
return prefs.getBoolean("template_enabled", false)
&& prefs.getStringSet("template_options", Collections.emptySet()).contains("PUSH_REMOTE");
}
```
- Add to updateConfig(...)
```
// Template Driver
enabled = prefs.getBoolean("template_enabled", false);
if (enabled) {
SensorConfig templateConfig = new SensorConfig();
templateConfig.id = "TEMPLATE_DRIVER_";
templateConfig.name = "Template [" + deviceName + "]";
templateConfig.autoStart = true;
templateConfig.lastUpdated = ANDROID_SENSORS_LAST_UPDATED;
templateConfig.uid_extension = prefs.getString("uid_extension", "");
sensorhubConfig.add(templateConfig);
}
```


### Adding External Modules (osh-addons/osh-core/...)
This is slightly different process then local modules
1. Include the module in `settings.gradle`
```groovy
'sensors/positioning/sensorhub-driver-trupulse'
```
**>**: Ensure the module path in settings.gradle matches the project folder structure exactly, and you include the correct submodule repository

2. Add Dependency in `sensorhub-android-lib`
```groovy
api project(':sensorhub-driver-kestrel')
```
3. Repeat steps 3-5 in the first set of instructions
47 changes: 47 additions & 0 deletions sensorhub-android-template/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'

description = 'Template Driver'
ext.details = 'Driver template for android'
version = '1.0.0'

dependencies {
//api 'org.sensorhub:sensorhub-core:' + oshCoreVersion
api project(':sensorhub-core')
api project(':sensorhub-android-service')

implementation 'io.reactivex.rxjava3:rxjava:3.1.6'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation project(path: ':sensorhub-driver-android')
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core:1.5.0'
}
configurations.configureEach {
exclude group: "ch.qos.logback"
}

android {
namespace 'org.sensorhub.impl.sensor.template'
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
}

lintOptions {
abortOnError false
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/resources']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
}
Loading