Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Backlight support for Onyx Nova 3 Color #375

Closed
ilyats opened this issue Jul 7, 2022 · 1 comment
Closed

[PATCH] Backlight support for Onyx Nova 3 Color #375

ilyats opened this issue Jul 7, 2022 · 1 comment

Comments

@ilyats
Copy link

ilyats commented Jul 7, 2022

diff --git a/app/src/main/java/org/koreader/launcher/TestActivity.kt b/app/src/main/java/org/koreader/launcher/TestActivity.kt
index 736b823..02e1b0e 100644
--- a/app/src/main/java/org/koreader/launcher/TestActivity.kt
+++ b/app/src/main/java/org/koreader/launcher/TestActivity.kt
@@ -18,6 +18,7 @@ import org.koreader.launcher.device.epd.RK3368EPDController
 import org.koreader.launcher.device.epd.TolinoEPDController
 import org.koreader.launcher.device.lights.OnyxC67Controller
 import org.koreader.launcher.device.lights.OnyxWarmthController
+import org.koreader.launcher.device.lights.OnyxNova3ColorController
 import org.koreader.launcher.device.lights.TolinoWarmthController
 import org.koreader.launcher.dialog.LightDialog
 
@@ -63,6 +64,7 @@ class TestActivity: AppCompatActivity() {
         lightsMap["Tolino (warmth)"] = TolinoWarmthController()
         lightsMap["Onyx (warmth)"] = OnyxWarmthController()
         lightsMap["Onyx C67"] = OnyxC67Controller()
+        lightsMap["Onyx Nova3 Color"] = OnyxNova3ColorController()
 
         // Device ID
         binding.info.append("Manufacturer: ${DeviceInfo.MANUFACTURER}\n")
diff --git a/app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt b/app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt
index a94f981..2055fd2 100644
--- a/app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt
+++ b/app/src/main/java/org/koreader/launcher/device/DeviceInfo.kt
@@ -80,6 +80,7 @@ object DeviceInfo {
         ONYX_NOTE_PRO,
         ONYX_NOVA2,
         ONYX_NOVA3,
+	ONYX_NOVA3_COLOR,
         ONYX_NOVA_AIR,
         ONYX_KON_TIKI2,
         ONYX_POKE3,
@@ -430,6 +431,7 @@ object DeviceInfo {
         lightsMap[LightsDevice.ONYX_NOVA_AIR] = ONYX_NOVA_AIR
         lightsMap[LightsDevice.ONYX_POKE_PRO] = ONYX_POKE_PRO
         lightsMap[LightsDevice.TOLINO_EPOS] = TOLINO_EPOS
+        lightsMap[LightsDevice.ONYX_NOVA3_COLOR] = ONYX_NOVA3_COLOR
 
         lightsMap.keys.iterator().run {
             while (this.hasNext()) {
diff --git a/app/src/main/java/org/koreader/launcher/device/LightsFactory.kt b/app/src/main/java/org/koreader/launcher/device/LightsFactory.kt
index 6bfa9fb..f7b2067 100644
--- a/app/src/main/java/org/koreader/launcher/device/LightsFactory.kt
+++ b/app/src/main/java/org/koreader/launcher/device/LightsFactory.kt
@@ -32,6 +32,10 @@ object LightsFactory {
                     logController("ONYX C67")
                     OnyxC67Controller()
                 }
+		DeviceInfo.LightsDevice.ONYX_NOVA3_COLOR -> {
+			logController("Onyx/Nova3Color")
+			OnyxNova3ColorController()
+		}
                 else -> {
                     logController("Generic")
                     GenericController()
diff --git a/app/src/main/java/org/koreader/launcher/device/lights/OnyxNova3ColorController.kt b/app/src/main/java/org/koreader/launcher/device/lights/OnyxNova3ColorController.kt
new file mode 100644
index 0000000..f9e7c27
--- /dev/null
+++ b/app/src/main/java/org/koreader/launcher/device/lights/OnyxNova3ColorController.kt
@@ -0,0 +1,91 @@
+package org.koreader.launcher.device.lights
+
+import android.app.Activity
+import android.util.Log
+import org.koreader.launcher.device.LightsInterface
+import java.io.File
+
+// Unlike other recent (as of 2022) devices by Boox, Nova 3 Color has monochrome backlight. 
+class OnyxNova3ColorController : LightsInterface {
+    companion object {
+        private const val TAG = "Lights"
+        private const val BRIGHTNESS_MAX = 255
+        private const val BRIGHTNESS_MIN = 0
+        private const val BRIGHTNESS_FILE = "/sys/class/backlight/pwm-backlight.0/brightness"
+        private const val ACTUAL_BRIGHTNESS_FILE = "/sys/class/backlight/pwm-backlight.0/actual_brightness"
+    }
+
+    override fun getPlatform(): String {
+        return "Onyx/Nova3Color"
+    }
+
+    override fun hasFallback(): Boolean {
+        return false
+    }
+
+    override fun hasWarmth(): Boolean {
+        return false	
+    }
+
+    override fun needsPermission(): Boolean {
+        return false
+    }
+
+    override fun getBrightness(activity: Activity): Int {
+        val brightnessFile = File(ACTUAL_BRIGHTNESS_FILE)
+        return try {
+            // .replace("\n", "") is needed, since it's automatically appended
+            // without it exception is thrown
+            // java.lang.NumberFormatException: For input string: "125\n"
+            return brightnessFile.readText().replace("\n", "").toInt()
+        } catch (e: Exception) {
+            Log.w(TAG, Log.getStackTraceString(e))
+            0
+        }
+    }
+
+    override fun setBrightness(activity: Activity, brightness: Int) {
+        if (brightness < BRIGHTNESS_MIN || brightness > BRIGHTNESS_MAX) {
+            Log.w(TAG, "brightness value of of range: $brightness")
+            return
+        }
+        Log.v(TAG, "Setting brightness to $brightness")
+        val brightnessFile = File(BRIGHTNESS_FILE)
+        try {
+            brightnessFile.writeText(brightness.toString())
+        } catch (e: Exception) {
+            Log.w(TAG, "$e")
+        }
+    }
+
+
+
+
+    override fun getMinBrightness(): Int {
+        return BRIGHTNESS_MAX
+    }
+
+    override fun getMaxBrightness(): Int {
+        return BRIGHTNESS_MAX
+    }
+
+    override fun getMinWarmth(): Int {
+        return 0
+    }
+    override fun getMaxWarmth(): Int {
+        return 0
+    }
+
+    override fun getWarmth(activity: Activity): Int {
+        Log.w(TAG, "getWarmth: not implemented")
+        return 0
+    }
+
+    override fun setWarmth(activity: Activity, warmth: Int) {
+        Log.w(TAG, "ignoring setWarmth: not implemented")
+    }
+
+    override fun enableFrontlightSwitch(activity: Activity): Int {
+        return 1
+    }
+}
diff --git a/jni/luajit/luajit b/jni/luajit/luajit
--- a/jni/luajit/luajit
+++ b/jni/luajit/luajit
@@ -1 +1 @@
-Subproject commit 20aea93915a0d31138cb00e17cc15eb849e3b806
+Subproject commit 20aea93915a0d31138cb00e17cc15eb849e3b806-dirty
@pazos pazos closed this as completed Jul 7, 2022
@pazos
Copy link
Member

pazos commented Jul 7, 2022

thanks for the patch but I cannot read it. Please provide feedback on the proper ticket (I'm waiting for you ;)) and we can address the lack of warmth later.

I'm fairly sure all onyx color eink lack warmth so, if the sdk lights driver work for actual brightness, we can repurpose it for these devices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants