commit fa41bfd3312402c44b026605b8d14903f559a853 Author: Maurizio Porrato Date: Sun Feb 17 09:52:17 2019 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..cf3b26c --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "eu.worn.apps.androvac" + minSdkVersion 19 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/eu/worn/apps/androvac/ExampleInstrumentedTest.java b/app/src/androidTest/java/eu/worn/apps/androvac/ExampleInstrumentedTest.java new file mode 100644 index 0000000..dc67796 --- /dev/null +++ b/app/src/androidTest/java/eu/worn/apps/androvac/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package eu.worn.apps.androvac; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("eu.worn.apps.androvac", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..45aa1bc --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/eu/worn/apps/androvac/AndroidIRBeamer.java b/app/src/main/java/eu/worn/apps/androvac/AndroidIRBeamer.java new file mode 100644 index 0000000..2352a6f --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/AndroidIRBeamer.java @@ -0,0 +1,20 @@ +package eu.worn.apps.androvac; + +import android.app.Activity; +import android.content.Context; +import android.hardware.ConsumerIrManager; + +public class AndroidIRBeamer implements IRBeamer { + private ConsumerIrManager cim; + + public AndroidIRBeamer(Activity act) { + Context ctx = act.getApplicationContext(); + cim = (ConsumerIrManager) ctx.getSystemService(ctx.CONSUMER_IR_SERVICE); + } + + public boolean isAvailable() { return cim.hasIrEmitter(); } + + public void transmit(int carrier, int[] pulses) { + cim.transmit(carrier, pulses); + } +} diff --git a/app/src/main/java/eu/worn/apps/androvac/DebugIRBeamer.java b/app/src/main/java/eu/worn/apps/androvac/DebugIRBeamer.java new file mode 100644 index 0000000..b4fe1bf --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/DebugIRBeamer.java @@ -0,0 +1,17 @@ +package eu.worn.apps.androvac; + +import android.app.Activity; +import android.widget.Toast; + +public class DebugIRBeamer implements IRBeamer { + private Activity act; + + public DebugIRBeamer(Activity act) { + this.act = act; + } + public boolean isAvailable() { return true; } + + public void transmit(int carrier, int[] pulses) { + Toast.makeText(act.getApplicationContext(), "Transmitting", Toast.LENGTH_LONG).show(); + } +} diff --git a/app/src/main/java/eu/worn/apps/androvac/EufyIRModulation.java b/app/src/main/java/eu/worn/apps/androvac/EufyIRModulation.java new file mode 100644 index 0000000..5beab88 --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/EufyIRModulation.java @@ -0,0 +1,41 @@ +package eu.worn.apps.androvac; + +import java.util.ArrayList; + +public class EufyIRModulation implements IRModulation { + // Pulse widths in microseconds + private static final int PREAMBLE[] = {3000, 3000}; + private static final int LOGIC[][] = {{400, 600}, {400, 1600}}; + private static final int TRAILER[] = {400, 20000}; + private static final int REPEATS = 2; + + public int getCarrierFrequency() { return 38000; } + + public int[] modulate(byte[] frame) { + int pulses = PREAMBLE.length + LOGIC[0].length*frame.length + TRAILER.length; + ArrayList fragment = new ArrayList<>(pulses); + + for (int p: PREAMBLE) + fragment.add(p); + for (byte f : frame) + for (int bit = 0; bit < 8; bit++) { + int bv = ((f & (0x80 >> bit)) != 0 ? 1 : 0); + for (int p: LOGIC[bv]) + fragment.add(p); + } + for (int p: TRAILER) + fragment.add(p); + + int fs = fragment.size(); + int res[] = new int[fs*(REPEATS+1)]; + int pos = 0; + + for (int e: fragment) { + for (int r = 0; r <= REPEATS; r++) + res[pos + fs * r] = e; + pos++; + } + + return res; + } +} diff --git a/app/src/main/java/eu/worn/apps/androvac/IRBeamer.java b/app/src/main/java/eu/worn/apps/androvac/IRBeamer.java new file mode 100644 index 0000000..417f72e --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/IRBeamer.java @@ -0,0 +1,6 @@ +package eu.worn.apps.androvac; + +public interface IRBeamer { + boolean isAvailable(); + void transmit(int carrier, int[] pulses); +} diff --git a/app/src/main/java/eu/worn/apps/androvac/IRModulation.java b/app/src/main/java/eu/worn/apps/androvac/IRModulation.java new file mode 100644 index 0000000..8ac969a --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/IRModulation.java @@ -0,0 +1,6 @@ +package eu.worn.apps.androvac; + +public interface IRModulation { + int getCarrierFrequency(); + int[] modulate(byte[] frame); +} diff --git a/app/src/main/java/eu/worn/apps/androvac/MainActivity.java b/app/src/main/java/eu/worn/apps/androvac/MainActivity.java new file mode 100644 index 0000000..bd76d9c --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/MainActivity.java @@ -0,0 +1,68 @@ +package eu.worn.apps.androvac; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.Switch; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + + private IRBeamer beamer; + private RoboVac11sRemote remote; + + private void beam(byte[] msg) { + beamer.transmit(remote.modulation.getCarrierFrequency(), remote.modulation.modulate(msg)); + } + + public void onClick(View v) { + byte[] msg; + + switch (v.getId()) { + case R.id.cleanAuto: msg = remote.cleanAuto(); break; + case R.id.cleanSpot: msg = remote.cleanSpot(); break; + case R.id.cleanEdge: msg = remote.cleanEdge(); break; + case R.id.cleanRoom: msg = remote.cleanRoom(); break; + case R.id.powerStandard: msg = remote.powerStandard(); break; + case R.id.powerMax: msg = remote.powerMax(); break; + case R.id.powerBoostIQ: msg = remote.powerBoostIQ(); break; + case R.id.moveForward: msg = remote.moveForward(); break; + case R.id.moveBackward: msg = remote.moveBackward(); break; + case R.id.moveCCW: msg = remote.moveCCW(); break; + case R.id.moveCW: msg = remote.moveCW(); break; + case R.id.returnBase: msg = remote.returnBase(); break; + case R.id.stop: msg = remote.stop(); break; + default: msg = new byte[0]; + } + if (msg.length > 0) + beam(msg); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + remote = new RoboVac11sRemote(); + + beamer = new AndroidIRBeamer(this); + if (!beamer.isAvailable()) { + Toast.makeText(this.getApplicationContext(), + "No IR beamer found: entering debug mode", + Toast.LENGTH_LONG).show(); + beamer = new DebugIRBeamer(this); + } + + findViewById(R.id.schedule).setEnabled( + ((Switch) findViewById(R.id.enableSchedule)).isChecked()); + + ((Switch) findViewById(R.id.enableSchedule)).setOnCheckedChangeListener( + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + findViewById(R.id.schedule).setEnabled(isChecked); + } + }); + } +} diff --git a/app/src/main/java/eu/worn/apps/androvac/RoboVac11sRemote.java b/app/src/main/java/eu/worn/apps/androvac/RoboVac11sRemote.java new file mode 100644 index 0000000..82c3f07 --- /dev/null +++ b/app/src/main/java/eu/worn/apps/androvac/RoboVac11sRemote.java @@ -0,0 +1,57 @@ +package eu.worn.apps.androvac; + +import java.util.Calendar; + +public class RoboVac11sRemote { + public IRModulation modulation = new EufyIRModulation(); + + private Calendar schedule = null; + + private byte[] buildMessage(byte command) { + byte msg[] = new byte[6]; + Calendar now = Calendar.getInstance(); + + msg[0] = (byte) 0x68; + msg[1] = command; + msg[2] = (byte) now.get(Calendar.HOUR_OF_DAY); + msg[3] = (byte) now.get(Calendar.MINUTE); + if (schedule != null) + msg[4] = (byte) (schedule.get(Calendar.HOUR_OF_DAY) * 4 + + schedule.get(Calendar.MINUTE) / 15); + else + msg[4] = (byte) 0xff; + msg[5] = (byte) (msg[0] + msg[1] + msg[2] + msg[3] + msg[4]); + + return msg; + } + + public RoboVac11sRemote() { + schedule = null; + } + + public void setSchedule(Calendar s) { + schedule = s; + } + + public Calendar getSchedule() { + return schedule; + } + + public byte[] cleanAuto() { return buildMessage((byte) 0x5d); } + public byte[] cleanSpot() { return buildMessage((byte) 0x8c); } + public byte[] cleanEdge() { return buildMessage((byte) 0x9c); } + public byte[] cleanRoom() { return buildMessage((byte) 0xad); } + + public byte[] powerStandard() { return buildMessage((byte) 0x1e); } + public byte[] powerMax() { return buildMessage((byte) 0x1c); } + public byte[] powerBoostIQ() { return buildMessage((byte) 0x1d); } + + public byte[] moveForward() { return buildMessage((byte) 0x2f); } + public byte[] moveBackward() { return buildMessage((byte) 0x7f); } + public byte[] moveCCW() { return buildMessage((byte) 0x3f); } + public byte[] moveCW() { return buildMessage((byte) 0x6f); } + public byte[] returnBase() { return buildMessage((byte) 0xef); } + + public byte[] stop() { return buildMessage((byte) 0x4f); } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e5cc126 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,225 @@ + + + + + +