50 #include <board_config.h> 52 #include <px4_platform_common/getopt.h> 53 #include <px4_platform_common/module.h> 68 int start(
const uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
69 int start_bus(
const int bus = PX4_I2C_BUS_EXPANSION,
70 const uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
71 int start_pwm(
const uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
83 PX4_ERR(
"No ll40ls driver running");
101 if (instance !=
nullptr) {
102 PX4_ERR(
"already started");
124 if (instance !=
nullptr) {
125 PX4_ERR(
"already started");
132 if (instance ==
nullptr) {
133 PX4_ERR(
"Failed to instantiate the driver");
139 if (instance->
init() != PX4_OK) {
140 PX4_ERR(
"Failed to initialize LidarLite on bus = %u", bus);
149 PX4_INFO(
"driver started");
162 if (instance !=
nullptr) {
163 PX4_ERR(
"already started");
169 if (instance ==
nullptr) {
170 PX4_ERR(
"Failed to instantiate the driver");
176 if (instance->
init() != PX4_OK) {
177 PX4_ERR(
"Failed to initialize LidarLite pwm.");
186 PX4_INFO(
"driver started");
196 if (instance ==
nullptr) {
197 PX4_ERR(
"driver not running");
211 if (instance !=
nullptr) {
216 PX4_INFO(
"driver stopped");
226 PRINT_MODULE_DESCRIPTION(
230 I2C bus driver for LidarLite rangefinders. 232 The sensor/driver must be enabled using the parameter SENS_EN_LL40LS. 234 Setup/usage information: https://docs.px4.io/en/sensor/lidar_lite.html 238 Start driver on any bus (start on bus where first sensor found). 239 $ ll40ls start i2c -a 240 Start driver on specified bus 241 $ ll40ls start i2c -b 1 246 PRINT_MODULE_USAGE_NAME("ll40ls",
"driver");
247 PRINT_MODULE_USAGE_SUBCATEGORY(
"distance_sensor");
248 PRINT_MODULE_USAGE_COMMAND_DESCR(
"print_regs",
"Print the register values");
249 PRINT_MODULE_USAGE_COMMAND_DESCR(
"start",
"Start driver");
250 PRINT_MODULE_USAGE_COMMAND_DESCR(
"pwm",
"PWM device");
251 PRINT_MODULE_USAGE_COMMAND_DESCR(
"i2c",
"I2C device");
252 PRINT_MODULE_USAGE_PARAM_FLAG(
'a',
"Attempt to start driver on all I2C buses (first one found)",
true);
253 PRINT_MODULE_USAGE_PARAM_INT(
'b', 1, 1, 2000,
"Start driver on specific I2C bus",
true);
254 PRINT_MODULE_USAGE_PARAM_INT(
'R', 25, 1, 25,
"Sensor rotation - downward facing by default",
true);
255 PRINT_MODULE_USAGE_COMMAND_DESCR(
"status",
"Print driver status information");
256 PRINT_MODULE_USAGE_COMMAND_DESCR(
"stop",
"Stop driver");
268 const char *myoptarg =
nullptr;
270 int bus = PX4_I2C_BUS_EXPANSION;
274 uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
276 bool start_i2c_all =
false;
279 while ((ch = px4_getopt(argc, argv,
"ab:R:", &myoptind, &myoptarg)) != EOF) {
282 start_i2c_all =
true;
286 bus = atoi(myoptarg);
290 rotation = (uint8_t)atoi(myoptarg);
291 PX4_INFO(
"Setting Lidar orientation to %d", (
int)rotation);
300 if (argc > myoptind + 1) {
301 const char *protocol = argv[myoptind + 1];
303 if (!strcmp(protocol,
"i2c")) {
304 PX4_INFO(
"protocol %s", protocol);
306 }
else if (!strcmp(protocol,
"pwm")) {
307 PX4_INFO(
"protocol %s", protocol);
311 PX4_INFO(
"unknown protocol, choose pwm or i2c");
316 if (myoptind >= argc) {
321 if (!strcmp(argv[myoptind],
"print_regs")) {
326 if (!strcmp(argv[myoptind],
"start")) {
328 PX4_INFO(
"starting all i2c busses");
331 }
else if (start_pwm) {
332 PX4_INFO(
"starting pwm");
341 if (!strcmp(argv[myoptind],
"status")) {
346 if (!strcmp(argv[myoptind],
"stop")) {
int stop()
Stops the driver.
int start_pwm(const uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING)
Start the pwm driver.
Local functions in support of the shell command.
int usage()
Displays driver usage at the console.
int status()
Prints status info about the driver.
int start_bus(const int bus=PX4_I2C_BUS_EXPANSION, const uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING)
Start the driver on a specific bus.
virtual void print_registers()
print registers to console.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
static const int i2c_bus_options[]
int print_regs()
Prints register information to the console.
__EXPORT int ll40ls_main(int argc, char *argv[])
Driver 'main' command.
void print_info()
Diagnostics - print some basic information about the driver.
#define NUM_I2C_BUS_OPTIONS
int start(const uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING)
Attempt to start driver on all available I2C busses.
Base class for devices connected via I2C.