Notification settings: correctly count values with a zero index (#621)

This commit is contained in:
SG 2021-08-04 03:07:39 +10:00 committed by GitHub
parent bf6c9fe114
commit 15592682ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,7 +74,7 @@ uint8_t float_value_index(const float value, const float values[], uint8_t value
const float epsilon = 0.01f;
float last_value = values[0];
uint8_t index = 0;
for(uint8_t i = 1; i < values_count; i++) {
for(uint8_t i = 0; i < values_count; i++) {
if((value >= last_value - epsilon) && (value <= values[i] + epsilon)) {
index = i;
break;
@ -85,9 +85,9 @@ uint8_t float_value_index(const float value, const float values[], uint8_t value
}
uint8_t uint32_value_index(const uint32_t value, const uint32_t values[], uint8_t values_count) {
float last_value = values[0];
int64_t last_value = INT64_MIN;
uint8_t index = 0;
for(uint8_t i = 1; i < values_count; i++) {
for(uint8_t i = 0; i < values_count; i++) {
if((value >= last_value) && (value <= values[i])) {
index = i;
break;