Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
优化显示器调节
Browse files Browse the repository at this point in the history
  • Loading branch information
1812z committed Sep 20, 2024
1 parent d6821e6 commit b87c2d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 11 additions & 3 deletions command.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ def on_connect(client, userdata, flags, reason_code, properties):
print("成功连接到:", broker)
subcribe(client)


# 运行命令
def run_command(command, data):
path = json_data.get("user_directory") + "\\AppData\\Local\\Programs\\twinkle-tray\\Twinkle Tray.exe"
print(path)
key = command.split('/')[2]
if key == device_name + "screen": # 显示器亮度调节
if key == device_name + "screen": # 显示器控制
if data == "OFF":
run = r' "C:\Program Files\WindowsApps\38002AlexanderFrangos.TwinkleTray_1.15.4.0_x64__m7qx9dzpwqaze\app\Twinkle Tray.exe" --MonitorNum=1 --VCP=0xD6:0x04 '
run = 'start /b cmd /c "'+ path + '" --MonitorNum=1 --VCP=0xD6:0x04'
os.system(run)
else:
brightness = str(int(data) * 100 // 255)
run = 'start /b cmd /c '+r' "C:\Program Files\WindowsApps\38002AlexanderFrangos.TwinkleTray_1.15.4.0_x64__m7qx9dzpwqaze\app\Twinkle Tray.exe" --MonitorNum=1 --Set=' + brightness
run = 'start /b cmd /c "'+ path + '" --MonitorNum=1 --Set=' + brightness
print(run)
os.system(run)
print("显示器亮度:", brightness)
elif key == device_name + "volume":
Expand All @@ -96,6 +101,7 @@ def run_command(command, data):
run = current_directory + '\\' + run_file
os.system(f'start "" "{run}"')


# 初始化
def init_data():
global current_directory
Expand All @@ -115,12 +121,14 @@ def init_data():
global device_name
global device_name
global broker
global user_directory
json_data = json.load(file)
username = json_data.get("username")
password = json_data.get("password")
broker = json_data.get("HA_MQTT")
port = json_data.get("HA_MQTT_port")
device_name = json_data.get("device_name")
user_directory = json_data.get("user_directory")

global mqttc
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
Expand Down
9 changes: 7 additions & 2 deletions gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import threading
import time
from PIL import Image
Expand Down Expand Up @@ -358,10 +359,14 @@ def icon_task():
icon.run()


def user_directory():
save_json_data("user_directory",os.path.expanduser("~"))


show_menu_flag = False
icon_flag = True
if __name__ == "__main__":

threading.Thread(target=icon_task).start()
with open('config.json', 'r') as file:
json_data = json.load(file)
Expand All @@ -375,7 +380,7 @@ def icon_task():
read_ha_broker = json_data.get("HA_MQTT")
read_port = json_data.get("HA_MQTT_port")
read_device_name = json_data.get("device_name")

user_directory()
if fun4:
run_flag = True
start()
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Homeassistant远程运行可执行文件
- 必选: pyhon 相关库, Homeassistant MQTT加载项
通过如下命令安装环境
`pip install -r .\requirements.txt`
- 监控反馈: Aida64(读取数据并共享给程序)
- 远程命令: Twinkle tray(控制显示器亮度)
- 电脑信息监控: 依赖Aida64(读取数据并共享给程序)
- 显示器亮度调节: 依赖[Twinkle tray](https://github.com/xanderfrangos/twinkle-tray/releases)

## 二.启动程序

Expand Down

0 comments on commit b87c2d5

Please sign in to comment.