Browse Source

AP_HAL_Linux: examples: small fixes to BusTest

- Fix char allocation
  - Fix coding style
  - Fix accessing dev->bus_type(): it's a function
master
Lucas De Marchi 8 years ago
parent
commit
875538ccb5
  1. 24
      libraries/AP_HAL_Linux/examples/BusTest/BusTest.cpp

24
libraries/AP_HAL_Linux/examples/BusTest/BusTest.cpp

@ -1,5 +1,3 @@
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
// //
// scan I2C and SPI buses for expected devices // scan I2C and SPI buses for expected devices
// //
@ -25,22 +23,24 @@ get_device(const char *name)
{ {
AP_HAL::OwnPtr<AP_HAL::Device> dev; AP_HAL::OwnPtr<AP_HAL::Device> dev;
const char *spi_name = new char; const char *spi_name = hal.spi->get_device_name(0);
spi_name = hal.spi->get_device_name(0);
/* Dummy is the default device at index 0 /* Dummy is the default device at index 0
if there isn't registered device for the target board. if there isn't registered device for the target board.
*/ */
const char *dummy = {"**dummy**"}; const char *dummy = "**dummy**";
if (!strcmp(dummy, spi_name)) { if (!strcmp(dummy, spi_name)) {
hal.console->printf("No devices, nothing to do.\n"); hal.console->printf("No devices, nothing to do.\n");
while(1) { hal.scheduler->delay(500); }; while (1) {
hal.scheduler->delay(500);
}
} }
/* We get possible registered device count on the target board */ /* We get possible registered device count on the target board */
uint8_t spicount = hal.spi->get_count(); uint8_t spicount = hal.spi->get_count();
for (uint8_t ref = 0; ref < spicount; ref++) { for (uint8_t ref = 0; ref < spicount; ref++) {
/* We get the name from the index and we compare /*
with our possible devices list. * We get the name from the index and we compare
* with our possible devices list.
*/ */
spi_name = hal.spi->get_device_name(ref); spi_name = hal.spi->get_device_name(ref);
if (!strcmp(name, spi_name)) { if (!strcmp(name, spi_name)) {
@ -67,9 +67,11 @@ void loop(void)
for (uint8_t i = 0; i < ARRAY_SIZE(whoami_list); i++) { for (uint8_t i = 0; i < ARRAY_SIZE(whoami_list); i++) {
dev = get_device(whoami_list[i].name); dev = get_device(whoami_list[i].name);
if (dev) { if (!dev) {
continue;
}
if (dev->bus_type == AP_HAL::Device::BusType::BUS_TYPE_SPI) { if (dev->bus_type() == AP_HAL::Device::BusType::BUS_TYPE_SPI) {
bus_type = "SPI"; bus_type = "SPI";
} else { } else {
bus_type = "I2C"; bus_type = "I2C";
@ -94,7 +96,7 @@ void loop(void)
} }
spi_sem->give(); spi_sem->give();
} }
}
hal.scheduler->delay(1000); hal.scheduler->delay(1000);
} }

Loading…
Cancel
Save