Skip to content

Commit b243407

Browse files
authored
feat: Boox Palma 2 Pro support (#575)
1 parent 6d84bf6 commit b243407

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.koreader.launcher.device.lights.OnyxC67Controller
2424
import org.koreader.launcher.device.lights.OnyxColorController
2525
import org.koreader.launcher.device.lights.OnyxSdkLightsController
2626
import org.koreader.launcher.device.lights.OnyxWarmthController
27+
import org.koreader.launcher.device.lights.OnyxPalma2ProController
2728
import org.koreader.launcher.device.lights.TolinoRootController
2829
import org.koreader.launcher.device.lights.TolinoNtxController
2930
import org.koreader.launcher.device.lights.TolinoNtxNoWarmthController
@@ -79,6 +80,7 @@ class TestActivity: AppCompatActivity() {
7980
lightsMap["Onyx Color"] = OnyxColorController()
8081
lightsMap["Onyx SDK (lights)"] = OnyxSdkLightsController()
8182
lightsMap["Onyx (warmth)"] = OnyxWarmthController()
83+
lightsMap["Onyx Palma2 Pro"] = OnyxPalma2ProController()
8284
lightsMap["Tolino Root"] = TolinoRootController()
8385
lightsMap["Tolino Ntx"] = TolinoNtxController()
8486
lightsMap["Tolino Ntx (no warmth)"] = TolinoNtxNoWarmthController()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ object DeviceInfo {
126126
ONYX_PAGE,
127127
ONYX_PALMA,
128128
ONYX_PALMA2,
129+
ONYX_PALMA2_PRO,
129130
ONYX_POKE2,
130131
ONYX_POKE3,
131132
ONYX_POKE4,
@@ -568,6 +569,10 @@ object DeviceInfo {
568569
BRAND == "onyx" && MODEL == "palma2"
569570
-> Id.ONYX_PALMA2
570571

572+
// Onyx Palma2 Pro (Palma2_Pro_C)
573+
BRAND == "onyx" && MODEL == "palma2_pro_c"
574+
-> Id.ONYX_PALMA2_PRO
575+
571576
// Onyx Poke 2
572577
MANUFACTURER == "onyx" && PRODUCT == "poke2"
573578
-> Id.ONYX_POKE2

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ object EPDFactory {
131131
DeviceInfo.Id.ONYX_PAGE,
132132
DeviceInfo.Id.ONYX_PALMA,
133133
DeviceInfo.Id.ONYX_PALMA2,
134+
DeviceInfo.Id.ONYX_PALMA2_PRO,
134135
DeviceInfo.Id.ONYX_POKE2,
135136
DeviceInfo.Id.ONYX_POKE3,
136137
DeviceInfo.Id.ONYX_POKE4,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ object LightsFactory {
118118
logController("TolinoB300Controller")
119119
TolinoB300Controller()
120120
}
121+
DeviceInfo.Id.ONYX_PALMA2_PRO,
122+
-> {
123+
logController("OnyxPalma2Pro")
124+
OnyxPalma2ProController()
125+
}
121126
else -> {
122127
logController("Generic")
123128
GenericController()
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package org.koreader.launcher.device.lights
2+
3+
import android.app.Activity
4+
import android.util.Log
5+
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
9+
10+
/* Controller for Onyx Boox Palma 2 Pro with brightness and warmth support.
11+
* Uses onyx_bl_br for brightness and onyx_bl_ct for warmth (color temperature).
12+
* Dynamically reads max values from sysfs.
13+
*/
14+
15+
class OnyxPalma2ProController : LightsInterface {
16+
companion object {
17+
private const val TAG = "Lights"
18+
private const val MIN = 0
19+
private const val DEFAULT_BRIGHTNESS_MAX = 255
20+
private const val DEFAULT_WARMTH_MAX = 32
21+
22+
private const val BRIGHTNESS_FILE = "/sys/class/backlight/onyx_bl_br/brightness"
23+
private const val BRIGHTNESS_MAX_FILE = "/sys/class/backlight/onyx_bl_br/max_brightness"
24+
private const val WARMTH_FILE = "/sys/class/backlight/onyx_bl_ct/brightness"
25+
private const val WARMTH_MAX_FILE = "/sys/class/backlight/onyx_bl_ct/max_brightness"
26+
}
27+
28+
private val cachedBrightnessMax: Int by lazy {
29+
try {
30+
val value = File(BRIGHTNESS_MAX_FILE).read()
31+
if (value > 0) value else DEFAULT_BRIGHTNESS_MAX
32+
} catch (e: Exception) {
33+
Log.w(TAG, "Failed to read max brightness, using default: $e")
34+
DEFAULT_BRIGHTNESS_MAX
35+
}
36+
}
37+
38+
private val cachedWarmthMax: Int by lazy {
39+
try {
40+
val value = File(WARMTH_MAX_FILE).read()
41+
if (value > 0) value else DEFAULT_WARMTH_MAX
42+
} catch (e: Exception) {
43+
Log.w(TAG, "Failed to read max warmth, using default: $e")
44+
DEFAULT_WARMTH_MAX
45+
}
46+
}
47+
48+
override fun getPlatform(): String {
49+
return "onyx-palma2pro"
50+
}
51+
52+
override fun hasFallback(): Boolean {
53+
return false
54+
}
55+
56+
override fun hasWarmth(): Boolean {
57+
return true
58+
}
59+
60+
override fun needsPermission(): Boolean {
61+
return false
62+
}
63+
64+
override fun getBrightness(activity: Activity): Int {
65+
return try {
66+
File(BRIGHTNESS_FILE).read()
67+
} catch (e: Exception) {
68+
Log.w(TAG, "Failed to read brightness: $e")
69+
0
70+
}
71+
}
72+
73+
override fun getWarmth(activity: Activity): Int {
74+
return try {
75+
File(WARMTH_FILE).read()
76+
} catch (e: Exception) {
77+
Log.w(TAG, "Failed to read warmth: $e")
78+
0
79+
}
80+
}
81+
82+
override fun setBrightness(activity: Activity, brightness: Int) {
83+
if (brightness !in MIN..cachedBrightnessMax) {
84+
Log.w(TAG, "brightness value out of range: $brightness (max: $cachedBrightnessMax)")
85+
return
86+
}
87+
Log.v(TAG, "Setting brightness to $brightness")
88+
try {
89+
File(BRIGHTNESS_FILE).write(brightness)
90+
} catch (e: Exception) {
91+
Log.e(TAG, "Failed to set brightness: $e")
92+
}
93+
}
94+
95+
override fun setWarmth(activity: Activity, warmth: Int) {
96+
if (warmth !in MIN..cachedWarmthMax) {
97+
Log.w(TAG, "warmth value out of range: $warmth (max: $cachedWarmthMax)")
98+
return
99+
}
100+
Log.v(TAG, "Setting warmth to $warmth")
101+
try {
102+
File(WARMTH_FILE).write(warmth)
103+
} catch (e: Exception) {
104+
Log.e(TAG, "Failed to set warmth: $e")
105+
}
106+
}
107+
108+
override fun getMinWarmth(): Int {
109+
return MIN
110+
}
111+
112+
override fun getMaxWarmth(): Int {
113+
return cachedWarmthMax
114+
}
115+
116+
override fun getMinBrightness(): Int {
117+
return MIN
118+
}
119+
120+
override fun getMaxBrightness(): Int {
121+
return cachedBrightnessMax
122+
}
123+
124+
override fun enableFrontlightSwitch(activity: Activity): Int {
125+
return 1
126+
}
127+
128+
override fun hasStandaloneWarmth(): Boolean {
129+
return true
130+
}
131+
}

0 commit comments

Comments
 (0)