Initial commit
This commit is contained in:
commit
b84a808c43
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 punzik
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
5
Makefile
Normal file
5
Makefile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
all: nbackbright.nim
|
||||||
|
nim c -d:release --opt:size nbackbright.nim
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf nbackbright
|
||||||
7
README.md
Normal file
7
README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Simple tool for backlight brightness control. For build from source needs
|
||||||
|
[Nim](https://nim-lang.org/) language compiler.
|
||||||
|
|
||||||
|
Usage: `nbackbright <percent>`, where `<percent>` is a percentage of brightness
|
||||||
|
changing.
|
||||||
|
|
||||||
|
For example: `nbackbright -10` decrease brightness by 10%.
|
||||||
37
nbackbright.nim
Normal file
37
nbackbright.nim
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
import streams
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
const
|
||||||
|
BL_SYS_DIR = "/sys/class/backlight"
|
||||||
|
|
||||||
|
proc change_brightness(percent: int) =
|
||||||
|
if dirExists(BL_SYS_DIR):
|
||||||
|
for kind, path in walkDir(BL_SYS_DIR):
|
||||||
|
let
|
||||||
|
br_file = path & "/brightness"
|
||||||
|
mb_file = path & "/max_brightness"
|
||||||
|
if fileExists(br_file) and fileExists(mb_file):
|
||||||
|
try:
|
||||||
|
let br_stream = openFileStream(br_file)
|
||||||
|
let br = parseInt(br_stream.readLine())
|
||||||
|
br_stream.close()
|
||||||
|
|
||||||
|
let mb_stream = openFileStream(mb_file)
|
||||||
|
let mb = parseInt(mb_stream.readLine())
|
||||||
|
mb_stream.close()
|
||||||
|
|
||||||
|
var new_br = int(float(br) + float(mb) / 100.0 * float(percent))
|
||||||
|
if new_br < 0: new_br = 0
|
||||||
|
if new_br > mb: new_br = mb
|
||||||
|
|
||||||
|
let br_write = openFileStream(br_file, fmWrite)
|
||||||
|
br_write.writeLine(new_br)
|
||||||
|
br_write.close()
|
||||||
|
except:
|
||||||
|
echo "Fail to interact with ", br_file
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
if paramCount() > 0:
|
||||||
|
let percent = parseInt(paramStr(1))
|
||||||
|
change_brightness(percent)
|
||||||
Loading…
x
Reference in New Issue
Block a user