Simplify code in functions related to product ids
Signed-off-by: Jacki <jacki@thejackimonster.de>
This commit is contained in:
parent
fc9eb2d898
commit
2ad1caa384
1 changed files with 20 additions and 15 deletions
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue