Skip to content

Commit 8a74be4

Browse files
committed
Adding (hopefully) proper Shine 4 support, adding proper light controls for the B300 Tolinos based off of koreader/pull/520
1 parent ca2c339 commit 8a74be4

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.koreader.launcher.device.lights.OnyxWarmthController
2727
import org.koreader.launcher.device.lights.TolinoRootController
2828
import org.koreader.launcher.device.lights.TolinoNtxController
2929
import org.koreader.launcher.device.lights.TolinoNtxNoWarmthController
30+
import org.koreader.launcher.device.lights.TolinoB300Controller
3031
import org.koreader.launcher.device.lights.BoyueS62RootController
3132
import org.koreader.launcher.dialog.LightDialog
3233
import org.koreader.launcher.dialog.ToolTip
@@ -81,6 +82,7 @@ class TestActivity: AppCompatActivity() {
8182
lightsMap["Tolino Root"] = TolinoRootController()
8283
lightsMap["Tolino Ntx"] = TolinoNtxController()
8384
lightsMap["Tolino Ntx (no warmth)"] = TolinoNtxNoWarmthController()
85+
lightsMap["Tolino B300"] = TolinoB300Controller()
8486

8587
// Device ID
8688
binding.info.append("Manufacturer: ${DeviceInfo.MANUFACTURER}\n")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ object DeviceInfo {
614614
BRAND == STR_KOBO && MODEL == STR_TOLINO && DEVICE == STR_NTX && HARDWARE == "e60k00"
615615
-> Id.TOLINO_SHINE3
616616

617+
// Tolino Shine 4
618+
BRAND == STR_KOBO && MODEL == "tolino shine 4" && DEVICE == STR_TOLINO && HARDWARE == "sun8iw15p1"
619+
-> Id.TOLINO_SHINE4
620+
617621
// Tolino Vision 4 also has warmth lights, but with ntx_io file
618622
BRAND == STR_KOBO && MODEL == STR_TOLINO && DEVICE == STR_NTX && HARDWARE == "e60q50"
619623
-> Id.TOLINO_VISION4

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ object EPDFactory {
6969
DeviceInfo.Id.NOOK_GL4,
7070
DeviceInfo.Id.TOLINO_EPOS3,
7171
DeviceInfo.Id.TOLINO_VISION6,
72+
DeviceInfo.Id.TOLINO_SHINE4,
7273
-> {
7374
logController("NOOK_GL4")
7475
NGL4EPDController()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ object LightsFactory {
106106
logController("TolinoRoot")
107107
TolinoRootController()
108108
}
109+
DeviceInfo.Id.TOLINO_EPOS3,
110+
DeviceInfo.Id.TOLINO_VISION6,
111+
DeviceInfo.Id.TOLINO_SHINE4,
112+
-> {
113+
logController("TolinoB300Controller")
114+
TolinoB300Controller()
115+
}
109116
else -> {
110117
logController("Generic")
111118
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.provider.Settings
5+
import android.util.Log
6+
import org.koreader.launcher.device.Ioctl
7+
import org.koreader.launcher.device.LightsInterface
8+
9+
// Light and warmth controller for B300 Tolino devices (Epos 3, Vision 6, Shine 4)
10+
// Need testers for Shine 4, I'm operating under the assumption that this works.
11+
// Vision 6 has inverted warmth from personal testing.
12+
class TolinoB300Controller : Ioctl(), LightsInterface {
13+
14+
companion object {
15+
private const val TAG = "Lights"
16+
private const val BRIGHTNESS_MAX = 100
17+
private const val WARMTH_MAX = 10
18+
private const val MIN = 0
19+
}
20+
21+
override fun getPlatform(): String {
22+
return "tolino"
23+
}
24+
25+
override fun hasFallback(): Boolean {
26+
return false
27+
}
28+
29+
override fun hasWarmth(): Boolean {
30+
return true
31+
}
32+
33+
override fun needsPermission(): Boolean {
34+
return true
35+
}
36+
37+
override fun enableFrontlightSwitch(activity: Activity): Int {
38+
return 1
39+
}
40+
41+
override fun getBrightness(activity: Activity): Int {
42+
return try {
43+
Settings.System.getInt(activity.applicationContext.contentResolver, "screen_brightness")
44+
} catch (e: Exception) {
45+
Log.w(TAG, e.toString())
46+
0
47+
}
48+
}
49+
50+
override fun getWarmth(activity: Activity): Int {
51+
return try {
52+
Settings.System.getInt(
53+
activity.applicationContext.contentResolver,
54+
"screen_brightness_color"
55+
)
56+
} catch (e: Exception) {
57+
Log.w(TAG, e.toString())
58+
}
59+
}
60+
61+
override fun setBrightness(activity: Activity, brightness: Int) {
62+
if (brightness < MIN || brightness > BRIGHTNESS_MAX) {
63+
Log.w(TAG, "brightness value of of range: $brightness")
64+
return
65+
}
66+
Log.v(TAG, "Setting brightness to $brightness")
67+
try {
68+
Settings.System.putInt(
69+
activity.applicationContext.contentResolver,
70+
"screen_brightness",
71+
brightness
72+
)
73+
} catch (e: Exception) {
74+
Log.w(TAG, "$e")
75+
}
76+
}
77+
78+
override fun setWarmth(activity: Activity, warmth: Int) {
79+
if (warmth < MIN || warmth > WARMTH_MAX) {
80+
Log.w(TAG, "warmth value of of range: $warmth")
81+
return
82+
}
83+
Log.v(TAG, "Setting warmth to $warmth")
84+
try {
85+
Settings.System.putInt(
86+
activity.applicationContext.contentResolver,
87+
"screen_brightness_color",
88+
warmth
89+
)
90+
91+
// crappy toggle brightness to force warmth refresh
92+
val currentBrightness: Int =
93+
Settings.System.getInt(
94+
activity.applicationContext.contentResolver,
95+
"screen_brightness"
96+
)
97+
Settings.System.putInt(
98+
activity.applicationContext.contentResolver,
99+
"screen_brightness",
100+
currentBrightness + 1
101+
)
102+
Settings.System.putInt(
103+
activity.applicationContext.contentResolver,
104+
"screen_brightness",
105+
currentBrightness
106+
)
107+
} catch (e: Exception) {
108+
Log.w(TAG, "$e")
109+
}
110+
}
111+
112+
override fun getMinWarmth(): Int {
113+
return MIN
114+
}
115+
116+
override fun getMaxWarmth(): Int {
117+
return WARMTH_MAX
118+
}
119+
120+
override fun getMinBrightness(): Int {
121+
return MIN
122+
}
123+
124+
override fun getMaxBrightness(): Int {
125+
return BRIGHTNESS_MAX
126+
}
127+
128+
override fun hasStandaloneWarmth(): Boolean {
129+
return false
130+
}
131+
}

0 commit comments

Comments
 (0)