From 6c846e7a2587dc576e1a20179bf18528179a25b6 Mon Sep 17 00:00:00 2001 From: cyberarm Date: Tue, 20 Sep 2022 17:28:53 -0500 Subject: [PATCH] Added opmodes to start/stop TACNET service, sync. --- .../external/samples/sample_conventions.md | 4 +-- .../internal/FtcRobotControllerActivity.java | 6 ++++ README.md | 10 +++--- .../tacnet_management/HaltTACNETService.java | 26 ++++++++++++++++ .../tacnet_management/StartTACNETService.java | 31 +++++++++++++++++++ build.dependencies.gradle | 1 + build.gradle | 2 +- 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 TeamCode/src/main/java/org/timecrafters/tacnet_management/HaltTACNETService.java create mode 100644 TeamCode/src/main/java/org/timecrafters/tacnet_management/StartTACNETService.java diff --git a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/sample_conventions.md b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/sample_conventions.md index afe14a4..45968ef 100644 --- a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/sample_conventions.md +++ b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/sample_conventions.md @@ -55,7 +55,7 @@ becomes obsolete. ### Device Configuration Names The following device names are used in the external samples - + ** Motors: left_drive right_drive @@ -82,7 +82,7 @@ digout ** Localization: compass gyro -imu +imu navx ### Device Object Names diff --git a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/internal/FtcRobotControllerActivity.java b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/internal/FtcRobotControllerActivity.java index 327d3ec..137fb43 100644 --- a/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/internal/FtcRobotControllerActivity.java +++ b/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/internal/FtcRobotControllerActivity.java @@ -183,6 +183,11 @@ public class FtcRobotControllerActivity extends Activity private WifiDirectChannelChanger wifiDirectChannelChanger; + private static FtcRobotControllerActivity appActivity; + public static FtcRobotControllerActivity getAppActivity() { + return appActivity; + } + protected class RobotRestarter implements Restarter { public void requestRestart() { @@ -267,6 +272,7 @@ public class FtcRobotControllerActivity extends Activity @Override protected void onCreate(Bundle savedInstanceState) { + appActivity = this; super.onCreate(savedInstanceState); if (enforcePermissionValidator()) { diff --git a/README.md b/README.md index bdb61ad..3347f5a 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,8 @@ The readme.md file located in the [/TeamCode/src/main/java/org/firstinspires/ftc * Allows disabling bluetooth radio from inspection screen * Improves warning messages when I2C devices are not responding * Adds support for controlling the RGB LED present on PS4/Etpark gamepads from OpModes -* Removes legacy Pushbot references from OpMode samples. Renames "Pushbot" samples to "Robot". Motor directions reversed to be compatible with "direct Drive" drive train. - +* Removes legacy Pushbot references from OpMode samples. Renames "Pushbot" samples to "Robot". Motor directions reversed to be compatible with "direct Drive" drive train. + ### Bug fixes * Fixes [issue #316](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/316) (MatrixF.inverted() returned an incorrectly-sized matrix for 1x1 and 2x2 matrixes). @@ -256,14 +256,14 @@ The readme.md file located in the [/TeamCode/src/main/java/org/firstinspires/ftc Cannot open OpModes in v6.1 Blocks offline editor * Fixes [FtcRobotController issue #79](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/79) 6.1 causes a soft reboot on the Motorola E5 Play -* Fixes issue where the Control Hub OS's watchdog would restart the Robot Controller app if +* Fixes issue where the Control Hub OS's watchdog would restart the Robot Controller app if the Control Hub was not able to communicate with its internal Expansion Hub -* Fixes certain I2C devices not showing up in the appropriate `HardwareMap` fields (such as `hardwareMap.colorSensor`) +* Fixes certain I2C devices not showing up in the appropriate `HardwareMap` fields (such as `hardwareMap.colorSensor`) * Fixes issue where performing a Wi-Fi factory reset on the Control Hub would not set the Wi-Fi band to 2.4 GHz * Fixes issue where OnBotJava might fail to create a new file if the option to "Setup Code for Configured Hardware" was selected * Fixes issue where performing certain operations after an Op Mode crashes would temporarily break Control/Expansion Hub communication * Fixes issue where a Control Hub with a configured USB-connected Expansion Hub would not work if the Expansion Hub was missing at startup -* Fixes potential issues caused by having mismatched Control/Expansion Hub firmware versions +* Fixes potential issues caused by having mismatched Control/Expansion Hub firmware versions * Fixes [ftc_app issue 673](https://github.com/ftctechnh/ftc_app/issues/673) Latest matchlog is being deleted instead of old ones by RobotLog * Fixes ConceptVuforiaUltimateGoalNavigationWebcam sample opmode by correctly orienting camera on robot. * Fixes issue where logcat would be spammed with InterruptedExceptions when stop is requested from the Driver Station (this behavior was accidentally introduced in v5.3). This change has no impact on functionality. diff --git a/TeamCode/src/main/java/org/timecrafters/tacnet_management/HaltTACNETService.java b/TeamCode/src/main/java/org/timecrafters/tacnet_management/HaltTACNETService.java new file mode 100644 index 0000000..ca0b34a --- /dev/null +++ b/TeamCode/src/main/java/org/timecrafters/tacnet_management/HaltTACNETService.java @@ -0,0 +1,26 @@ +package org.timecrafters.tacnet_management; + +import android.content.Context; +import android.content.Intent; + +import com.qualcomm.robotcore.eventloop.opmode.OpMode; +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; + +import org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity; + +@TeleOp(name = "Halt TACNET Service", group = "TACNET") +public class HaltTACNETService extends OpMode { + @Override + public void init() { + Context appContext = FtcRobotControllerActivity.getAppActivity().getApplicationContext(); + Intent tacnetIntent = new Intent("org.timecrafters.TimeCraftersConfigurationTool.tacnet.ACTION_START_SERVER"); + tacnetIntent.setPackage("org.timecrafters.TimeCraftersConfigurationTool"); + + appContext.stopService(tacnetIntent); + } + + @Override + public void loop() { + stop(); + } +} diff --git a/TeamCode/src/main/java/org/timecrafters/tacnet_management/StartTACNETService.java b/TeamCode/src/main/java/org/timecrafters/tacnet_management/StartTACNETService.java new file mode 100644 index 0000000..db0cef7 --- /dev/null +++ b/TeamCode/src/main/java/org/timecrafters/tacnet_management/StartTACNETService.java @@ -0,0 +1,31 @@ +package org.timecrafters.tacnet_management; + +import android.content.Context; +import android.content.Intent; +import android.os.Build; + +import com.qualcomm.robotcore.eventloop.opmode.OpMode; +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; + +import org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity; + +@TeleOp(name = "Start TACNET Service", group = "TACNET") +public class StartTACNETService extends OpMode { + @Override + public void init() { + Context appContext = FtcRobotControllerActivity.getAppActivity().getApplicationContext(); + Intent tacnetIntent = new Intent("org.timecrafters.TimeCraftersConfigurationTool.tacnet.ACTION_START_SERVER"); + tacnetIntent.setPackage("org.timecrafters.TimeCraftersConfigurationTool"); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + appContext.startForegroundService(tacnetIntent); + } else { + appContext.startService(tacnetIntent); + } + } + + @Override + public void loop() { + stop(); + } +} diff --git a/build.dependencies.gradle b/build.dependencies.gradle index fbbdfad..56f72c9 100644 --- a/build.dependencies.gradle +++ b/build.dependencies.gradle @@ -19,3 +19,4 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'org.firstinspires.ftc:gameAssets-PowerPlay:1.0.0' } + diff --git a/build.gradle b/build.gradle index 4f9be88..2ce4e62 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:7.2.0' } }