adjusted dimming only when deadlight is on
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
#include "BSP_EE24.h"
|
||||
#include "LightTask.h"
|
||||
#include "CanDataHandler.h"
|
||||
#include "BSP_GPIO.h"
|
||||
|
||||
#include "CanDataTask.h"
|
||||
#include "BSP_ADC.h"
|
||||
#define DIMM_DEADZONE_VOLTAGE 0.7
|
||||
|
||||
@@ -77,19 +79,31 @@ void LightTask_func(void *argument) {
|
||||
// calculate the brightness to send
|
||||
uint8_t brightness = lightSettings.brightness;
|
||||
// Read ADC battery voltage and dimmer voltage
|
||||
float v_bus = BSP_ADC_ReadBusValue() - DIMM_DEADZONE_VOLTAGE;
|
||||
float v_dimm = BSP_ADC_ReadDimmerValue();
|
||||
|
||||
// calculate the dimmfactor based on the battery voltage and the dimmer voltage
|
||||
// the dimmfactor shoudl be 0 if the dimmer voltage is 4V.
|
||||
// the dimmfactor should be 1 if the dimmer voltage is the same as the battery voltage
|
||||
float dimmfactor;
|
||||
if (v_dimm >= v_bus) {
|
||||
dimmfactor = 1.0;
|
||||
} else if (v_dimm <= 4.0) {
|
||||
dimmfactor = 0.0;
|
||||
} else {
|
||||
dimmfactor = (v_dimm - 4.0) / (v_bus - 4.0);
|
||||
|
||||
|
||||
float dimmfactor = 1.0;
|
||||
|
||||
// only dimm if the headlight is on
|
||||
if (BSP_GPIO_HeadLightIsSet()) {
|
||||
|
||||
// new version over CAN
|
||||
uint8_t precent = CanDataTask_CarCanBrightness();
|
||||
dimmfactor = (float)precent / 100.0;
|
||||
|
||||
// old version over ADC
|
||||
// calculate the dimmfactor based on the battery voltage and the dimmer voltage
|
||||
// the dimmfactor shoudl be 0 if the dimmer voltage is 4V.
|
||||
// the dimmfactor should be 1 if the dimmer voltage is the same as the battery voltage
|
||||
// float v_bus = BSP_ADC_ReadBusValue() - DIMM_DEADZONE_VOLTAGE;
|
||||
// float v_dimm = BSP_ADC_ReadDimmerValue();
|
||||
//if (v_dimm >= v_bus) {
|
||||
// dimmfactor = 1.0;
|
||||
//} else if (v_dimm <= 4.0) {
|
||||
// dimmfactor = 0.0;
|
||||
//} else {
|
||||
// dimmfactor = (v_dimm - 4.0) / (v_bus - 4.0);
|
||||
//}
|
||||
}
|
||||
|
||||
uint8_t adjustedBrightness = (uint8_t)(brightness * dimmfactor);
|
||||
|
||||
@@ -6,9 +6,9 @@ if __name__ == "__main__":
|
||||
ser = setup_connection()
|
||||
# Create a message
|
||||
request = UpdateDeviceSettings()
|
||||
request.device = 2
|
||||
request.device = 5
|
||||
request.type = Type.LIGHT
|
||||
request.position.append(Position.LEFT)
|
||||
request.position.append(Position.RIGHT)
|
||||
request.position.append(Position.FLOOR)
|
||||
# Serialize the request to a bytearray
|
||||
request_data = request.SerializeToString()
|
||||
|
||||
Reference in New Issue
Block a user