Skip to content

Commit

Permalink
Merge pull request #22 from CrazyDude1994/release-1.2
Browse files Browse the repository at this point in the history
Release 1.2
  • Loading branch information
Sergey Kartavtsev authored Apr 16, 2019
2 parents b0e011a + f89d59a commit 4ad69d8
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea
.DS_Store
/build
/captures
Expand Down
38 changes: 38 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId "crazydude.com.telemetry"
minSdkVersion 16
targetSdkVersion 28
versionCode 10
versionName "1.1"
versionCode 11
versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ class PreferenceManager(context: Context) {
fun setYoutubeShown() {
sharedPreferences.edit().putBoolean("youtube_shown", true).apply()
}

fun getBatteryUnits(): String {
return sharedPreferences.getString("battery_units", "mAh") ?: "mAh"
}

fun usePitotTube(): Boolean {
return sharedPreferences.getBoolean("use_pitot_tube", false)
}

fun showArtificialHorizonView(): Boolean {
return sharedPreferences.getBoolean("show_artificial_horizon", true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class BluetoothDataPoller(
})
}
protocol = FrSkySportProtocol(dataDecoder)
val buffer = ByteArray(1024)
while (!thread.isInterrupted && bluetoothSocket.isConnected) {
val data = bluetoothSocket.inputStream.read()
outputStream?.write(data)
protocol.process(data)
val size = bluetoothSocket.inputStream.read(buffer)
outputStream?.write(buffer, 0, size)
for (i in 0 until size) {
protocol.process(buffer[i].toInt())
}
}
} catch (e: IOException) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class DataDecoder(private val listener: Listener) : FrSkySportProtocol.Companion
listener.onPitchData(value)
// Log.d(TAG, "Decoded pitch $value")
}
FrSkySportProtocol.ASPEED -> {
listener.onAirSpeed(data.data * 1.852f)
}
else -> {}
}
}
Expand Down Expand Up @@ -180,5 +183,6 @@ class DataDecoder(private val listener: Listener) : FrSkySportProtocol.Companion
firstFlightMode: FlyMode,
secondFlightMode: FlyMode?
)
fun onAirSpeed(speed: Float)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FrSkySportProtocol(var dataListener: DataListener) {
const val GPS_STATE_SENSOR = 0x0410
const val PITCH_SENSOR = 0x0430
const val ROLL_SENSOR = 0x0440
const val AIRSPEED_SENSOR = 0x0A00

const val FUEL = 0
const val GPS = 1
Expand All @@ -60,6 +61,7 @@ class FrSkySportProtocol(var dataListener: DataListener) {
const val ROLL = 13
const val PITCH = 14
const val GALT = 15
const val ASPEED = 16

interface DataListener {
fun onNewData(data: TelemetryData)
Expand All @@ -68,7 +70,7 @@ class FrSkySportProtocol(var dataListener: DataListener) {
@Retention(AnnotationRetention.SOURCE)
@IntDef(
FUEL, GPS, VBAT, CELL_VOLTAGE, CURRENT, HEADING, RSSI, FLYMODE, GPS_STATE, VSPEED, ALTITUDE, GSPEED,
DISTANCE, ROLL, PITCH, GALT
DISTANCE, ROLL, PITCH, GALT, ASPEED
)
annotation class TelemetryType

Expand Down Expand Up @@ -258,6 +260,11 @@ class FrSkySportProtocol(var dataListener: DataListener) {
)
)
}
AIRSPEED_SENSOR -> {
dataListener.onNewData(
TelemetryData(ASPEED, rawData)
)
}
else -> {
//Log.d(TAG, "Unknown packet" + buffer.contentToString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class LogPlayer(val originalListener: DataDecoder.Listener) : DataDecoder.Listen
originalListener.onRollData(rollAngle)
}

override fun onAirSpeed(speed: Float) {
originalListener.onAirSpeed(speed)
}

override fun onPitchData(pitchAngle: Float) {
originalListener.onPitchData(pitchAngle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ class DataService : Service(), DataDecoder.Listener {
})
}

override fun onAirSpeed(speed: Float) {
runOnMainThread(Runnable {
dataListener?.onAirSpeed(speed)
})
}

override fun onRSSIData(rssi: Int) {
runOnMainThread(Runnable {
dataListener?.onRSSIData(rssi)
Expand Down
94 changes: 94 additions & 0 deletions app/src/main/java/crazydude/com/telemetry/ui/HorizonView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package crazydude.com.telemetry.ui

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View

class HorizonView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

private val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private var roll: Float = 0f
private var pitch: Float = 0f
private var size: Float = 0f
private var center: Float = 0f

private val leftLinePath = Path()
private val rightLinePath = Path()
private val circlePath = Path()

private val planeLinePaint = Paint(Paint.ANTI_ALIAS_FLAG)
.apply {
strokeWidth = 5f
style = Paint.Style.STROKE
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)

size = w.toFloat()
center = size / 2

leftLinePath.apply {
moveTo(center - 100f, center)
lineTo(center - 20f, center)
lineTo(center - 20f, center + 10f)
}
rightLinePath.apply {
moveTo(center + 100f, center)
lineTo(center + 20f, center)
lineTo(center + 20f, center + 10f)
}
circlePath.apply {
addCircle(center, center, center, Path.Direction.CW)
}
}

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)

canvas?.let {
it.save()
it.clipPath(circlePath, Region.Op.INTERSECT)
it.rotate(-roll, center, center)
paint.color = Color.parseColor("#5BCBD3")
it.drawRect(0f, 0f, size, center - pitch * 5, paint)
paint.color = Color.parseColor("#D38700")
it.drawRect(0f, center - pitch * 5, size, size, paint)
paint.strokeWidth = 4f
paint.color = Color.BLACK
for (i in 1..18) {
val lineLength = if (i.rem(2) == 0) 50 else 25
it.drawLine(
center - lineLength,
(center - pitch * 5) + i * 25,
center + lineLength,
(center - pitch * 5) + i * 25,
paint
)
it.drawLine(
center - lineLength,
(center - pitch * 5) - i * 25,
center + lineLength,
(center - pitch * 5) - i * 25,
paint
)
}
it.restore()
it.drawPath(leftLinePath, planeLinePaint)
it.drawPath(rightLinePath, planeLinePaint)
}
}

fun setRoll(roll: Float) {
this.roll = roll
invalidate()
}

fun setPitch(pitch: Float) {
this.pitch = pitch
invalidate()
}
}
Loading

0 comments on commit 4ad69d8

Please sign in to comment.