#pragma once #include #include #include class EnvironmentSensorManager : public SensorManager { protected: static const int MAX_ACTIVE_SENSORS = 16; // Query function pointer + sub-channel index (for multi-channel sensors like INA3221). // Sub-channel is 0 for all single-output sensors. struct ActiveSensor { void (*query)(uint8_t channel, uint8_t sub_channel, CayenneLPP& telemetry); uint8_t sub_channel; }; ActiveSensor _active_sensors[MAX_ACTIVE_SENSORS]; int _active_sensor_count = 0; uint8_t next_available_channel = TELEM_CHANNEL_SELF + 1; bool gps_detected = false; bool gps_active = false; uint32_t gps_update_interval_sec = 1; #if ENV_INCLUDE_GPS // Duty-cycle state. `gps_duty` is the mode; `gps_active` stays the truth // about the receiver being powered, so everything that already reads it // (telemetry, settings) keeps working unchanged. bool gps_duty = false; uint32_t gps_wake_at = 0; // millis of the next sync attempt uint32_t gps_awake_until = 0; // millis the current attempt gives up at LocationProvider* _location; void start_gps(); void stop_gps(); void gpsDutyLoop(); void initBasicGPS(); #ifdef RAK_BOARD void rakGPSInit(); bool gpsIsAwake(uint8_t ioPin); #endif #endif public: #if ENV_INCLUDE_GPS EnvironmentSensorManager(LocationProvider &location): _location(&location){}; LocationProvider* getLocationProvider() { return _location; } void requestLocationRefresh() override; bool isGPSDetected() const override { return gps_detected; } #else EnvironmentSensorManager(){}; #endif bool begin() override; bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; #if ENV_INCLUDE_GPS || defined(ENV_INCLUDE_BME680_BSEC) void loop() override; #endif int getNumSettings() const override; const char* getSettingName(int i) const override; const char* getSettingValue(int i) const override; bool setSettingValue(const char* name, const char* value) override; int scanI2C(char* dest, size_t max_len) override; };