|
@@ -1,23 +1,27 @@
|
|
|
-#!/usr/bin/python3
|
|
|
|
|
|
|
+#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
-from typing import Dict
|
|
|
|
|
|
|
|
|
|
-# ließ und schreibt RGB Daten für die farbige Tastaturbeleuchtung auf Clevo NL51 Laptops
|
|
|
|
|
-# Notwendigerweise müssen die Treiber von NovaCustom oder Tuxedo kompiliert und geladen sein
|
|
|
|
|
-# siehe: https://wiki.siningsoft.de/doku.php?id=terra:1500p
|
|
|
|
|
|
|
+# reads and writes RGB and brightness data for led background color of Clevo NL51 Laptops
|
|
|
|
|
+# ensure to compile drivers before ! read: https://wiki.siningsoft.de/doku.php?id=terra:1500p
|
|
|
# Kernelmodul: tuxedo_keyboard
|
|
# Kernelmodul: tuxedo_keyboard
|
|
|
|
|
|
|
|
|
|
+# ToDo: add argument and function for switching color on commandline
|
|
|
|
|
+# ToDo: add argument and functions for switching brightness on commandline
|
|
|
|
|
+
|
|
|
# 2026-02-02 - devnull - initial
|
|
# 2026-02-02 - devnull - initial
|
|
|
# 2026-02-03 - devnull - added Brightness restore
|
|
# 2026-02-03 - devnull - added Brightness restore
|
|
|
# 2026-02-04 - devnull - JSON statefile
|
|
# 2026-02-04 - devnull - JSON statefile
|
|
|
-# 2026-02-11 - devnull - Einführung einer Klasse
|
|
|
|
|
|
|
+# 2026-02-11 - devnull - created class
|
|
|
|
|
+# 2026-02-18 - devnull - added logging
|
|
|
|
|
|
|
|
ver="1.1"
|
|
ver="1.1"
|
|
|
|
|
|
|
|
-import os
|
|
|
|
|
import sys
|
|
import sys
|
|
|
import argparse
|
|
import argparse
|
|
|
import json
|
|
import json
|
|
|
|
|
+import logging
|
|
|
|
|
+
|
|
|
|
|
+log = logging.getLogger("kbdLED")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -27,17 +31,26 @@ class kbdLED_class:
|
|
|
|
|
|
|
|
# diese Versionsnummer wird getrennt vom Programmcode geführt, da es sich getrennt entwickeln wird
|
|
# diese Versionsnummer wird getrennt vom Programmcode geführt, da es sich getrennt entwickeln wird
|
|
|
__version__ = 1.1
|
|
__version__ = 1.1
|
|
|
- config = Dict()
|
|
|
|
|
|
|
+ config = dict()
|
|
|
|
|
|
|
|
# Objekt erzeugen
|
|
# Objekt erzeugen
|
|
|
- def __init__(self, cmd, kbd_state_fp='/var/lib/kbdLED.state.json', sysfs_color_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/multi_intensity', sysfs_bri_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/brightness'):
|
|
|
|
|
|
|
+ def __init__(self, cmd, log, kbd_state_fp='/var/lib/kbdLED.state.json',
|
|
|
|
|
+ sysfs_color_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/multi_intensity',
|
|
|
|
|
+ sysfs_bri_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/brightness'):
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- self.config['sysfs']['color']=sysfs_color_fp
|
|
|
|
|
- self.config['sysfs']['bri']=sysfs_bri_fp
|
|
|
|
|
- self.config['state']=kbd_state_fp
|
|
|
|
|
|
|
+ self.config = {"sysfs" :
|
|
|
|
|
+ {
|
|
|
|
|
+ "color" : sysfs_color_fp ,
|
|
|
|
|
+ "bri" : sysfs_bri_fp
|
|
|
|
|
+ },
|
|
|
|
|
+ "state" : kbd_state_fp}
|
|
|
|
|
+
|
|
|
|
|
+ #DEBUGprint("debug: " + str(self.config))
|
|
|
|
|
|
|
|
if cmd=="start":
|
|
if cmd=="start":
|
|
|
self.readStateFile(self.config['state'])
|
|
self.readStateFile(self.config['state'])
|
|
|
|
|
+ #print("debug: " + str(self.config))
|
|
|
self.writeColor()
|
|
self.writeColor()
|
|
|
self.writeBrightness()
|
|
self.writeBrightness()
|
|
|
|
|
|
|
@@ -48,7 +61,7 @@ class kbdLED_class:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- def readStateFile(kbd_state_fp):
|
|
|
|
|
|
|
+ def readStateFile(self,kbd_state_fp):
|
|
|
|
|
|
|
|
config = {"color":
|
|
config = {"color":
|
|
|
{"R": 255,
|
|
{"R": 255,
|
|
@@ -59,59 +72,59 @@ class kbdLED_class:
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
with open(kbd_state_fp, 'r') as kbd_state_fh:
|
|
with open(kbd_state_fp, 'r') as kbd_state_fh:
|
|
|
- config = json.load(kbd_state_fh)
|
|
|
|
|
|
|
+ self.config = json.load(kbd_state_fh)
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
print("keine Statusdatei gefunden, nutze Standardwerte")
|
|
print("keine Statusdatei gefunden, nutze Standardwerte")
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
print("Fehler beim lesen")
|
|
print("Fehler beim lesen")
|
|
|
|
|
|
|
|
- return config
|
|
|
|
|
-
|
|
|
|
|
- def writeStateFile(kbd_state_fp):
|
|
|
|
|
|
|
+ def writeStateFile(self,kbd_state_fp):
|
|
|
try:
|
|
try:
|
|
|
with open(kbd_state_fp, 'w') as kbd_state_fh:
|
|
with open(kbd_state_fp, 'w') as kbd_state_fh:
|
|
|
- json.dump(self.config, kbd_state_fh)
|
|
|
|
|
|
|
+ json.dump(self.config,kbd_state_fh)
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
print("Verzeichnis nicht gefunden")
|
|
print("Verzeichnis nicht gefunden")
|
|
|
|
|
|
|
|
- return True
|
|
|
|
|
-
|
|
|
|
|
# color String nach Config Dict
|
|
# color String nach Config Dict
|
|
|
def color2dict(self,color_string):
|
|
def color2dict(self,color_string):
|
|
|
ca=color_string.split(" ")
|
|
ca=color_string.split(" ")
|
|
|
- self.config['color']['R'] = int(ca[0])
|
|
|
|
|
- self.config['color']['G'] = int(ca[1])
|
|
|
|
|
- self.config['color']['B'] = int(ca[2])
|
|
|
|
|
|
|
+ self.config['color'] = {"R": int(ca[0]),
|
|
|
|
|
+ "G": int(ca[1]),
|
|
|
|
|
+ "B": int(ca[2])}
|
|
|
|
|
|
|
|
# color Confi Dict nach String
|
|
# color Confi Dict nach String
|
|
|
def dict2color(self):
|
|
def dict2color(self):
|
|
|
- return self.config['color']['R'] + " " + self.config['color']['G'] + " " + self.config['color']['B']
|
|
|
|
|
|
|
+ return str(self.config['color']['R']) + " " + str(self.config['color']['G']) + " " + str(self.config['color']['B'])
|
|
|
|
|
|
|
|
# reads the color Values from sysfs
|
|
# reads the color Values from sysfs
|
|
|
def readColor(self):
|
|
def readColor(self):
|
|
|
try:
|
|
try:
|
|
|
- with open(self.config['sysfs']['sysfs_color_fp']) as fh:
|
|
|
|
|
|
|
+ with open(self.config['sysfs']['color']) as fh:
|
|
|
self.color2dict(fh.read())
|
|
self.color2dict(fh.read())
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("- fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['sysfs_color_fp'])
|
|
|
|
|
|
|
+ print("- fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("- keine Rechte die Datei zu lesen " + self.config['sysfs']['sysfs_color_fp'])
|
|
|
|
|
|
|
+ print("- keine Rechte die Datei zu lesen " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
# writes the color values to sysfs
|
|
# writes the color values to sysfs
|
|
|
def writeColor(self):
|
|
def writeColor(self):
|
|
|
try:
|
|
try:
|
|
|
- with open(self.config['sysfs']['color']) as fh:
|
|
|
|
|
- fh.write(self.dict2color())
|
|
|
|
|
|
|
+ #with open(self.config['sysfs']['color']) as fh:
|
|
|
|
|
+ # fh.write(self.dict2color())
|
|
|
|
|
+ fh = open(self.config['sysfs']['color'], 'w')
|
|
|
|
|
+ fh.write(self.dict2color())
|
|
|
|
|
+ fh.close()
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['color'])
|
|
print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
+
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
print("- keine Rechte die Datei zu schreiben " + self.config['sysfs']['color'])
|
|
print("- keine Rechte die Datei zu schreiben " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
@@ -132,8 +145,11 @@ class kbdLED_class:
|
|
|
# writes Brightness to sysfs
|
|
# writes Brightness to sysfs
|
|
|
def writeBrightness(self):
|
|
def writeBrightness(self):
|
|
|
try:
|
|
try:
|
|
|
- with open(self.config['sysfs']['bri']) as fh:
|
|
|
|
|
- fh.write(self.config['Brightness'])
|
|
|
|
|
|
|
+ #with open(self.config['sysfs']['bri']) as fh:
|
|
|
|
|
+ # fh.write(self.config['Brightness'])
|
|
|
|
|
+ fh = open(self.config['sysfs']['bri'], 'w')
|
|
|
|
|
+ fh.write(str(self.config['Brightness']))
|
|
|
|
|
+ fh.close()
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
@@ -153,20 +169,29 @@ if __name__ == '__main__':
|
|
|
startstop = parser.add_mutually_exclusive_group()
|
|
startstop = parser.add_mutually_exclusive_group()
|
|
|
startstop.add_argument('--start', action='store_true', help='will be used for system starts')
|
|
startstop.add_argument('--start', action='store_true', help='will be used for system starts')
|
|
|
startstop.add_argument('--stop', action='store_true', help='will be used for system shutdowns')
|
|
startstop.add_argument('--stop', action='store_true', help='will be used for system shutdowns')
|
|
|
|
|
+ startstop.add_argument('--verbose', action='store_true', help='extended Logging')
|
|
|
|
|
+ startstop.add_argument('--debug', action='store_true', help='debugging information')
|
|
|
startstop.add_argument('--version', action='version', version='%(prog)s ' + ver, default='d')
|
|
startstop.add_argument('--version', action='version', version='%(prog)s ' + ver, default='d')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
+ if args.verbose:
|
|
|
|
|
+ log.setLevel(logging.INFO)
|
|
|
|
|
+ if args.debug:
|
|
|
|
|
+ log.setLevel(logging.DEBUG)
|
|
|
|
|
+
|
|
|
if args.start:
|
|
if args.start:
|
|
|
print("Keyboard: read and set Color and Brightness")
|
|
print("Keyboard: read and set Color and Brightness")
|
|
|
- kL = kbdLED_class("start")
|
|
|
|
|
|
|
+ log.debug("System start")
|
|
|
|
|
+ kL = kbdLED_class("start", log)
|
|
|
|
|
|
|
|
elif args.stop:
|
|
elif args.stop:
|
|
|
print("Keyboard: read and save Color and Brightness")
|
|
print("Keyboard: read and save Color and Brightness")
|
|
|
- kL = kbdLED_class("stop")
|
|
|
|
|
|
|
+ log.debug("System stop")
|
|
|
|
|
+ kL = kbdLED_class("stop", log)
|
|
|
|
|
|
|
|
else:
|
|
else:
|
|
|
parser.print_help()
|
|
parser.print_help()
|
|
|
- sys.exit((1))
|
|
|
|
|
|
|
+ sys.exit((10))
|
|
|
|
|
|
|
|
sys.exit(0)
|
|
sys.exit(0)
|