Only read positive voltages in adc.c

The ADC sometimes responds with negative voltages read on the ADC input due to noise. This can lead to very high illuminance readings at night (4095 << 4 to be exact due to two's complement :) ).
This commit caps ADC readings at 0.
This commit is contained in:
Jan-Henrik Bruhn 2024-02-14 11:59:14 +01:00 committed by GitHub
parent dd373ea235
commit 905978e8c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -108,6 +108,7 @@ static int read_adc_spec(const struct adc_dt_spec* spec, prst_adc_read_t* out) {
int32_t val_mv = buf;
RET_IF_ERR(adc_raw_to_millivolts_dt(spec, &val_mv));
val_mv = MAX(0, val_mv);
out->raw = buf;
out->millivolts = val_mv;