Simplify code in functions related to product ids

Signed-off-by: Jacki <jacki@thejackimonster.de>
This commit is contained in:
Jacki 2024-08-02 01:12:58 +02:00
parent fc9eb2d898
commit 2ad1caa384
No known key found for this signature in database
GPG key ID: B404184796354C5E

View file

@ -56,31 +56,36 @@ const int xreal_mcu_interface_ids[NUM_SUPPORTED_PRODUCTS] = {
-1 // TODO - XREAL Air 2 Ultra MCU support via interface 0 -1 // TODO - XREAL Air 2 Ultra MCU support via interface 0
}; };
bool is_xreal_product_id(uint16_t product_id) { static int xreal_product_index(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) { for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) {
if (xreal_product_ids[i] == product_id) { if (xreal_product_ids[i] == product_id) {
return true; return i;
} }
} }
return false;
return -1;
}
bool is_xreal_product_id(uint16_t product_id) {
return xreal_product_index(product_id) >= 0;
} }
int xreal_imu_interface_id(uint16_t product_id) { int xreal_imu_interface_id(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) { const int index = xreal_product_index(product_id);
if (xreal_product_ids[i] == product_id) {
return xreal_imu_interface_ids[i];
}
}
return -1; if (index >= 0) {
return xreal_imu_interface_ids[index];
} else {
return -1;
}
} }
int xreal_mcu_interface_id(uint16_t product_id) { int xreal_mcu_interface_id(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) { const int index = xreal_product_index(product_id);
if (xreal_product_ids[i] == product_id) {
return xreal_mcu_interface_ids[i];
}
}
return -1; if (index >= 0) {
return xreal_mcu_interface_ids[index];
} else {
return -1;
}
} }