Compare commits

...

7 Commits

Author SHA1 Message Date
Roberto Viola
df3068a003 adding shellruntime to get the log from adb too 2023-02-10 10:28:06 +01:00
Roberto Viola
00425a5c0d parsing done from OCR 2023-02-10 09:27:17 +01:00
Roberto Viola
e5d753aeb1 trying to restart adb if it fails to get metrics 2023-02-09 18:28:02 +01:00
Roberto Viola
1da8cf3338 Merge branch 'pelotonbike' of https://github.com/cagnulein/qdomyos-zwift into pelotonbike 2023-02-09 18:18:03 +01:00
Roberto Viola
723009261b using mlkit v2 without model needing
https://stackoverflow.com/questions/68806597/android-ml-kit-textrecognizer-without-google-play-services
2023-02-09 14:38:33 +01:00
Roberto Viola
0c465e41fc trying to clean the log 2023-02-08 17:19:19 +01:00
Roberto Viola
f05b201595 trying to use the adb method 2023-02-08 09:22:04 +01:00
8 changed files with 104 additions and 11 deletions

View File

@@ -85,10 +85,6 @@
android:name=".ScreenCaptureService"
android:foregroundServiceType="mediaProjection" />
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="ocr" />
<activity android:name="org.cagnulen.qdomyoszwift.MyActivity" />
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>

View File

@@ -22,7 +22,7 @@ dependencies {
compile 'com.rvalerio:fgchecker:1.1.0'
implementation "androidx.core:core-ktx:+"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:18.0.2'
implementation 'com.google.mlkit:text-recognition:16.0.0-beta6'
implementation 'com.google.android.play:core:1.8.2'
def appcompat_version = "1.3.1"

View File

@@ -0,0 +1,54 @@
package org.cagnulen.qdomyoszwift;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ShellRuntime {
private static final String LOG_TAG = "QZ:Shell";
private static final Runtime runtime = Runtime.getRuntime();
private static String sh = null;
static String lastLine;
public static String lastOutput() {
return lastLine;
}
public static void execAndGetOutput(String command) throws IOException {
Process proc = exec(command);
BufferedReader is = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
lastLine = "";
while ((line = is.readLine()) != null) {
//Log.d(LOG_TAG, line);
lastLine = lastLine + line;
}
}
public static Process exec(String command) throws IOException {
String[] cmd = {getSh(), "-c", " " + command};
return runtime.exec(cmd);
}
private static String getSh() {
if(sh == null) {
sh = "/bin/sh";
try {
execAndGetOutput("ls");
} catch (final Exception ex) {
Log.w(LOG_TAG, "Calling " + sh + " failed", ex);
sh = "/system/bin/sh";
}
Log.d(LOG_TAG, "Using sh: " + sh);
}
return sh;
}
}

View File

@@ -6,7 +6,7 @@
#include <QThread>
class androidadblog : public QThread
{
{
Q_OBJECT
public:

View File

@@ -376,11 +376,11 @@ homeform::homeform(QQmlApplicationEngine *engine, bluetooth *bl) {
stravaWorkoutName = QLatin1String("");
movieFileName = QUrl("");
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS))
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS)) || defined(PELOTONBIKE)
#ifndef STEAM_STORE
connect(engine, &QQmlApplicationEngine::quit, &QGuiApplication::quit);
connect(&tLicense, &QTimer::timeout, this, &homeform::licenseTimeout);
tLicense.start(600000);
tLicense.start(1200000);
licenseRequest();
#endif
#endif
@@ -5643,7 +5643,7 @@ int homeform::preview_workout_points() {
return 0;
}
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS))
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS)) || defined(PELOTONBIKE)
void homeform::licenseReply(QNetworkReply *reply) {
QString r = reply->readAll();
qDebug() << r;

View File

@@ -21,6 +21,8 @@
#include <QQuickItemGrabResult>
#include <QTextToSpeech>
#define PELOTONBIKE
class DataObject : public QObject {
Q_OBJECT
@@ -653,7 +655,7 @@ class homeform : public QObject {
QTextToSpeech m_speech;
int tts_summary_count = 0;
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS))
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS)) || defined(PELOTONBIKE)
QTimer tLicense;
QNetworkAccessManager *mgr = nullptr;
void licenseRequest();
@@ -728,7 +730,7 @@ class homeform : public QObject {
void pelotonOffset_Minus();
int pelotonOffset() { return (trainProgram ? trainProgram->offsetElapsedTime() : 0); }
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS))
#if defined(Q_OS_WIN) || (defined(Q_OS_MAC) && !defined(Q_OS_IOS)) || defined(PELOTONBIKE)
void licenseReply(QNetworkReply *reply);
void licenseTimeout();
#endif

View File

@@ -57,6 +57,46 @@ void pelotonbike::update() {
"org/cagnulen/qdomyoszwift/ScreenCaptureService", "getLastText");
QString t = text.toString();
qDebug() << "OCR" << t;
QStringList list = t.split('\n');
bool waitCadence = false;
bool waitPower = false;
bool waitResistance = false;
bool waitSpeed = false;
foreach(QString l, list) {
if(l.startsWith("CADENCE")) {
waitCadence = true;
} else if(l.startsWith("RESISTANCE")) {
waitResistance = true;
} else if(l.startsWith("OUTPUT")) {
waitPower = true;
} else if(l.startsWith("SPEED")) {
waitSpeed = true;
} else if(waitCadence) {
waitCadence = false;
Cadence = l.toInt();
} else if(waitPower) {
waitPower = false;
m_watt = l.toInt();
} else if(waitResistance) {
waitResistance = false;
Resistance = l.toInt();
} else if(waitSpeed) {
waitSpeed = false;
Speed = l.split(" ").first().toDouble();
}
}
QAndroidJniObject adb = QAndroidJniObject::callStaticObjectMethod<jstring>(
"org/cagnulen/qdomyoszwift/ShellRuntime", "lastOutput");
QString tAdb = adb.toString();
qDebug() << "ADB lastOutput" << tAdb;
QString command = "logcat -d | grep \"V1Callback\"";
QAndroidJniObject commandString = QAndroidJniObject::fromString(command);
QAndroidJniObject::callStaticMethod<void>(
"org/cagnulen/qdomyoszwift/ShellRuntime", "execAndGetOutput","(Ljava/lang/String;)V", commandString.object<jstring>());
#endif
QString heartRateBeltName =

View File

@@ -673,6 +673,7 @@ DISTFILES += \
$$PWD/android/src/MediaProjection.java \
$$PWD/android/src/NotificationUtils.java \
$$PWD/android/src/ScreenCaptureService.java \
$$PWD/android/src/ShellRuntime.java \
.clang-format \
AppxManifest.xml \
android/AndroidManifest.xml \