Skip to content

Commit 80c0524

Browse files
committed
Fixes after test the code in the device
1 parent 5d2f903 commit 80c0524

File tree

5 files changed

+88
-26
lines changed

5 files changed

+88
-26
lines changed

app/src/main/java/org/koreader/launcher/TestActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import org.koreader.launcher.device.epd.RK3026EPDController
1717
import org.koreader.launcher.device.epd.RK3368EPDController
1818
import org.koreader.launcher.device.epd.TolinoEPDController
1919
import org.koreader.launcher.device.epd.NGL4EPDController
20-
import org.koreader.launcher.device.lights.OnyxBlController
2120
import org.koreader.launcher.device.lights.OnyxC67Controller
2221
import org.koreader.launcher.device.lights.OnyxColorController
2322
import org.koreader.launcher.device.lights.OnyxSdkLightsController
23+
import org.koreader.launcher.device.lights.OnyxSdk2LightsController
2424
import org.koreader.launcher.device.lights.OnyxWarmthController
2525
import org.koreader.launcher.device.lights.TolinoRootController
2626
import org.koreader.launcher.device.lights.TolinoNtxController
@@ -72,8 +72,8 @@ class TestActivity: AppCompatActivity() {
7272
lightsMap["Onyx C67"] = OnyxC67Controller()
7373
lightsMap["Onyx Color"] = OnyxColorController()
7474
lightsMap["Onyx SDK (lights)"] = OnyxSdkLightsController()
75+
lightsMap["Onyx SDK2 (lights)"] = OnyxSdk2LightsController()
7576
lightsMap["Onyx (warmth)"] = OnyxWarmthController()
76-
lightsMap["Onyx (bl)"] = OnyxBlController()
7777
lightsMap["Tolino Root"] = TolinoRootController()
7878
lightsMap["Tolino Ntx"] = TolinoNtxController()
7979
lightsMap["Tolino Ntx (no warmth)"] = TolinoNtxNoWarmthController()

app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt

+1
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ object DeviceInfo {
768768

769769
HAS_COLOR_SCREEN = when (EINK) {
770770
EinkDevice.NONE,
771+
EinkDevice.ONYX_NOTE_AIR3C,
771772
EinkDevice.ONYX_NOVA3_COLOR,
772773
EinkDevice.ONYX_TAB_ULTRA_C,
773774
EinkDevice.ONYX_NOVA_AIR_C -> true

app/src/main/java/org/koreader/launcher/device/LightsFactory.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ object LightsFactory {
6161
OnyxSdkLightsController()
6262
}
6363
DeviceInfo.LightsDevice.ONYX_NOTE_AIR3C -> {
64-
logController("Onyx/Bl")
65-
OnyxBlController()
64+
logController("Onyx/Sdk2")
65+
OnyxSdk2LightsController()
6666
}
6767
DeviceInfo.LightsDevice.ONYX_NOVA3_COLOR,
6868
DeviceInfo.LightsDevice.TAGUS_GEA -> {

app/src/main/java/org/koreader/launcher/device/lights/OnyxBlController.kt renamed to app/src/main/java/org/koreader/launcher/device/lights/OnyxSdk2LightsController.kt

+14-22
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@ package org.koreader.launcher.device.lights
33
import android.app.Activity
44
import android.util.Log
55
import org.koreader.launcher.device.LightsInterface
6-
import org.koreader.launcher.extensions.read
7-
import org.koreader.launcher.extensions.write
8-
import java.io.File
96

10-
class OnyxBlController : LightsInterface {
7+
class OnyxSdk2LightsController : LightsInterface {
118
companion object {
129
private const val TAG = "Lights"
13-
private const val MIN = 0
14-
private const val WHITE_FILE = "/sys/class/backlight/onyx_bl_br/brightness"
15-
private const val WARMTH_FILE = "/sys/class/backlight/onyx_bl_ct/brightness"
16-
private const val MAX_WHITE_FILE = "/sys/class/backlight/onyx_bl_br/max_brightness"
17-
private const val MAX_WARMTH_FILE = "/sys/class/backlight/onyx_bl_ct/max_brightness"
10+
private const val MIN_LIGHT_VALUE = 0
1811
}
1912

2013
override fun getPlatform(): String {
21-
return "onyx-bl"
14+
return "onyx-sdk-2-lights"
2215
}
2316

2417
override fun hasFallback(): Boolean {
@@ -34,53 +27,52 @@ class OnyxBlController : LightsInterface {
3427
}
3528

3629
override fun getBrightness(activity: Activity): Int {
37-
return File(WHITE_FILE).read()
30+
return OnyxSdkDeviceController.getLightValue(OnyxSdkDeviceController.Light.COLD)
3831
}
3932

4033
override fun getWarmth(activity: Activity): Int {
41-
return File(WARMTH_FILE).read()
34+
return OnyxSdkDeviceController.getLightValue(OnyxSdkDeviceController.Light.WARM)
4235
}
4336

4437
override fun setBrightness(activity: Activity, brightness: Int) {
45-
if (brightness < MIN || brightness > getMaxBrightness()) {
38+
if (brightness < getMinBrightness() || brightness > getMaxBrightness()) {
4639
Log.w(TAG, "brightness value of of range: $brightness")
4740
return
4841
}
4942
Log.v(TAG, "Setting brightness to $brightness")
50-
File(WHITE_FILE).write(brightness)
43+
OnyxSdkDeviceController.setLightValue(OnyxSdkDeviceController.Light.COLD, brightness)
5144
}
5245

5346
override fun setWarmth(activity: Activity, warmth: Int) {
54-
if (warmth < MIN || warmth > getMaxWarmth()) {
47+
if (warmth < getMinWarmth() || warmth > getMaxWarmth()) {
5548
Log.w(TAG, "warmth value of of range: $warmth")
5649
return
5750
}
58-
5951
Log.v(TAG, "Setting warmth to $warmth")
60-
File(WARMTH_FILE).write(warmth)
52+
OnyxSdkDeviceController.setLightValue(OnyxSdkDeviceController.Light.WARM, warmth)
6153
}
6254

6355
override fun getMinWarmth(): Int {
64-
return MIN
56+
return MIN_LIGHT_VALUE
6557
}
6658

6759
override fun getMaxWarmth(): Int {
68-
return File(MAX_WARMTH_FILE).read()
60+
return OnyxSdkDeviceController.getMaxLightValue(OnyxSdkDeviceController.Light.WARM)
6961
}
7062

7163
override fun getMinBrightness(): Int {
72-
return MIN
64+
return MIN_LIGHT_VALUE
7365
}
7466

7567
override fun getMaxBrightness(): Int {
76-
return File(MAX_WHITE_FILE).read()
68+
return OnyxSdkDeviceController.getMaxLightValue(OnyxSdkDeviceController.Light.COLD)
7769
}
7870

7971
override fun enableFrontlightSwitch(activity: Activity): Int {
8072
return 1
8173
}
8274

8375
override fun hasStandaloneWarmth(): Boolean {
84-
return true
76+
return false
8577
}
8678
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.koreader.launcher.device.lights
2+
3+
import android.util.Log
4+
import android.content.Context
5+
import java.lang.Class.forName
6+
import java.lang.reflect.Method
7+
8+
object OnyxSdkDeviceController {
9+
enum class Light(val code: Int) {
10+
COLD(7),
11+
WARM(6)
12+
}
13+
14+
private const val TAG = "lights"
15+
16+
private val flController: Class<*>? = try {
17+
forName("android.onyx.hardware.DeviceController")
18+
} catch (e: Exception) {
19+
Log.w(TAG, "$e")
20+
null
21+
}
22+
23+
private val getMaxLightValueMethod: Method? = try {
24+
flController!!.getMethod("getMaxLightValue", Integer.TYPE)
25+
} catch (e: Exception) {
26+
Log.w(TAG, "$e")
27+
null
28+
}
29+
30+
private val getLightValueMethod: Method? = try {
31+
flController!!.getMethod("getLightValue", Integer.TYPE)
32+
} catch (e: Exception) {
33+
Log.w(TAG, "$e")
34+
null
35+
}
36+
37+
private val setLightValueMethod: Method? = try {
38+
flController!!.getMethod("setLightValue", Integer.TYPE, Integer.TYPE)
39+
} catch (e: Exception) {
40+
Log.w(TAG, "$e")
41+
null
42+
}
43+
44+
fun getMaxLightValue(light: Light): Int {
45+
return try {
46+
getMaxLightValueMethod!!.invoke(flController!!, light.code) as Int
47+
} catch (e: Exception) {
48+
Log.e(TAG, "error getting the max light $light", e)
49+
0
50+
}
51+
}
52+
53+
fun getLightValue(light: Light): Int {
54+
return try {
55+
getLightValueMethod!!.invoke(flController!!, light.code) as Int
56+
} catch (e: Exception) {
57+
Log.e(TAG, "error getting the light $light", e)
58+
0
59+
}
60+
}
61+
62+
fun setLightValue(light: Light, value: Int) {
63+
try {
64+
setLightValueMethod!!.invoke(flController!!, light.code, value)
65+
} catch (e: Exception) {
66+
Log.e(TAG, "error setting the light $light to $value", e)
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)