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

View File

@@ -7,6 +7,7 @@
#include "CLSAddress.h"
#include "BSP_EE24.h"
#include "LightTask.h"
#include "CanDataHandler.h"
// Memory for the task
StaticTask_t LightTask_cb;
@@ -27,6 +28,7 @@ static cls_light_GlobalBrightness msg_cls_light_GlobalBrightness;
static cls_light_GlobalTheme msg_cls_light_GlobalTheme;
static cls_light_ThemeSettings msg_cls_light_ThemeSettings;
static cls_light_SaveThemeSettings msg_cls_light_SaveThemeSettings;
static cls_light_RequestThemeSetting msg_cls_light_RequestThemeSetting;
static volatile struct LightSettings_s {
volatile uint8_t brightness;
@@ -105,4 +107,36 @@ void DataClbk_cls_light_SaveThemeSettings(void* msg, uint32_t length) {
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 4);
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_1);
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)"X");
}
static uint8_t request_theme;
static RGB_Theme_t response_theme;
static cls_light_ThemeSettings themesettings;
void CanData_responseThemeSetting(CanDataId canid, uint8_t* data, uint8_t len) {
if(len == 8) {
memcpy(&response_theme, data, 8);
themesettings.animation = response_theme.animation;
themesettings.brightness = response_theme.max_brighness;
themesettings.deviceId = (canid >> 3) & 0x1F;
themesettings.rgb = response_theme.color.r | (response_theme.color.g << 8) | (response_theme.color.b << 16);
themesettings.theme = request_theme;
USBDataResonse(&themesettings,cls_light_ThemeSettings_fields, cls_usb_PackageType_LIGHT_SETTING_THEME);
}
CanData_removeEvent(canid);
}
void DataClbk_cls_light_RequestThemeSetting(void* msg, uint32_t length) {
DATA_CLBK_SETUP(cls_light_RequestThemeSetting);
uint8_t device = msg_cls_light_RequestThemeSetting.deviceId;
request_theme = (uint8_t)msg_cls_light_RequestThemeSetting.theme;
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 7);
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_1);
CanData_regEventMsg(msg_light_setting,CanData_responseThemeSetting);
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)&request_theme);
}

View File

@@ -60,6 +60,7 @@ union {
cls_light_GlobalTheme msg_cls_light_GlobalTheme;
cls_light_ThemeSettings msg_cls_light_ThemeSettings;
cls_light_SaveThemeSettings msg_cls_light_SaveThemeSettings;
cls_light_RequestThemeSetting msg_cls_light_RequestThemeSetting;
} mem_msg_decode;
@@ -117,6 +118,7 @@ message_handler_t message_handlers[] = {
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_GLOBAL_THEME, cls_light_GlobalTheme),
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_SETTING_THEME, cls_light_ThemeSettings),
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_SETTING_THEME_SAVE, cls_light_SaveThemeSettings),
MESSAGE_HANDLER(cls_usb_PackageType_LIGHT_REQUEST_THEME, cls_light_RequestThemeSetting),
};

View File

@@ -134,6 +134,7 @@ void DataClbk_cls_light_GlobalBrightness(void* msg, uint32_t length);
void DataClbk_cls_light_GlobalTheme(void* msg, uint32_t length);
void DataClbk_cls_light_ThemeSettings(void* msg, uint32_t length);
void DataClbk_cls_light_SaveThemeSettings(void* msg, uint32_t length);
void DataClbk_cls_light_RequestThemeSetting(void* msg, uint32_t length);
#include "usb.pb.h"
void USBDataResonse(void * msg, const pb_msgdesc_t *fields, cls_usb_PackageType typeid);

2
proto

Submodule proto updated: eca57b1315...30e74889a2

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)