mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 18:33:34 +08:00
ll40ls: refactor driver start on i2c.
Signed-off-by: Claudio Micheli <claudio@auterion.com>
This commit is contained in:
committed by
Nuno Marques
parent
5eefd9409b
commit
fcdd2fabeb
@@ -89,7 +89,7 @@ namespace ll40ls
|
|||||||
{
|
{
|
||||||
|
|
||||||
LidarLite *instance = nullptr;
|
LidarLite *instance = nullptr;
|
||||||
|
int start_bus(const struct ll40ls_bus_option &i2c_bus, uint8_t rotation);
|
||||||
void start(enum LL40LS_BUS busid, uint8_t rotation);
|
void start(enum LL40LS_BUS busid, uint8_t rotation);
|
||||||
void stop();
|
void stop();
|
||||||
void info();
|
void info();
|
||||||
@@ -126,35 +126,53 @@ void start(enum LL40LS_BUS busid, uint8_t rotation)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = new LidarLiteI2C(bus_options[i].busnum, rotation);
|
if (start_bus(bus_options[i], rotation) == PX4_OK) {
|
||||||
|
|
||||||
if (!instance) {
|
|
||||||
PX4_ERR("Failed to instantiate LidarLiteI2C");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance->init() == PX4_OK) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
PX4_ERR("failed to initialize LidarLiteI2C on busnum=%u", bus_options[i].busnum);
|
|
||||||
stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) {
|
if (instance == nullptr) {
|
||||||
PX4_WARN("No LidarLite found");
|
PX4_WARN("No LidarLite found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the driver on a specific bus.
|
||||||
|
*
|
||||||
|
* This function call only returns once the driver is up and running
|
||||||
|
* or failed to detect the sensor.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
start_bus(const struct ll40ls_bus_option &i2c_bus, uint8_t rotation)
|
||||||
|
{
|
||||||
|
instance = new LidarLiteI2C(i2c_bus.busnum, rotation);
|
||||||
|
|
||||||
|
if (instance->init() != OK) {
|
||||||
|
stop();
|
||||||
|
PX4_INFO("LidarLiteI2C - no device on bus %u", (unsigned)i2c_bus.busid);
|
||||||
|
return PX4_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PX4_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stops the driver
|
* @brief Stops the driver
|
||||||
*/
|
*/
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
delete instance;
|
if (instance != nullptr) {
|
||||||
instance = nullptr;
|
delete instance;
|
||||||
|
instance = nullptr;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
PX4_ERR("driver not running");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user