sensor_lis2dw: No need to send messages when stopping queries
Simplify the mcu code as any messages are ignored by the host anyway. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
5ff555a705
commit
95e1a290f1
|
@ -48,7 +48,7 @@ class LIS2DW:
|
||||||
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000)
|
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000)
|
||||||
self.mcu = mcu = self.spi.get_mcu()
|
self.mcu = mcu = self.spi.get_mcu()
|
||||||
self.oid = oid = mcu.create_oid()
|
self.oid = oid = mcu.create_oid()
|
||||||
self.query_lis2dw_cmd = self.query_lis2dw_end_cmd = None
|
self.query_lis2dw_cmd = None
|
||||||
self.query_lis2dw_status_cmd = None
|
self.query_lis2dw_status_cmd = None
|
||||||
mcu.add_config_cmd("config_lis2dw oid=%d spi_oid=%d"
|
mcu.add_config_cmd("config_lis2dw oid=%d spi_oid=%d"
|
||||||
% (oid, self.spi.get_oid()))
|
% (oid, self.spi.get_oid()))
|
||||||
|
@ -75,10 +75,6 @@ class LIS2DW:
|
||||||
cmdqueue = self.spi.get_command_queue()
|
cmdqueue = self.spi.get_command_queue()
|
||||||
self.query_lis2dw_cmd = self.mcu.lookup_command(
|
self.query_lis2dw_cmd = self.mcu.lookup_command(
|
||||||
"query_lis2dw oid=%c clock=%u rest_ticks=%u", cq=cmdqueue)
|
"query_lis2dw oid=%c clock=%u rest_ticks=%u", cq=cmdqueue)
|
||||||
self.query_lis2dw_end_cmd = self.mcu.lookup_query_command(
|
|
||||||
"query_lis2dw oid=%c clock=%u rest_ticks=%u",
|
|
||||||
"lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
|
||||||
" buffered=%c fifo=%c limit_count=%hu", oid=self.oid, cq=cmdqueue)
|
|
||||||
self.query_lis2dw_status_cmd = self.mcu.lookup_query_command(
|
self.query_lis2dw_status_cmd = self.mcu.lookup_query_command(
|
||||||
"query_lis2dw_status oid=%c",
|
"query_lis2dw_status oid=%c",
|
||||||
"lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
"lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
||||||
|
@ -179,7 +175,7 @@ class LIS2DW:
|
||||||
self.last_error_count = 0
|
self.last_error_count = 0
|
||||||
def _finish_measurements(self):
|
def _finish_measurements(self):
|
||||||
# Halt bulk reading
|
# Halt bulk reading
|
||||||
params = self.query_lis2dw_end_cmd.send([self.oid, 0, 0])
|
self.query_lis2dw_cmd.send_wait_ack([self.oid, 0, 0])
|
||||||
self.bulk_queue.clear_samples()
|
self.bulk_queue.clear_samples()
|
||||||
logging.info("LIS2DW finished '%s' measurements", self.name)
|
logging.info("LIS2DW finished '%s' measurements", self.name)
|
||||||
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0x00)
|
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0x00)
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct lis2dw {
|
||||||
uint32_t rest_ticks;
|
uint32_t rest_ticks;
|
||||||
struct spidev_s *spi;
|
struct spidev_s *spi;
|
||||||
uint16_t sequence, limit_count;
|
uint16_t sequence, limit_count;
|
||||||
uint8_t flags, data_count, fifo_disable;
|
uint8_t flags, data_count;
|
||||||
uint8_t data[48];
|
uint8_t data[48];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ lis2dw_query(struct lis2dw *ax, uint8_t oid)
|
||||||
ax->limit_count++;
|
ax->limit_count++;
|
||||||
|
|
||||||
// check if we need to run the task again (more packets in fifo?)
|
// check if we need to run the task again (more packets in fifo?)
|
||||||
if (!fifo_empty&&!(ax->fifo_disable)) {
|
if (!fifo_empty) {
|
||||||
// More data in fifo - wake this task again
|
// More data in fifo - wake this task again
|
||||||
sched_wake_task(&lis2dw_wake);
|
sched_wake_task(&lis2dw_wake);
|
||||||
} else if (ax->flags & LIS_RUNNING) {
|
} else if (ax->flags & LIS_RUNNING) {
|
||||||
|
@ -134,7 +134,6 @@ lis2dw_start(struct lis2dw *ax, uint8_t oid)
|
||||||
{
|
{
|
||||||
sched_del_timer(&ax->timer);
|
sched_del_timer(&ax->timer);
|
||||||
ax->flags = LIS_RUNNING;
|
ax->flags = LIS_RUNNING;
|
||||||
ax->fifo_disable = 0;
|
|
||||||
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0xC0};
|
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0xC0};
|
||||||
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
||||||
lis2dw_reschedule_timer(ax);
|
lis2dw_reschedule_timer(ax);
|
||||||
|
@ -147,23 +146,8 @@ lis2dw_stop(struct lis2dw *ax, uint8_t oid)
|
||||||
// Disable measurements
|
// Disable measurements
|
||||||
sched_del_timer(&ax->timer);
|
sched_del_timer(&ax->timer);
|
||||||
ax->flags = 0;
|
ax->flags = 0;
|
||||||
// Drain any measurements still in fifo
|
|
||||||
ax->fifo_disable = 1;
|
|
||||||
lis2dw_query(ax, oid);
|
|
||||||
|
|
||||||
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0};
|
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0};
|
||||||
uint32_t end1_time = timer_read_time();
|
|
||||||
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
||||||
uint32_t end2_time = timer_read_time();
|
|
||||||
|
|
||||||
uint8_t msg[2] = { LIS_FIFO_SAMPLES | LIS_AM_READ , 0};
|
|
||||||
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
|
|
||||||
uint8_t fifo_status = msg[1]&0x1f;
|
|
||||||
|
|
||||||
//Report final data
|
|
||||||
if (ax->data_count)
|
|
||||||
lis2dw_report(ax, oid);
|
|
||||||
lis2dw_status(ax, oid, end1_time, end2_time, fifo_status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -183,7 +167,6 @@ command_query_lis2dw(uint32_t *args)
|
||||||
ax->flags = LIS_HAVE_START;
|
ax->flags = LIS_HAVE_START;
|
||||||
ax->sequence = ax->limit_count = 0;
|
ax->sequence = ax->limit_count = 0;
|
||||||
ax->data_count = 0;
|
ax->data_count = 0;
|
||||||
ax->fifo_disable = 0;
|
|
||||||
sched_add_timer(&ax->timer);
|
sched_add_timer(&ax->timer);
|
||||||
}
|
}
|
||||||
DECL_COMMAND(command_query_lis2dw,
|
DECL_COMMAND(command_query_lis2dw,
|
||||||
|
|
Loading…
Reference in New Issue