Rewrite API change

This commit is contained in:
Theodor Teslia
2023-05-11 13:57:05 +02:00
parent c5eb409d79
commit c7299a8372
2 changed files with 57 additions and 23 deletions

View File

@@ -1,10 +1,15 @@
#include "sta/MS5607.hpp"
namespace sta {
// Forward declaration
uint16_t uint_8BufferTouint16_t(uint8_t* buffer);
MS5607::MS5607(SpiDevice* device, OsrLevel level) {
this->device_ = device;
this->osr_ = level;
this->lastPresVal = -1;
this->adcStartTime = -1;
this->presRead = true;
// Reset device on start-up
this->reset();
@@ -12,17 +17,44 @@ namespace sta {
this->readPROM();
}
void MS5607::requestAdcReadout() {
void MS5607::requestAdcReadout(uint32_t time) {
// Get current state of calculation
if (time-adcStartTime < delayTimes(this->osr_) || !presRead) {
// Time since last adc command is not enough
return;
}
this->device_->beginTransmission();
this->device_->transfer(MS5607::Operations::D1_CONVERSION + 2*this->osr_);
this->device_->endTransmission();
adcStartTime = time;
presRead = false;
}
int32_t MS5607::getPressure(int32_t temp) {
int32_t MS5607::getPressure(int32_t temp, uint32_t time) {
if (time-adcStartTime < delayTimes(this->osr_) || presRead) {
// Time since last adc command is not enough
return lastPresVal;
}
uint8_t buffer[3] = { 0 };
this->device_->beginTransmission();
this->device_->transfer(MS5607::Operations::ADC_RESULT);
this->device_->receive(buffer, 3);
this->device_->endTransmission();
this->presRead = true;
uint32_t d1_val = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
this->requestAdcReadout(time);
return calculatePressure(d1_val, reverseTempCalc(temp));
}
int32_t MS5607::reverseTempCalc(int32_t temp) {
return this->tempsens;
}
// DEPRECATED
@@ -48,14 +80,8 @@ namespace sta {
// Wait for ADC to finish
// Could do sth. else and schedule continuation with scheduler in RTOS
uint8_t buf[1] = { 0 };
do {
*buf = 0;
uint8_t tx[1] = { 0b11111110 };
this->device_->beginTransmission();
this->device_->transfer(tx, buf, 1);
this->device_->endTransmission();
} while (*buf == 0x00);
// TODO: Find out min
sta::delayMs(10);
// Request readout of ADC value
uint8_t d1Arr[3];
@@ -99,14 +125,8 @@ namespace sta {
// Wait for ADC to finish
// Could do sth. else and schedule continuation with scheduler in RTOS
uint8_t buf[1] = { 0 };
do {
*buf = 0;
uint8_t tx[1] = { 0b11111110 };
this->device_->beginTransmission();
this->device_->transfer(tx, buf, 1);
this->device_->endTransmission();
} while (*buf == 0x00);
// TODO: Test out min
sta::delayMs(10);
// Request ADC readout