Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/org/koreader/launcher/TestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.koreader.launcher.device.lights.OnyxWarmthController
import org.koreader.launcher.device.lights.TolinoRootController
import org.koreader.launcher.device.lights.TolinoNtxController
import org.koreader.launcher.device.lights.TolinoNtxNoWarmthController
import org.koreader.launcher.device.lights.TolinoB300Controller
import org.koreader.launcher.device.lights.BoyueS62RootController
import org.koreader.launcher.dialog.LightDialog
import org.koreader.launcher.dialog.ToolTip
Expand Down Expand Up @@ -81,6 +82,7 @@ class TestActivity: AppCompatActivity() {
lightsMap["Tolino Root"] = TolinoRootController()
lightsMap["Tolino Ntx"] = TolinoNtxController()
lightsMap["Tolino Ntx (no warmth)"] = TolinoNtxNoWarmthController()
lightsMap["Tolino B300"] = TolinoB300Controller()

// Device ID
binding.info.append("Manufacturer: ${DeviceInfo.MANUFACTURER}\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ object LightsFactory {
logController("TolinoRoot")
TolinoRootController()
}
DeviceInfo.Id.TOLINO_VISION6,
-> {
logController("TolinoB300Controller")
TolinoB300Controller()
}
else -> {
logController("Generic")
GenericController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package org.koreader.launcher.device.lights

import android.app.Activity
import android.provider.Settings
import android.util.Log
import org.koreader.launcher.device.Ioctl
import org.koreader.launcher.device.LightsInterface

// Light and warmth controller for B300 Tolino devices (Epos 3, Vision 6, Shine 4)
// Need testers for Shine 4 and Epos 3, Vision 6 tested personally.
// Vision 6 has inverted warmth.
class TolinoB300Controller : Ioctl(), LightsInterface {

companion object {
private const val TAG = "Lights"
private const val BRIGHTNESS_MAX = 100
private const val WARMTH_MAX = 10
private const val MIN = 0
private const val SCREEN_BRIGHTNESS = "screen_brightness"
private const val SCREEN_BRIGHTNESS_COLOR = "screen_brightness_color"
}

override fun getPlatform(): String {
return "tolino"
}

override fun hasFallback(): Boolean {
return false
}

override fun hasWarmth(): Boolean {
return true
}

override fun needsPermission(): Boolean {
return true
}

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

override fun getBrightness(activity: Activity): Int {
return try {
Settings.System.getInt(activity.applicationContext.contentResolver, SCREEN_BRIGHTNESS)
} catch (e: Exception) {
Log.w(TAG, e.toString())
0
}
}

override fun getWarmth(activity: Activity): Int {
return try {
Settings.System.getInt(
activity.applicationContext.contentResolver,
SCREEN_BRIGHTNESS_COLOR
)
} catch (e: Exception) {
Log.w(TAG, e.toString())
}
}

override fun setBrightness(activity: Activity, brightness: Int) {
if (brightness < MIN || brightness > BRIGHTNESS_MAX) {
Log.w(TAG, "brightness value of of range: $brightness")
return
}
Log.v(TAG, "Setting brightness to $brightness")
try {
Settings.System.putInt(
activity.applicationContext.contentResolver,
SCREEN_BRIGHTNESS,
brightness
)
} catch (e: Exception) {
Log.w(TAG, "$e")
}
}

override fun setWarmth(activity: Activity, warmth: Int) {
if (warmth < MIN || warmth > WARMTH_MAX) {
Log.w(TAG, "warmth value of of range: $warmth")
return
}
Log.v(TAG, "Setting warmth to $warmth")
try {
Settings.System.putInt(
activity.applicationContext.contentResolver,
SCREEN_BRIGHTNESS_COLOR,
warmth
)

// crappy toggle brightness to force warmth refresh
val currentBrightness: Int = getBrightness(activity)
Settings.System.putInt(
activity.applicationContext.contentResolver,
SCREEN_BRIGHTNESS,
currentBrightness + 1
)
Settings.System.putInt(
activity.applicationContext.contentResolver,
SCREEN_BRIGHTNESS,
currentBrightness
)
} catch (e: Exception) {
Log.w(TAG, "$e")
}
}

override fun getMinWarmth(): Int {
return MIN
}

override fun getMaxWarmth(): Int {
return WARMTH_MAX
}

override fun getMinBrightness(): Int {
return MIN
}

override fun getMaxBrightness(): Int {
return BRIGHTNESS_MAX
}

override fun hasStandaloneWarmth(): Boolean {
return false
}
}