Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
43965c6e
Commit
43965c6e
authored
6 years ago
by
Daniel Agar
Browse files
Options
Downloads
Patches
Plain Diff
batt_smbus cleanup unnecessary Device CDev usage
parent
9b2274ea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/drivers/batt_smbus/batt_smbus.cpp
+7
-11
7 additions, 11 deletions
src/drivers/batt_smbus/batt_smbus.cpp
src/drivers/batt_smbus/batt_smbus.h
+4
-6
4 additions, 6 deletions
src/drivers/batt_smbus/batt_smbus.h
with
11 additions
and
17 deletions
src/drivers/batt_smbus/batt_smbus.cpp
+
7
−
11
View file @
43965c6e
...
...
@@ -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.0
f
),
_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
}
This diff is collapsed.
Click to expand it.
src/drivers/batt_smbus/batt_smbus.h
+
4
−
6
View file @
43965c6e
...
...
@@ -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
dev
ice
::
CDev
class
BATT_SMBUS
:
public
c
dev
::
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
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment