]> Devi Nivas Git - smartwatch.git/commitdiff
pedometer + calories task_imu
authorGajula, Anish <agajula7@gatech.edu>
Tue, 25 Nov 2025 07:03:53 +0000 (02:03 -0500)
committerGajula, Anish <agajula7@gatech.edu>
Tue, 25 Nov 2025 07:03:53 +0000 (02:03 -0500)
.gitignore
README
main/task_imu.c

index d0e8a429e999a87880eed6fdce5e7fede22cf9a5..5d362fbf0b4c152758f09335aabcfeb3834ebe32 100644 (file)
@@ -19,3 +19,4 @@ dependencies.lock
 
 .vscode/
 managed_components/
+
diff --git a/README b/README
index b6d02092e6ed8cb83dc383b7378b355aacd71b93..98ac93fda4bf4e42bac07ece2ea2c7344b7e5524 100644 (file)
--- a/README
+++ b/README
@@ -11,14 +11,15 @@ Task List
 ===========
 
 Anish 
-- Pedometer
+
 - Workouts App
-- Compass
 - RTC & AM/PM logic
 - Rings (Move, Exercise, and Standing) (extra)
 - Snake Game (extra)
 - Messaging (extra)
 - 2035le (extra)
+- Pedometer 
+- Calories burned
 
 Advaith
 - Button Shortcuts
index d9435c8036c4ac53ea366bef7a382220f53399e7..80f616b86d6b4c755b4e275657fbe5d32228bd87 100644 (file)
@@ -25,12 +25,55 @@ i2c_config_t conf = {
        .clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
 };
 
+static int step_count = 0;
+static bool is_paused = false;
+static uint32_t pause_start_ms = 0;
+
+ const int16_t SWING_THRESHOLD = 15000;  
+ const uint32_t PAUSE_DURATION_MS = 500;
+
 /* ICM 20948 configuration */
 icm0948_config_i2c_t icm_config = {
        .i2c_port = I2C_NUM_0,
        .i2c_addr = ICM_20948_I2C_ADDR_AD1
 };
 
+void step_counter(icm20948_agmt_t agmt) {
+
+    int16_t x = agmt.acc.axes.x;  // x-axis
+    if (x < 0) x = -x;            // absolute value 
+
+    uint32_t now_ms = xTaskGetTickCount() * portTICK_PERIOD_MS;
+
+    // If currently paused, check if time is up
+    if (is_paused) {
+        if (now_ms - pause_start_ms >= PAUSE_DURATION_MS) {
+            is_paused = false;   // pause finished
+        }
+        return;  // idling
+    }
+
+    // check for the arm movement 
+    if (x >= SWING_THRESHOLD) {
+        step_count += 2;  // add 2 steps 
+        ESP_LOGI(TAG, "Swing detected. Total steps: %d", step_count);
+
+        is_paused = true;  // add a buffer to prevent over counting
+        pause_start_ms = now_ms; 
+    }
+
+}
+
+float calculate_calories_from_steps(int steps, float height_cm, float weight_kg) {
+
+    float stride_m = (height_cm / 100.0f) * 0.415f;
+
+    float distance_m = steps * stride_m;
+
+    float calories = (distance_m / 1000.0f) * weight_kg * 0.55f;
+
+    return calories;
+}
 
 void print_agmt(icm20948_agmt_t agmt)
 {
@@ -110,6 +153,8 @@ void task_imu_all(void *)
                icm20948_agmt_t agmt; // = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0}};
                if (icm20948_get_agmt(&icm, &agmt) == ICM_20948_STAT_OK) {
                        print_agmt(agmt);
+            step_counter(agmt);
+                       ESP_LOGI(TAG, "Calories burned: %.2f kcal\n Step Count: %d", calculate_calories_from_steps(step_count, 170.0f, 65.5f), step_count);
                } else {
                        ESP_LOGE(TAG, "Uh oh");
                }