I'm thinking the code should look more like:
static void MX_VD6283A1_ALSValues_Process(void)
{
uint8_t channel;
uint32_t current_gain;
uint32_t current_exposure;
uint32_t current_imt; /* inter-measurement time */
/* initialize exposure time */
VD6283A1_LIGHT_SENSOR_SetExposureTime(LIGHT_SENSOR_INSTANCE_0, 100000); /* microseconds */
VD6283A1_LIGHT_SENSOR_GetExposureTime(LIGHT_SENSOR_INSTANCE_0, ¤t_exposure);
printf("Exposure set to %lu us\n", current_exposure);
/* initialize gains */
for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
{
VD6283A1_LIGHT_SENSOR_SetGain(LIGHT_SENSOR_INSTANCE_0, channel, 256);
VD6283A1_LIGHT_SENSOR_GetGain(LIGHT_SENSOR_INSTANCE_0, channel, ¤t_gain);
printf("Channel %d gain set to", channel + 1);
display_gain(current_gain);
}
/* initialize inter measurement time */
VD6283A1_LIGHT_SENSOR_SetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, 500000); /* 100 ms */
VD6283A1_LIGHT_SENSOR_GetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, ¤t_imt);
/* start ALS capture on all channels in continuous mode */
VD6283A1_LIGHT_SENSOR_Start(LIGHT_SENSOR_INSTANCE_0, LIGHT_SENSOR_MODE_CONTINUOUS);
while (!is_quit_requested)
{
/* wait for interrupt event */
if (ALS_EventDetected != 0U)
{
ALS_EventDetected = 0U;
status = VD6283A1_LIGHT_SENSOR_GetValues(LIGHT_SENSOR_INSTANCE_0, AlsResults);
if (status == BSP_ERROR_NONE)
{
/* display ALS values */
for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
{
if (is_dark_enabled && (channel == LIGHT_SENSOR_VISIBLE_CHANNEL))
printf("Channel %u - %8s", channel + 1, "DARK");
else
printf("Channel %u - %8s", channel + 1, AlsChannelStr[channel]);
printf("\tValue: %lu\n", AlsResults[channel]);
}
printf("\n\n");
}
}
handle_cmd(get_key());
}
VD6283A1_LIGHT_SENSOR_Stop(LIGHT_SENSOR_INSTANCE_0);
VD6283A1_LIGHT_SENSOR_DeInit(LIGHT_SENSOR_INSTANCE_0);
printf("Quitting the demo...\n");
while (1);
}
This code is from a slightly different project than yours so the calls are a bit different.
But what I see in mine is different from yours in that I wait for done.
It takes a bit for the sensor to integrate the light and have an answer ready to go.
So you need some 'Are you done yet?' call. (In my code, I'm waiting for an interrupt.)
And I think that is what you are missing.
Sorry for the slow reply, I somehow didn't see you there. I'm blaming the holidays, but I'm sure it's my fault.