101 lines
3.2 KiB
C
101 lines
3.2 KiB
C
|
|
#include "UsbDataHandler.h"
|
|
#include "headlight.pb.h"
|
|
#include "CanDataHandler.h"
|
|
#include "stdint.h"
|
|
#include "cmsis_os2.h"
|
|
#include "CLS.h"
|
|
#include "CLS_BSP.h"
|
|
#include "CLSAddress.h"
|
|
#include "ulog.h"
|
|
|
|
cls_headlight_RequestSettings msg_cls_headlight_RequestSettings;
|
|
cls_headlight_Settings msg_cls_headlight_Settings;
|
|
cls_headlight_SaveSettings msg_cls_headlight_SaveSettings;
|
|
|
|
|
|
typedef struct Headlight_Control_Setting {
|
|
float alpha;
|
|
uint16_t on_threshold;
|
|
uint16_t off_threshold;
|
|
} Headlight_Control_Setting_t;
|
|
|
|
|
|
uint16_t headlight_amblight = 0;
|
|
|
|
void CanData_ambilight(CanDataId canid, uint8_t* data, uint8_t len) {
|
|
if(len == 2) {
|
|
headlight_amblight = (data[1] << 8) | data[0];
|
|
}
|
|
|
|
ULOG_INFO("Ambilight: %d", headlight_amblight);
|
|
}
|
|
|
|
void AddHeadlightMessages() {
|
|
CanData_regEventMsg(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS, 0, CLS_CH_STA_AMBIENTLIGHT), CanData_ambilight);
|
|
}
|
|
|
|
// whan a message is received, this function is called
|
|
void DataClbk_cls_headlight_Settings(void* msg, uint32_t length) {
|
|
DATA_CLBK_SETUP(cls_headlight_Settings);
|
|
uint8_t device = msg_cls_headlight_Settings.deviceId;
|
|
|
|
uint16_t msg_light_setting = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG, device, 0);
|
|
CLS_BSP_TxHeaderType can_header = CREATE_BSP_CAN_HEADER(msg_light_setting, CLS_BSP_DLC_BYTES_8);
|
|
|
|
|
|
Headlight_Control_Setting_t data = {0};
|
|
data.alpha = msg_cls_headlight_Settings.alpha;
|
|
data.on_threshold = msg_cls_headlight_Settings.on_threshold;
|
|
data.off_threshold = msg_cls_headlight_Settings.off_threshold;
|
|
|
|
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)&data);
|
|
}
|
|
|
|
|
|
void DataClbk_cls_headlight_SaveSettings(void* msg, uint32_t length) {
|
|
DATA_CLBK_SETUP(cls_headlight_SaveSettings);
|
|
|
|
uint8_t device = msg_cls_headlight_SaveSettings.deviceId;
|
|
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 Headlight_Control_Setting_t response_theme = {0};
|
|
static cls_headlight_Settings headligh_settings = {0};
|
|
void CanData_responseHeadlightSetting(CanDataId canid, uint8_t* data, uint8_t len) {
|
|
if(len == 8) {
|
|
memcpy(&response_theme, data, 8);
|
|
|
|
headligh_settings.alpha = response_theme.alpha;
|
|
headligh_settings.on_threshold = response_theme.on_threshold;
|
|
headligh_settings.off_threshold = response_theme.off_threshold;
|
|
headligh_settings.deviceId = (canid >> 3) & 0x1F;
|
|
|
|
|
|
USBDataResonse(&headligh_settings,cls_headlight_Settings_fields, cls_usb_PackageType_HEADLIGHT_SETTINGS);
|
|
}
|
|
|
|
CanData_removeEvent(canid);
|
|
}
|
|
|
|
|
|
|
|
void DataClbk_cls_headlight_RequestSettings(void* msg, uint32_t length) {
|
|
DATA_CLBK_SETUP(cls_headlight_RequestSettings);
|
|
uint8_t device = msg_cls_headlight_RequestSettings.deviceId;
|
|
uint8_t data = 0;
|
|
|
|
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_responseHeadlightSetting);
|
|
|
|
|
|
CLS_BSP_CAN_AddMessageToSend(&can_header, (uint8_t*)&data);
|
|
}
|