Make read bulk fan speed read correctly from the array

This commit is contained in:
Sebastian H. Gabrielli 2024-04-30 11:21:26 +02:00
parent 1671476f41
commit b858d29ce8

View File

@ -245,9 +245,23 @@ uint8_t route_command(int pos) {
break;
case READ_BULK_FAN_SPEED:
if (context.fan == FAN1) {
return fan1_history[pos];
// Validate that pos is valid, if not return 0
if (pos >= 512) { return 0; }
// Calculate the index position
int16_t index = fan1_history_index - pos;
if (index < 0) { index = 511-pos; }
return fan1_history[index];
} else if (context.fan == FAN2) {
return fan2_history[pos];
// Validate that pos is valid, if not return 0
if (pos >= 512) { return 0; }
// Calculate the index position
int16_t index = fan2_history_index - pos;
if (index < 0) { index = 511-pos; }
return fan2_history[index];
} else {
return 0;
}