-
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.
lights drivers: refactor common code to read/write from/to sys nodes
add light driver for Onyx Nova3 color
- Loading branch information
Showing
8 changed files
with
120 additions
and
58 deletions.
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
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
79 changes: 79 additions & 0 deletions
79
app/src/main/java/org/koreader/launcher/device/lights/OnyxColorController.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,79 @@ | ||
package org.koreader.launcher.device.lights | ||
|
||
import android.app.Activity | ||
import android.util.Log | ||
import org.koreader.launcher.device.LightsInterface | ||
import org.koreader.launcher.extensions.read | ||
import org.koreader.launcher.extensions.write | ||
import java.io.File | ||
|
||
/* Controller for some Onyx Color devices. | ||
* Tested on a Onyx Nova3 Color. | ||
* | ||
* Thanks to @ilyats | ||
*/ | ||
|
||
class OnyxColorController : 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-color" | ||
} | ||
|
||
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 File(ACTUAL_BRIGHTNESS_FILE).read() | ||
} | ||
|
||
override fun getWarmth(activity: Activity): Int { | ||
Log.w(TAG, "getWarmth: not implemented") | ||
return 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") | ||
File(BRIGHTNESS_FILE).write(brightness) | ||
} | ||
|
||
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 BRIGHTNESS_MIN | ||
} | ||
override fun getMaxBrightness(): Int { | ||
return BRIGHTNESS_MAX | ||
} | ||
} |
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
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