Skip to content
Snippets Groups Projects
Commit 43965c6e authored by Daniel Agar's avatar Daniel Agar
Browse files

batt_smbus cleanup unnecessary Device CDev usage

parent 9b2274ea
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@
#include "batt_smbus.h"
BATT_SMBUS::BATT_SMBUS(device::Device *interface, const char *path) :
CDev("BATT_SMBUS", path),
CDev(path),
_interface(interface),
_batt_topic(nullptr),
_batt_orb_id(nullptr),
......@@ -61,10 +61,6 @@ BATT_SMBUS::BATT_SMBUS(device::Device *interface, const char *path) :
_low_thr(0.0f),
_manufacturer_name(nullptr)
{
// Set the device type from the interface.
_device_id.devid_s.bus_type = _interface->get_device_bus_type();
_device_id.devid_s.bus = _interface->get_device_bus();
_device_id.devid_s.address = _interface->get_device_address();
}
BATT_SMBUS::~BATT_SMBUS()
......@@ -107,7 +103,7 @@ int BATT_SMBUS::block_read(const uint8_t cmd_code, void *data, const unsigned le
}
// addr(wr), cmd_code, addr(r), byte_count, rx_data[]
uint8_t device_address = get_device_address();
uint8_t device_address = _interface->get_device_address();
uint8_t full_data_packet[DATA_BUFFER_SIZE + 4] = {0};
full_data_packet[0] = (device_address << 1) | 0x00;
......@@ -560,7 +556,7 @@ int BATT_SMBUS::read_word(const uint8_t cmd_code, void *data)
if (PX4_OK == result) {
// Check PEC.
uint8_t addr = (get_device_address() << 1);
uint8_t addr = (_interface->get_device_address() << 1);
uint8_t full_data_packet[5];
full_data_packet[0] = addr | 0x00;
full_data_packet[1] = cmd_code;
......@@ -584,12 +580,12 @@ int BATT_SMBUS::search_addresses()
{
uint16_t tmp;
set_device_address(BATT_SMBUS_ADDR);
_interface->set_device_address(BATT_SMBUS_ADDR);
if (PX4_OK != read_word(BATT_SMBUS_VOLTAGE, &tmp)) {
// Search through all valid SMBus addresses.
for (uint8_t i = BATT_SMBUS_ADDR_MIN; i < BATT_SMBUS_ADDR_MAX; i++) {
set_device_address(i);
_interface->set_device_address(i);
if (read_word(BATT_SMBUS_VOLTAGE, &tmp) == PX4_OK) {
if (tmp > 0) {
......@@ -604,7 +600,7 @@ int BATT_SMBUS::search_addresses()
}
}
PX4_INFO("Smart battery found at 0x%x", get_device_address());
PX4_INFO("Smart battery found at 0x%x", _interface->get_device_address());
PX4_INFO("Smart battery connected");
return PX4_OK;
......@@ -633,4 +629,4 @@ int BATT_SMBUS::unseal()
}
return PX4_OK;
}
\ No newline at end of file
}
......@@ -43,7 +43,6 @@
* @author Jacob Dahl <dahl.jakejacob@gmail.com>
*/
#include <px4_config.h>
#include <px4_workqueue.h>
......@@ -52,7 +51,7 @@
#include <string.h>
#include <ecl/geo/geo.h>
#include <drivers/device/CDev.hpp>
#include <lib/cdev/CDev.hpp>
#include <drivers/device/Device.hpp>
#include <drivers/device/i2c.h>
#include <drivers/drv_device.h>
......@@ -119,7 +118,7 @@ int serial_number();
extern device::Device *BATT_SMBUS_I2C_interface(int bus);
typedef device::Device *(*BATT_SMBUS_constructor)(int);
class BATT_SMBUS : public device::CDev
class BATT_SMBUS : public cdev::CDev
{
public:
......@@ -264,9 +263,8 @@ public:
*/
int unseal();
protected:
Device *_interface;
device::Device *_interface;
private:
......@@ -319,4 +317,4 @@ private:
/* Do not allow copy construction or move assignment of this class. */
BATT_SMBUS(const BATT_SMBUS &);
BATT_SMBUS operator=(const BATT_SMBUS &);
};
\ No newline at end of file
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment