39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
#pragma once
|
||
#include <Arduino.h>
|
||
|
||
// Tuning
|
||
#ifndef SLEEP_IMU_IDLE_MS
|
||
#define SLEEP_IMU_IDLE_MS (10UL * 1000UL) // 10 s → gyro off, accel LP
|
||
#endif
|
||
#ifndef SLEEP_DEEP_IDLE_MS
|
||
#define SLEEP_DEEP_IDLE_MS (60UL * 1000UL) // 60 s → system deep sleep (no-BLE only)
|
||
#endif
|
||
|
||
// LSM6DS3 wakeup threshold: 1 LSB = 7.8 mg at ±2 g FS (±2g range).
|
||
#ifndef SLEEP_WAKEUP_THS
|
||
#define SLEEP_WAKEUP_THS 6 // 0–63
|
||
#endif
|
||
|
||
// Number of consecutive 26 Hz samples that must exceed the threshold.
|
||
#ifndef SLEEP_WAKEUP_DUR
|
||
#define SLEEP_WAKEUP_DUR 1 // 0–3
|
||
#endif
|
||
|
||
// GPIO pin connected to LSM6DS3 INT1.
|
||
#ifndef IMU_INT1_PIN
|
||
#define IMU_INT1_PIN PIN_LSM6DS3TR_C_INT1
|
||
#endif
|
||
|
||
// Public state (read-only from main.cpp)
|
||
enum SleepStage : uint8_t {
|
||
SLEEP_AWAKE = 0, // normal full-rate operation
|
||
SLEEP_IMU_LP = 1, // gyro off, accel LP - nRF awake
|
||
SLEEP_DEEP = 2, // system WFE - BLE disconnected only
|
||
};
|
||
|
||
extern volatile SleepStage sleepStage;
|
||
extern volatile bool imuWakeFlag;
|
||
|
||
void sleepManagerInit();
|
||
bool sleepManagerUpdate(unsigned long nowMs, bool idle, bool bleConnected);
|
||
void sleepManagerWakeIMU(); |