Skip to content

Commit

Permalink
Tolino Page 2 support (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed Jan 3, 2024
1 parent b295579 commit 5c4670c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
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 @@ -22,6 +22,7 @@ import org.koreader.launcher.device.lights.OnyxSdkLightsController
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.BoyueS62RootController
import org.koreader.launcher.dialog.LightDialog

Expand Down Expand Up @@ -71,6 +72,7 @@ class TestActivity: AppCompatActivity() {
lightsMap["Onyx (warmth)"] = OnyxWarmthController()
lightsMap["Tolino Root"] = TolinoRootController()
lightsMap["Tolino Ntx"] = TolinoNtxController()
lightsMap["Tolino Ntx (no warmth)"] = TolinoNtxNoWarmthController()

// Device ID
binding.info.append("Manufacturer: ${DeviceInfo.MANUFACTURER}\n")
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ object DeviceInfo {
RIDI_PAPER_3,
TAGUS_GEA,
TOLINO_EPOS,
TOLINO_PAGE2,
TOLINO_SHINE3,
TOLINO_VISION4,
TOLINO_VISION5
Expand Down Expand Up @@ -230,6 +231,7 @@ object DeviceInfo {
private val SONY_RP1: Boolean
private val TAGUS_GEA: Boolean
private val TOLINO_EPOS: Boolean
private val TOLINO_PAGE2: Boolean
private val TOLINO_SHINE3: Boolean
private val TOLINO_VISION4: Boolean
private val TOLINO_VISION5: Boolean
Expand Down Expand Up @@ -540,8 +542,15 @@ object DeviceInfo {
&& DEVICE.contentEquals("ntx_6sl")
&& !HARDWARE.contentEquals("e60k00")
&& !HARDWARE.contentEquals("e60q50")
&& !HARDWARE.contentEquals("e60qv0")
&& !HARDWARE.contentEquals("e70k00")

// Tolino Page 2 has no warmth lights
TOLINO_PAGE2 = BRAND.contentEquals("rakutenkobo")
&& MODEL.contentEquals("tolino")
&& DEVICE.contentEquals("ntx_6sl")
&& HARDWARE.contentEquals("e60qv0")

// Tolino Shine 3 also has warmth lights, but with ntx_io file
TOLINO_SHINE3 = BRAND.contentEquals("rakutenkobo")
&& MODEL.contentEquals("tolino")
Expand Down Expand Up @@ -698,6 +707,7 @@ object DeviceInfo {
lightsMap[LightsDevice.RIDI_PAPER_3] = RIDI_PAPER_3
lightsMap[LightsDevice.TAGUS_GEA] = TAGUS_GEA
lightsMap[LightsDevice.TOLINO_EPOS] = TOLINO_EPOS
lightsMap[LightsDevice.TOLINO_PAGE2] = TOLINO_PAGE2
lightsMap[LightsDevice.TOLINO_SHINE3] = TOLINO_SHINE3
lightsMap[LightsDevice.TOLINO_VISION4] = TOLINO_VISION4
lightsMap[LightsDevice.TOLINO_VISION5] = TOLINO_VISION5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ object LightsFactory {
logController("TolinoNTX")
TolinoNtxController()
}
DeviceInfo.LightsDevice.TOLINO_PAGE2 -> {
logController("TolinoNTXNoWarmth")
TolinoNtxNoWarmthController()
}
DeviceInfo.LightsDevice.ONYX_DARWIN7,
DeviceInfo.LightsDevice.ONYX_EDISON,
DeviceInfo.LightsDevice.ONYX_FAUST3,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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

/* Special controller for Tolino Page 2
*
* Same as `./TolinoNtxController.kt` but without warmth support.
*/

class TolinoNtxNoWarmthController : Ioctl(), LightsInterface {

companion object {
private const val TAG = "Lights"
private const val BRIGHTNESS_MAX = 255
private const val MIN = 0
private const val NTX_IO_FILE = "/dev/ntx_io"
}

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

override fun hasFallback(): Boolean {
return false
}

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 {
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 {
Log.w(TAG, "getWarmth: not implemented")
return 0
}

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) {
Log.w(TAG, "ignoring setWarmth: not implemented")
}

override fun getMinWarmth(): Int {
return 0
}

override fun getMaxWarmth(): Int {
return 0
}

override fun getMinBrightness(): Int {
return MIN
}

override fun getMaxBrightness(): Int {
return BRIGHTNESS_MAX
}
}

0 comments on commit 5c4670c

Please sign in to comment.