-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frontlight support for Onyx C67 (#301)
- Loading branch information
1 parent
56c954d
commit bd7a8f3
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/src/main/java/org/koreader/launcher/device/lights/OnyxC67Controller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.koreader.launcher.device.lights | ||
|
||
import android.app.Activity | ||
import android.util.Log | ||
import org.koreader.launcher.Logger | ||
import org.koreader.launcher.interfaces.LightInterface | ||
import java.io.File | ||
|
||
class OnyxC67Controller : LightInterface { | ||
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/rk28_bl/brightness" | ||
} | ||
|
||
override fun hasFallback(): Boolean { | ||
return true | ||
} | ||
|
||
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 { | ||
val brightnessFile = File(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) { | ||
Logger.w(TAG, Log.getStackTraceString(e)) | ||
0 | ||
} | ||
} | ||
|
||
override fun getWarmth(activity: Activity): Int { | ||
Logger.w(TAG, "getWarmth: not implemented") | ||
return 0 | ||
} | ||
|
||
|
||
override fun setBrightness(activity: Activity, brightness: Int) { | ||
if (brightness < BRIGHTNESS_MIN || brightness > BRIGHTNESS_MAX) { | ||
Logger.w(TAG, "brightness value of of range: $brightness") | ||
return | ||
} | ||
Logger.v(TAG, "Setting brightness to $brightness") | ||
val brightnessFile = File(BRIGHTNESS_FILE) | ||
try { | ||
brightnessFile.writeText(brightness.toString()) | ||
} catch (e: Exception) { | ||
Logger.w(TAG, "$e") | ||
} | ||
} | ||
|
||
override fun setWarmth(activity: Activity, warmth: Int) { | ||
Logger.w(TAG, "ignoring setWarmth: not implemented") | ||
} | ||
|
||
override fun getMinWarmth(): Int { | ||
return 0 | ||
} | ||
override fun getMaxWarmth(): Int { | ||
return 0 | ||
} | ||
override fun getMinBrightness(): Int { | ||
return BRIGHTNESS_MIN | ||
} | ||
override fun getMaxBrightness(): Int { | ||
return BRIGHTNESS_MAX | ||
} | ||
} |