mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-07 02:51:36 +08:00
trone: fixed code style
This commit is contained in:
+24
-23
@@ -212,7 +212,8 @@ static const uint8_t crc_table[] = {
|
|||||||
0xfa, 0xfd, 0xf4, 0xf3
|
0xfa, 0xfd, 0xf4, 0xf3
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t crc8(uint8_t *p, uint8_t len) {
|
static uint8_t crc8(uint8_t *p, uint8_t len)
|
||||||
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint16_t crc = 0x0;
|
uint16_t crc = 0x0;
|
||||||
|
|
||||||
@@ -301,7 +302,7 @@ TRONE::init()
|
|||||||
_reports->get(&ds_report);
|
_reports->get(&ds_report);
|
||||||
|
|
||||||
_distance_sensor_topic = orb_advertise_multi(ORB_ID(distance_sensor), &ds_report,
|
_distance_sensor_topic = orb_advertise_multi(ORB_ID(distance_sensor), &ds_report,
|
||||||
&_orb_class_instance, ORB_PRIO_LOW);
|
&_orb_class_instance, ORB_PRIO_LOW);
|
||||||
|
|
||||||
if (_distance_sensor_topic == nullptr) {
|
if (_distance_sensor_topic == nullptr) {
|
||||||
DEVICE_LOG("failed to create distance_sensor object. Did you start uOrb?");
|
DEVICE_LOG("failed to create distance_sensor object. Did you start uOrb?");
|
||||||
@@ -318,23 +319,23 @@ out:
|
|||||||
int
|
int
|
||||||
TRONE::probe()
|
TRONE::probe()
|
||||||
{
|
{
|
||||||
uint8_t who_am_i=0;
|
uint8_t who_am_i = 0;
|
||||||
|
|
||||||
const uint8_t cmd = TRONE_WHO_AM_I_REG;
|
const uint8_t cmd = TRONE_WHO_AM_I_REG;
|
||||||
|
|
||||||
// set the I2C bus address
|
// set the I2C bus address
|
||||||
set_address(TRONE_BASEADDR);
|
set_address(TRONE_BASEADDR);
|
||||||
|
|
||||||
// can't use a single transfer as TROne need a bit of time for internal processing
|
// can't use a single transfer as TROne need a bit of time for internal processing
|
||||||
if (transfer(&cmd, 1, nullptr, 0) == OK) {
|
if (transfer(&cmd, 1, nullptr, 0) == OK) {
|
||||||
if ( transfer(nullptr, 0, &who_am_i, 1) == OK && who_am_i == TRONE_WHO_AM_I_REG_VAL){
|
if (transfer(nullptr, 0, &who_am_i, 1) == OK && who_am_i == TRONE_WHO_AM_I_REG_VAL) {
|
||||||
return measure();
|
return measure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEVICE_DEBUG("WHO_AM_I byte mismatch 0x%02x should be 0x%02x\n",
|
DEVICE_DEBUG("WHO_AM_I byte mismatch 0x%02x should be 0x%02x\n",
|
||||||
(unsigned)who_am_i,
|
(unsigned)who_am_i,
|
||||||
TRONE_WHO_AM_I_REG_VAL);
|
TRONE_WHO_AM_I_REG_VAL);
|
||||||
|
|
||||||
// not found on any address
|
// not found on any address
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -596,7 +597,7 @@ TRONE::collect()
|
|||||||
|
|
||||||
// This validation check can be used later
|
// This validation check can be used later
|
||||||
_valid = crc8(val, 2) == val[2] && (float)report.current_distance > report.min_distance
|
_valid = crc8(val, 2) == val[2] && (float)report.current_distance > report.min_distance
|
||||||
&& (float)report.current_distance < report.max_distance ? 1 : 0;
|
&& (float)report.current_distance < report.max_distance ? 1 : 0;
|
||||||
|
|
||||||
/* publish it, if we are the primary */
|
/* publish it, if we are the primary */
|
||||||
if (_distance_sensor_topic != nullptr) {
|
if (_distance_sensor_topic != nullptr) {
|
||||||
@@ -680,10 +681,10 @@ TRONE::cycle()
|
|||||||
if (_measure_ticks > USEC2TICK(TRONE_CONVERSION_INTERVAL)) {
|
if (_measure_ticks > USEC2TICK(TRONE_CONVERSION_INTERVAL)) {
|
||||||
/* schedule a fresh cycle call when we are ready to measure again */
|
/* schedule a fresh cycle call when we are ready to measure again */
|
||||||
work_queue(HPWORK,
|
work_queue(HPWORK,
|
||||||
&_work,
|
&_work,
|
||||||
(worker_t)&TRONE::cycle_trampoline,
|
(worker_t)&TRONE::cycle_trampoline,
|
||||||
this,
|
this,
|
||||||
_measure_ticks - USEC2TICK(TRONE_CONVERSION_INTERVAL));
|
_measure_ticks - USEC2TICK(TRONE_CONVERSION_INTERVAL));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -699,10 +700,10 @@ TRONE::cycle()
|
|||||||
|
|
||||||
/* schedule a fresh cycle call when the measurement is done */
|
/* schedule a fresh cycle call when the measurement is done */
|
||||||
work_queue(HPWORK,
|
work_queue(HPWORK,
|
||||||
&_work,
|
&_work,
|
||||||
(worker_t)&TRONE::cycle_trampoline,
|
(worker_t)&TRONE::cycle_trampoline,
|
||||||
this,
|
this,
|
||||||
USEC2TICK(TRONE_CONVERSION_INTERVAL));
|
USEC2TICK(TRONE_CONVERSION_INTERVAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user