Skip to content

Commit

Permalink
Add frontlight support for Onyx C67 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsurban authored Apr 17, 2021
1 parent 56c954d commit bd7a8f3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ object DeviceInfo {
enum class LightsDevice {
NONE,
TOLINO_EPOS,
ONYX_NOVA2
ONYX_NOVA2,
ONYX_C67
}

enum class BugDevice {
Expand Down Expand Up @@ -163,6 +164,7 @@ object DeviceInfo {
ONYX_C67 = (MANUFACTURER.contentEquals("onyx")
&& (PRODUCT.startsWith("c67") || MODEL.contentEquals("rk30sdk"))
&& DEVICE.startsWith("c67"))
lightsMap[LightsDevice.ONYX_C67] = ONYX_C67
deviceMap[EinkDevice.ONYX_C67] = ONYX_C67

// Energy Sistem eReaders. Tested on Energy Ereader Pro 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.koreader.launcher.device
import org.koreader.launcher.Logger
import org.koreader.launcher.device.lights.GenericController
import org.koreader.launcher.device.lights.OnyxWarmthController
import org.koreader.launcher.device.lights.OnyxC67Controller
import org.koreader.launcher.device.lights.TolinoWarmthController
import org.koreader.launcher.interfaces.LightInterface
import java.util.*
Expand All @@ -19,6 +20,10 @@ object LightsFactory {
logController("ONYX_NOVA2")
OnyxWarmthController()
}
DeviceInfo.LightsDevice.ONYX_C67 -> {
logController("ONYX_C67")
OnyxC67Controller()
}
else -> {
logController("Generic")
GenericController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.koreader.launcher.device.lights

import android.app.Activity
import android.util.Log
import org.koreader.launcher.Logger
import org.koreader.launcher.interfaces.LightInterface
import java.io.File

class OnyxC67Controller : LightInterface {
companion object {
private const val TAG = "lights"
private const val BRIGHTNESS_MAX = 255
private const val BRIGHTNESS_MIN = 0
private const val BRIGHTNESS_FILE = "/sys/class/backlight/rk28_bl/brightness"
}

override fun hasFallback(): Boolean {
return true
}

override fun hasWarmth(): Boolean {
return false
}

override fun needsPermission(): Boolean {
return false
}

override fun enableFrontlightSwitch(activity: Activity): Int {
return 1
}

override fun getBrightness(activity: Activity): Int {
val brightnessFile = File(BRIGHTNESS_FILE)
return try {
// .replace("\n", "") is needed, since it's automatically appended
// without it exception is thrown
// java.lang.NumberFormatException: For input string: "125\n"
return brightnessFile.readText().replace("\n", "").toInt()
} catch (e: Exception) {
Logger.w(TAG, Log.getStackTraceString(e))
0
}
}

override fun getWarmth(activity: Activity): Int {
Logger.w(TAG, "getWarmth: not implemented")
return 0
}


override fun setBrightness(activity: Activity, brightness: Int) {
if (brightness < BRIGHTNESS_MIN || brightness > BRIGHTNESS_MAX) {
Logger.w(TAG, "brightness value of of range: $brightness")
return
}
Logger.v(TAG, "Setting brightness to $brightness")
val brightnessFile = File(BRIGHTNESS_FILE)
try {
brightnessFile.writeText(brightness.toString())
} catch (e: Exception) {
Logger.w(TAG, "$e")
}
}

override fun setWarmth(activity: Activity, warmth: Int) {
Logger.w(TAG, "ignoring setWarmth: not implemented")
}

override fun getMinWarmth(): Int {
return 0
}
override fun getMaxWarmth(): Int {
return 0
}
override fun getMinBrightness(): Int {
return BRIGHTNESS_MIN
}
override fun getMaxBrightness(): Int {
return BRIGHTNESS_MAX
}
}

0 comments on commit bd7a8f3

Please sign in to comment.