sensor_adxl345: 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:
Kevin O'Connor 2023-12-17 11:30:23 -05:00
parent 83d0d2f19b
commit 3275614b89
2 changed files with 2 additions and 24 deletions

View File

@ -204,7 +204,7 @@ class ADXL345:
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_adxl345_cmd = self.query_adxl345_end_cmd = None self.query_adxl345_cmd = None
self.query_adxl345_status_cmd = None self.query_adxl345_status_cmd = None
mcu.add_config_cmd("config_adxl345 oid=%d spi_oid=%d" mcu.add_config_cmd("config_adxl345 oid=%d spi_oid=%d"
% (oid, self.spi.get_oid())) % (oid, self.spi.get_oid()))
@ -230,10 +230,6 @@ class ADXL345:
cmdqueue = self.spi.get_command_queue() cmdqueue = self.spi.get_command_queue()
self.query_adxl345_cmd = self.mcu.lookup_command( self.query_adxl345_cmd = self.mcu.lookup_command(
"query_adxl345 oid=%c clock=%u rest_ticks=%u", cq=cmdqueue) "query_adxl345 oid=%c clock=%u rest_ticks=%u", cq=cmdqueue)
self.query_adxl345_end_cmd = self.mcu.lookup_query_command(
"query_adxl345 oid=%c clock=%u rest_ticks=%u",
"adxl345_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_adxl345_status_cmd = self.mcu.lookup_query_command( self.query_adxl345_status_cmd = self.mcu.lookup_query_command(
"query_adxl345_status oid=%c", "query_adxl345_status oid=%c",
"adxl345_status oid=%c clock=%u query_ticks=%u next_sequence=%hu" "adxl345_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
@ -334,7 +330,7 @@ class ADXL345:
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_adxl345_end_cmd.send([self.oid, 0, 0]) self.query_adxl345_cmd.send_wait_ack([self.oid, 0, 0])
self.bulk_queue.clear_samples() self.bulk_queue.clear_samples()
logging.info("ADXL345 finished '%s' measurements", self.name) logging.info("ADXL345 finished '%s' measurements", self.name)
def _process_batch(self, eventtime): def _process_batch(self, eventtime):

View File

@ -148,25 +148,7 @@ adxl_stop(struct adxl345 *ax, uint8_t oid)
sched_del_timer(&ax->timer); sched_del_timer(&ax->timer);
ax->flags = 0; ax->flags = 0;
uint8_t msg[2] = { AR_POWER_CTL, 0x00 }; uint8_t msg[2] = { AR_POWER_CTL, 0x00 };
uint32_t end1_time = timer_read_time();
spidev_transfer(ax->spi, 0, sizeof(msg), msg); spidev_transfer(ax->spi, 0, sizeof(msg), msg);
uint32_t end2_time = timer_read_time();
// Drain any measurements still in fifo
uint_fast8_t i;
for (i=0; i<33; i++) {
msg[0] = AR_FIFO_STATUS | AM_READ;
msg[1] = 0x00;
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
uint_fast8_t fifo_status = msg[1] & ~0x80;
if (!fifo_status)
break;
if (fifo_status <= 32)
adxl_query(ax, oid);
}
// Report final data
if (ax->data_count)
adxl_report(ax, oid);
adxl_status(ax, oid, end1_time, end2_time, msg[1]);
} }
void void