Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update Betaflight Configurator to 10.6.0 #5

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,70 @@
# Betaflight - Configurator for Android
[![GPL-3.0 license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://github.com/cmengler/betaflight-configurator-android/blob/master/LICENSE) ![Built with Cordova](https://img.shields.io/badge/built_with-Cordova-4CC2E4.svg) ![Betaflight Configurator Version](https://img.shields.io/badge/configurator-10.3.0-yellow.svg) ![Status](https://img.shields.io/badge/status-development-red.svg)

[![GPL-3.0 license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://github.com/cmengler/betaflight-configurator-android/blob/master/LICENSE) ![Built with Cordova](https://img.shields.io/badge/built_with-Cordova-4CC2E4.svg) ![Betaflight Configurator Version](https://img.shields.io/badge/configurator-10.6.0-yellow.svg) ![Status](https://img.shields.io/badge/status-development-red.svg)

### This project uses Apache Cordova to build a version of the Betaflight Configurator to run on Android devices with USB On-The-Go (OTG) capabilities.
**This project uses Apache Cordova to build a version of the Betaflight Configurator to run on Android devices with USB On-The-Go (OTG) capabilities.**

This Android version is only suitable for large device screens such as tablets in landscape mode.

This is a work-in-progress -- please be aware that functionality of the desktop Betaflight Configurator may not work as intended in this version.

## Prerequisites

* [Android SDK](https://developer.android.com/)
* [Node.js](https://nodejs.org/)
* [Node.js](https://nodejs.org/) v10.x
* JDK v1.8.0
* Gradle v3.5.1

## Build

Refer to [build tips](README_build_tips.md) for additional help with the build process.

### 1. Prepare Betaflight Configurator

```bash
git submodule update --init
cd betaflight-configurator
yarn install
yarn gulp dist
```

### 2. Build Android APK

```bash
npm install
./node_modules/gulp/bin/gulp.js www
cordova prepare
cordova build android --debug
./node_modules/cordova/bin/cordova platform add android
./node_modules/cordova/bin/cordova run
```
This will generate the following Android APK file platforms/android/build/outputs/apk/armv7/debug/android-armv7-debug.apk

This will generate a number of APK files in the directory `platforms/android/app/build/outputs/apk/`

## Debugging

1. Connect the device via USB to your development machine.
2. Open Chrome -> Developer Tools (F12) -> More tools -> Remove Devices.
3. Under the development device, click the Inspect button on the WebView. Console logs will be visible in this session.

### ADB

Android Debug Bridge (adb) is a command-line tool that lets you communicate with an Android device. It's particularly useful for quickly uploading and installing APK's to the device. `adb` is included in the Android SDK [platform-tools](https://developer.android.com/studio/releases/platform-tools) package.

```bash
adb install -r platforms/android/build/outputs/apk/armv7/debug/android-armv7-debug.apk
adb install -r platforms/android/app/build/outputs/apk/armv7/debug/app-armv7-debug.apk
```

## Notes

* `_locales` directory is renamed to `i18n` due to an Android [issue](https://issues.apache.org/jira/browse/CB-8245) with directories starting with underscores
* TCP support `tcp://[IP]:[PORT]` has not been **tested**

## Known issues

* CLI output doesn't show all data when "dump" is requested
* Firmware tab intentionally hidden

## Roadmap

* Propose changes to [Betaflight Configurator](https://github.com/betaflight/betaflight-configurator) HTML/CSS to be responsive for smaller screens
* Revise serial support (e.g. create chrome.serial plugin for Cordova) to remove necessity to override [Betaflight Configurator](https://github.com/betaflight/betaflight-configurator) core JavaScript files in `merges`
* iOS support using WiFi
* iOS support using WiFi
17 changes: 17 additions & 0 deletions README_build_tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Build Tips

## OpenJDK

```bash
sudo apt install openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
```

## Gradle

```bash
wget https://downloads.gradle-dn.com/distributions/gradle-3.5.1-bin.zip
unzip gradle-3.5.1-bin.zip
export GRADLE_HOME=/path/to/gradle-3.5.1/bin
export PATH=$PATH:$GRADLE_HOME
```
2 changes: 1 addition & 1 deletion betaflight-configurator
5 changes: 3 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="tech.betaflight.android" version="10.3.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="tech.betaflight.android" version="10.6.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Betaflight - Configurator</name>
<description>Crossplatform configuration tool for Betaflight flight control system</description>
<author email="[email protected]" href="https://betaflight.tech">Betaflight Squad</author>
Expand Down Expand Up @@ -37,6 +37,7 @@
<splash density="land-xhdpi" src="res/android/screen/drawable-land-xhdpi/screen.png" />
<splash density="land-xxhdpi" src="res/android/screen/drawable-land-xxhdpi/screen.png" />
<splash density="land-xxxhdpi" src="res/android/screen/drawable-land-xxxhdpi/screen.png" />
<preference name="android-minSdkVersion" value="19" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<preference name="StatusBarStyle" value="lightcontent" />
Expand All @@ -59,5 +60,5 @@
<plugin name="cordova-plugin-chrome-apps-runtime" spec="^2.0.0" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-chrome-apps-sockets-tcp" spec="https://github.com/KoenLav/cordova-plugin-chrome-apps-sockets-tcp.git" />
<engine name="android" spec="^6.4.0" />
<engine name="android" spec="^8.1.0" />
</widget>
40 changes: 12 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,32 @@

const gulp = require('gulp');
const del = require('del');
const install = require('gulp-install');
const replace = require('gulp-replace');
const fs = require('fs');

const WWW_DIR = './www/';

gulp.task('clean-www', clean_www);

var wwwBuild = gulp.series(clean_www, www_src, www_locale, www_libraries, www_resources, www_replace);
var wwwBuild = gulp.series(clean_www, www_dist, www_locale, www_replace);
gulp.task('www', wwwBuild);

function www_src() {
function www_dist() {
var wwwSources = [
'./betaflight-configurator/src/**/*',
'!./betaflight-configurator/src/css/dropdown-lists/LICENSE',
'!./betaflight-configurator/src/css/font-awesome/css/font-awesome.css',
'!./betaflight-configurator/src/css/opensans_webfontkit/*.{txt,html}',
'!./betaflight-configurator/src/support/**'
'./betaflight-configurator/dist/**/*',
'!./betaflight-configurator/dist/css/dropdown-lists/LICENSE',
'!./betaflight-configurator/dist/css/font-awesome/css/font-awesome.css',
'!./betaflight-configurator/dist/css/opensans_webfontkit/*.{txt,html}',
];

return gulp.src(wwwSources, { base: 'betaflight-configurator/src' })
.pipe(gulp.src('betaflight-configurator/manifest.json', { passthrougth: true }))
.pipe(gulp.src('betaflight-configurator/package.json', { passthrougth: true }))
return gulp.src(wwwSources, { base: 'betaflight-configurator/dist' })
.pipe(gulp.src('betaflight-configurator/changelog.html', { passthrougth: true }))
.pipe(gulp.dest(WWW_DIR))
.pipe(install({
npm: '--production --ignore-scripts'
}));
.pipe(gulp.dest(WWW_DIR));
}

function www_locale() {
return gulp.src('betaflight-configurator/locales/**/*', { base: 'betaflight-configurator/locales'})
.pipe(gulp.dest(WWW_DIR + 'i18n'));
}

function www_libraries() {
return gulp.src('betaflight-configurator/libraries/**/*', { base: 'betaflight-configurator/libraries'})
.pipe(gulp.dest(WWW_DIR + 'js/libraries'));
}

function www_resources() {
return gulp.src('betaflight-configurator/resources/**/*', { base: 'betaflight-configurator/resources'})
.pipe(gulp.dest(WWW_DIR + 'resources'));
function www_locale(cb) {
fs.renameSync(WWW_DIR + '_locales', WWW_DIR + 'i18n');
cb();
}

function www_replace() {
Expand Down
8 changes: 7 additions & 1 deletion merges/android/js/Beepers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ var Beepers = function (config, supportedConditions) {
);
}

if (semver.gte(config.apiVersion, "1.39.0")) {
beepers.push(
{bit: 22, name: 'RC_SMOOTHING_INIT_FAIL', visible: true}
);
}

if (supportedConditions) {
self._beepers = [];
beepers.forEach(function (beeper) {
Expand Down Expand Up @@ -81,7 +87,7 @@ Beepers.prototype.generateElements = function (template, destination) {
destination.append(element);

var input_e = $(element).find('input');
var label_e = $(element).find('label');
var label_e = $(element).find('div');
var span_e = $(element).find('span');

input_e.attr('id', 'beeper-' + i);
Expand Down
51 changes: 51 additions & 0 deletions merges/android/js/ConfigStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

// idea here is to abstract around the use of chrome.storage.local as it functions differently from "localStorage" and IndexedDB
// localStorage deals with strings, not objects, so the objects have been serialized.
var ConfigStorage = {
// key can be one string, or array of strings
get: function(key, callback) {
if (GUI.isChromeApp()) {
chrome.storage.local.get(key,callback);
} else {
//console.log('Abstraction.get',key);
if (Array.isArray(key)) {
var obj = {};
key.forEach(function (element) {
try {
obj = $.extend(obj, JSON.parse(window.localStorage.getItem(element)));
} catch (e) {
// is okay
}
});
callback(obj);
} else {
var keyValue = window.localStorage.getItem(key);
if (keyValue) {
var obj = {};
try {
obj = JSON.parse(keyValue);
} catch (e) {
// It's fine if we fail that parse
}
callback(obj);
} else {
callback({});
}
}
}
},
// set takes an object like {'userLanguageSelect':'DEFAULT'}
set: function(input) {
if (GUI.isChromeApp()) {
chrome.storage.local.set(input);
} else {
//console.log('Abstraction.set',input);
Object.keys(input).forEach(function (element) {
var tmpObj = {};
tmpObj[element] = input[element];
window.localStorage.setItem(element, JSON.stringify(tmpObj));
});
}
}
}
Loading