Handle return code from BMA driver, and set a flag is the initialization fails. This allows to boot InfiniTime even if the device cannot initialize.

This commit is contained in:
Jean-François Milants 2021-04-02 16:56:14 +02:00
parent c7cc47ae30
commit 52a90288fd
7 changed files with 33 additions and 15 deletions

View File

@ -31,3 +31,6 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
} }
return false; return false;
} }
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}

View File

@ -14,13 +14,16 @@ namespace Pinetime {
uint32_t NbSteps() const { return nbSteps; } uint32_t NbSteps() const { return nbSteps; }
bool ShouldWakeUp(bool isSleeping); bool ShouldWakeUp(bool isSleeping);
private: void IsSensorOk(bool isOk);
bool IsSensorOk() const { return isSensorOk; }
private:
uint32_t nbSteps; uint32_t nbSteps;
int16_t x; int16_t x;
int16_t y; int16_t y;
int16_t z; int16_t z;
int16_t lastYForWakeUp = 0; int16_t lastYForWakeUp = 0;
bool isSensorOk = false;
}; };
} }
} }

View File

@ -240,9 +240,13 @@ bool WatchFaceDigital::Refresh() {
} }
stepCount = motionController.NbSteps(); stepCount = motionController.NbSteps();
if(stepCount.IsUpdated()) { motionSensorOk = motionController.IsSensorOk();
if(stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
char stepBuffer[5]; char stepBuffer[5];
sprintf(stepBuffer, "%lu", stepCount.Get()); if(motionSensorOk.Get())
sprintf(stepBuffer, "%lu", stepCount.Get());
else
sprintf(stepBuffer, "---", stepCount.Get());
lv_label_set_text(stepValue, stepBuffer); lv_label_set_text(stepValue, stepBuffer);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2);
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);

View File

@ -50,6 +50,7 @@ namespace Pinetime {
DirtyValue<int> batteryPercentRemaining {}; DirtyValue<int> batteryPercentRemaining {};
DirtyValue<bool> bleState {}; DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{}; DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{};
DirtyValue<bool> motionSensorOk {};
DirtyValue<uint32_t> stepCount {}; DirtyValue<uint32_t> stepCount {};
DirtyValue<uint8_t> heartbeat {}; DirtyValue<uint8_t> heartbeat {};
DirtyValue<bool> heartbeatRunning {}; DirtyValue<bool> heartbeatRunning {};

View File

@ -36,27 +36,27 @@ Bma421::Bma421(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster{twiMaster},
void Bma421::Init() { void Bma421::Init() {
auto ret = bma4_soft_reset(&bma); auto ret = bma4_soft_reset(&bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
nrf_delay_ms(1); nrf_delay_ms(1);
ret = bma423_init(&bma); ret = bma423_init(&bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
ret = bma423_write_config_file(&bma); ret = bma423_write_config_file(&bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
ret = bma4_set_interrupt_mode(BMA4_LATCH_MODE, &bma); ret = bma4_set_interrupt_mode(BMA4_LATCH_MODE, &bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
ret = bma423_feature_enable(BMA423_STEP_CNTR, 1, &bma); ret = bma423_feature_enable(BMA423_STEP_CNTR, 1, &bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
ret = bma423_step_detector_enable(0, &bma); ret = bma423_step_detector_enable(0, &bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
ret = bma4_set_accel_enable(1, &bma); ret = bma4_set_accel_enable(1, &bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
struct bma4_accel_config accel_conf; struct bma4_accel_config accel_conf;
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ; accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
@ -64,7 +64,9 @@ void Bma421::Init() {
accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4; accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
accel_conf.perf_mode = BMA4_CIC_AVG_MODE; accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
ret = bma4_set_accel_config(&accel_conf, &bma); ret = bma4_set_accel_config(&accel_conf, &bma);
ASSERT(ret == BMA4_OK); if(ret != BMA4_OK) return;
isOk = true;
} }
void Bma421::Reset() { void Bma421::Reset() {
@ -81,6 +83,7 @@ void Bma421::Write(uint8_t registerAddress, const uint8_t *data, size_t size) {
} }
Bma421::Values Bma421::Process() { Bma421::Values Bma421::Process() {
if(not isOk) return {};
struct bma4_accel data; struct bma4_accel data;
bma4_read_accel_xyz(&data, &bma); bma4_read_accel_xyz(&data, &bma);
@ -99,4 +102,6 @@ Bma421::Values Bma421::Process() {
// X and Y axis are swapped because of the way the sensor is mounted in the PineTime // X and Y axis are swapped because of the way the sensor is mounted in the PineTime
return {steps, data.y, data.x, data.z}; return {steps, data.y, data.x, data.z};
} }
bool Bma421::IsOk() const {
return isOk;
}

View File

@ -25,12 +25,13 @@ namespace Pinetime {
void Read(uint8_t registerAddress, uint8_t *buffer, size_t size); void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
void Write(uint8_t registerAddress, const uint8_t *data, size_t size); void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
bool IsOk() const;
private: private:
TwiMaster& twiMaster; TwiMaster& twiMaster;
uint8_t deviceAddress = 0x18; uint8_t deviceAddress = 0x18;
struct bma4_dev bma; struct bma4_dev bma;
bool isOk = false;
}; };
} }
} }

View File

@ -243,6 +243,7 @@ void SystemTask::UpdateMotion() {
if(isSleeping) if(isSleeping)
twiMaster.Sleep(); twiMaster.Sleep();
motionController.IsSensorOk(motionSensor.IsOk());
motionController.Update(motionValues.x, motionController.Update(motionValues.x,
motionValues.y, motionValues.y,
motionValues.z, motionValues.z,