Skip to content

Commit

Permalink
Implemented step-statistics support in emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro committed Sep 8, 2022
1 parent bfffc0c commit 3f52c86
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ target_compile_definitions(emulator.run PUBLIC
$<$<CONFIG:Release>:
NDEBUG=1
>
# Comment these as you wish...
OSW_FEATURE_STATS_STEPS
)
target_compile_options(emulator.run PUBLIC
$<$<CONFIG:Debug>:
Expand Down
3 changes: 2 additions & 1 deletion include/devices/bma400.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BMA400 : public OswTemperatureProvider, public OswAccelerationProvider {

virtual void setup() override;
virtual void update() override;
virtual void reset() override;
virtual void reset() override {};
virtual void stop() override {};

virtual inline const char* getName() override {
Expand All @@ -24,6 +24,7 @@ class BMA400 : public OswTemperatureProvider, public OswAccelerationProvider {
}; // This sensor is not sooo good...

virtual uint32_t getStepCount() override;
virtual void resetStepCount() override;
virtual float getAccelerationX() override;
virtual float getAccelerationY() override;
virtual float getAccelerationZ() override;
Expand Down
1 change: 1 addition & 0 deletions include/devices/interfaces/OswAccelerationProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class OswAccelerationProvider : public OswDevice {
public:
virtual uint32_t getStepCount() = 0;
virtual void resetStepCount() = 0;
virtual float getAccelerationX() = 0;
virtual float getAccelerationY() = 0;
virtual float getAccelerationZ() = 0;
Expand Down
3 changes: 3 additions & 0 deletions include/devices/virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Virtual : public OswTemperatureProvider, public OswAccelerationProvider, p
virtual inline uint32_t getStepCount() override {
return this->values.steps;
};
virtual void resetStepCount() override {
this->values.steps = 0;
};
virtual inline float getAccelerationX() override {
return this->values.accelerationX;
};
Expand Down
1 change: 1 addition & 0 deletions include/hal/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OswHal::Environment {
// Statistics: Steps
void setupStepStatistics();
uint32_t getStepsToday();
void resetStepCount();
uint32_t getStepsTotal();
uint32_t getStepsTotalWeek();
#ifdef OSW_FEATURE_STATS_STEPS
Expand Down
4 changes: 2 additions & 2 deletions src/devices/bma400.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void IRAM_ATTR isrTap() {
#endif
}

void OswDevices::BMA400::reset() {
void OswDevices::BMA400::resetStepCount() {
int8_t rslt = bma400_soft_reset(&bma);
bma400_check_rslt("bma400_soft_reset", rslt);
step_count = 0;
Expand Down Expand Up @@ -325,7 +325,7 @@ float OswDevices::BMA400::getAccelerationX() {
#else
return accelY;
#endif
}
}r

float OswDevices::BMA400::getAccelerationY() {
#if defined(GPS_EDITION)
Expand Down
15 changes: 8 additions & 7 deletions src/hal/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ void OswHal::Environment::setupStepStatistics() {
const uint32_t currentSteps = this->getStepsToday();
this->_stepsCache[lastDoW] = currentSteps; // write current step to last dow
this->_stepsSum += currentSteps; // Let's just hope this never rolls over...
#if OSW_PLATFORM_HARDWARE_BMA400 == 1
if(OswHal::getInstance()->devices->bma400 == this->accelSensor)
OswHal::getInstance()->devices->bma400->reset();
#else
#warning "Are you sure your acceleration provider does not need to be reset?"
#endif
OswHal::getInstance()->environment->resetStepCount();
if(OswConfigAllKeys::stepsHistoryClear.get()) {
if(currDoW > lastDoW) {
// set stepscache to 0 in ]lastDoW, currDoW[
Expand Down Expand Up @@ -154,7 +149,7 @@ void OswHal::Environment::setupStepStatistics() {
}
prefs.end();
#ifndef NDEBUG
Serial.print(String(__FILE__) + ": Current step history (day " + String(currDoW) + ", today " + String(OswHal::getInstance()->devices->bma400->getStepCount()) + ", sum " + String(this->_stepsSum) + ") is: {");
Serial.print(String(__FILE__) + ": Current step history (day " + String(currDoW) + ", today " + String(OswHal::getInstance()->environment->getStepsToday()) + ", sum " + String(this->_stepsSum) + ") is: {");
for(size_t i = 0; i < 7; i++) {
if(i > 0)
Serial.print(", ");
Expand All @@ -175,6 +170,12 @@ uint32_t OswHal::Environment::getStepsToday() {
return this->accelSensor->getStepCount();
}

void OswHal::Environment::resetStepCount() {
if(!this->accelSensor)
throw std::runtime_error("No acceleration provider!");
return this->accelSensor->resetStepCount();
}

#ifdef OSW_FEATURE_STATS_STEPS
uint32_t OswHal::Environment::getStepsOnDay(uint8_t dayOfWeek, bool lastWeek) {
uint32_t day = 0;
Expand Down

0 comments on commit 3f52c86

Please sign in to comment.