reduce RAM size

This commit is contained in:
Patric Gruber 2024-07-11 15:53:18 +02:00
parent 616926345e
commit e6f0a89202
2 changed files with 21 additions and 22 deletions

View file

@ -5,6 +5,21 @@
using namespace Pinetime::Applications; using namespace Pinetime::Applications;
TickType_t CurrentTaskDelay(HeartRateTask::States state, TickType_t ppgDeltaTms) {
switch (state) {
case HeartRateTask::States::Measuring:
case HeartRateTask::States::BackgroundMeasuring:
return ppgDeltaTms;
case HeartRateTask::States::Running:
return pdMS_TO_TICKS(100);
case HeartRateTask::States::BackgroundWaiting:
return pdMS_TO_TICKS(10000);
default:
return portMAX_DELAY;
}
}
HeartRateTask::HeartRateTask(Drivers::Hrs3300& heartRateSensor, HeartRateTask::HeartRateTask(Drivers::Hrs3300& heartRateSensor,
Controllers::HeartRateController& controller, Controllers::HeartRateController& controller,
Controllers::Settings& settings) Controllers::Settings& settings)
@ -26,10 +41,10 @@ void HeartRateTask::Process(void* instance) {
} }
void HeartRateTask::Work() { void HeartRateTask::Work() {
lastBpm = 0; int lastBpm = 0;
while (true) { while (true) {
TickType_t delay = CurrentTaskDelay(); TickType_t delay = CurrentTaskDelay(state, ppg.deltaTms);
Messages msg; Messages msg;
if (xQueueReceive(messageQueue, &msg, delay) == pdTRUE) { if (xQueueReceive(messageQueue, &msg, delay) == pdTRUE) {
@ -41,7 +56,7 @@ void HeartRateTask::Work() {
HandleWakeUp(); HandleWakeUp();
break; break;
case Messages::StartMeasurement: case Messages::StartMeasurement:
HandleStartMeasurement(); HandleStartMeasurement(&lastBpm);
break; break;
case Messages::StopMeasurement: case Messages::StopMeasurement:
HandleStopMeasurement(); HandleStopMeasurement();
@ -117,12 +132,12 @@ void HeartRateTask::HandleWakeUp() {
} }
} }
void HeartRateTask::HandleStartMeasurement() { void HeartRateTask::HandleStartMeasurement(int* lastBpm) {
switch (state) { switch (state) {
case States::Idle: case States::Idle:
case States::Running: case States::Running:
state = States::Measuring; state = States::Measuring;
lastBpm = 0; *lastBpm = 0;
StartMeasurement(); StartMeasurement();
break; break;
case States::Measuring: case States::Measuring:
@ -201,20 +216,6 @@ void HeartRateTask::HandleSensorData(int* lastBpm) {
} }
} }
TickType_t HeartRateTask::CurrentTaskDelay() {
switch (state) {
case States::Measuring:
case States::BackgroundMeasuring:
return ppg.deltaTms;
case States::Running:
return pdMS_TO_TICKS(100);
case States::BackgroundWaiting:
return pdMS_TO_TICKS(10000);
default:
return portMAX_DELAY;
}
}
TickType_t HeartRateTask::GetHeartRateBackgroundMeasurementIntervalInTicks() { TickType_t HeartRateTask::GetHeartRateBackgroundMeasurementIntervalInTicks() {
int ms; int ms;
switch (settings.GetHeartRateBackgroundMeasurementInterval()) { switch (settings.GetHeartRateBackgroundMeasurementInterval()) {

View file

@ -58,12 +58,11 @@ namespace Pinetime {
void HandleGoToSleep(); void HandleGoToSleep();
void HandleWakeUp(); void HandleWakeUp();
void HandleStartMeasurement(); void HandleStartMeasurement(int* lastBpm);
void HandleStopMeasurement(); void HandleStopMeasurement();
void HandleBackgroundWaiting(); void HandleBackgroundWaiting();
void HandleSensorData(int* lastBpm); void HandleSensorData(int* lastBpm);
TickType_t CurrentTaskDelay();
TickType_t GetHeartRateBackgroundMeasurementIntervalInTicks(); TickType_t GetHeartRateBackgroundMeasurementIntervalInTicks();
bool IsContinuosModeActivated(); bool IsContinuosModeActivated();
@ -78,7 +77,6 @@ namespace Pinetime {
Controllers::Ppg ppg; Controllers::Ppg ppg;
TickType_t backgroundWaitingStart = 0; TickType_t backgroundWaitingStart = 0;
TickType_t measurementStart = 0; TickType_t measurementStart = 0;
int lastBpm = 0;
}; };
} }