added request for light theme

This commit is contained in:
2024-05-09 02:16:48 +02:00
parent e8518fc9d4
commit 4431f12c8f
5 changed files with 85 additions and 1 deletions

47
tools/test_get_theme.py Normal file
View File

@@ -0,0 +1,47 @@
import serial
import struct
from google.protobuf.message import DecodeError
from serial.tools import list_ports
from light_pb2 import RequestThemeSetting, Theme, ThemeSettings
from usb_pb2 import PackageType
from vcp_driver import *
if __name__ == "__main__":
ser = setup_connection()
request = RequestThemeSetting()
request.deviceId = 0
request.theme = 1
print("send request")
print(request)
request_data = request.SerializeToString()
send_package(PackageType.LIGHT_REQUEST_THEME, request_data, ser)
print("wait for response")
# Read the header from the serial port
response_header = ser.read(5) # assuming the header is 5 bytes long
# Unpack the header to get the length and type
length, typeid, check = struct.unpack('<HHB', response_header)
print(length, typeid, check)
# Check if the type is RESPONSE_DEVICE_LIST
if typeid == PackageType.LIGHT_SETTING_THEME:
# Read the response data from the serial port
response_data = ser.read(length)
# Try to parse the data as a ResponseDeviceList message
try:
response = ThemeSettings.FromString(response_data)
except DecodeError:
# If we get a DecodeError, it means the data we read is not a valid
# ResponseDeviceList message. Ignore it and continue reading.
pass
print(response)