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