Generalized-Core-Counter 3.20
Particle-based generalized core counter firmware
Loading...
Searching...
No Matches
SensorManager Class Reference

#include <SensorManager.h>

Public Member Functions

SensorData getSensorData () const
 Get the latest sensor data from the active sensor.
void initializeFromConfig ()
 Create and initialize the active sensor based on configuration.
bool isSensorReady () const
 Check whether the active sensor is initialized and ready.
bool loop ()
 Poll the active sensor; call from the main loop.
void onEnterSleep ()
 Notify the sensor that the device is entering deep sleep.
void onExitSleep ()
 Notify the sensor that the device has woken from deep sleep.
void setSensor (ISensor *sensor)
 Set the concrete ISensor implementation to use.
void setup ()
 Initialize the active sensor and any manager state.
Utility functions

Helpers for temperature, battery, radio signal, and delays.

float tmp36TemperatureC (int adcValue)
 Convert TMP36 ADC reading to degrees Celsius.
bool readTmp112TemperatureC (float &tempC)
 Read TMP112A temperature (I2C) in degrees Celsius.
bool batteryState ()
 Determine whether the battery is present and not critically low.
bool isItSafeToCharge ()
 Determine whether it is safe to charge the battery.
void getSignalStrength ()
 Update global signal strength strings for logging/telemetry.

Static Public Member Functions

static SensorManagerinstance ()
 Get the SensorManager singleton instance.

Protected Member Functions

SensorManageroperator= (const SensorManager &)=delete
 SensorManager ()
 SensorManager (const SensorManager &)=delete
virtual ~SensorManager ()

Protected Attributes

unsigned long _lastPollTime
 Timestamp of the last sensor poll (millis).
ISensor_sensor
 Currently active sensor implementation (not owned).

Static Protected Attributes

static SensorManager_instance
 Pointer to the singleton instance.

Detailed Description

Definition at line 35 of file SensorManager.h.

Constructor & Destructor Documentation

◆ SensorManager() [1/2]

SensorManager::SensorManager ( )
protected

Definition at line 28 of file SensorManager.cpp.

References _lastPollTime, and _sensor.

Referenced by instance(), operator=(), and SensorManager().

◆ ~SensorManager()

SensorManager::~SensorManager ( )
protectedvirtual

Definition at line 30 of file SensorManager.cpp.

◆ SensorManager() [2/2]

SensorManager::SensorManager ( const SensorManager & )
protecteddelete

References SensorManager().

Member Function Documentation

◆ batteryState()

bool SensorManager::batteryState ( )

Determine whether the battery is present and not critically low.

Definition at line 225 of file SensorManager.cpp.

References batteryContext, current, isItSafeToCharge(), readTmp112TemperatureC(), sysStatus, TMP36_SENSE_PIN, and tmp36TemperatureC().

◆ getSensorData()

SensorData SensorManager::getSensorData ( ) const

Get the latest sensor data from the active sensor.

Definition at line 105 of file SensorManager.cpp.

References _sensor.

◆ getSignalStrength()

void SensorManager::getSignalStrength ( )

Update global signal strength strings for logging/telemetry.

Definition at line 652 of file SensorManager.cpp.

References signalStr.

◆ initializeFromConfig()

void SensorManager::initializeFromConfig ( )

Create and initialize the active sensor based on configuration.

Uses sysStatus.get_sensorType() and SensorFactory to select the concrete implementation, then calls the sensor's initializeHardware().

Definition at line 56 of file SensorManager.cpp.

References _sensor, SensorFactory::createSensor(), setSensor(), and sysStatus.

Referenced by ensureSensorEnabled(), handleSleepingState(), and setup().

◆ instance()

SensorManager & SensorManager::instance ( )
static

Get the SensorManager singleton instance.

Definition at line 22 of file SensorManager.cpp.

References _instance, and SensorManager().

Referenced by ensureSensorEnabled(), handleCountingMode(), handleIdleState(), handleOccupancyMode(), handleSleepingState(), and setup().

◆ isItSafeToCharge()

bool SensorManager::isItSafeToCharge ( )

Determine whether it is safe to charge the battery.

Definition at line 600 of file SensorManager.cpp.

References current, and sysStatus.

Referenced by batteryState().

◆ isSensorReady()

bool SensorManager::isSensorReady ( ) const

Check whether the active sensor is initialized and ready.

Definition at line 112 of file SensorManager.cpp.

References _sensor.

◆ loop()

bool SensorManager::loop ( )

Poll the active sensor; call from the main loop.

Returns
true if new sensor data is available.

Definition at line 78 of file SensorManager.cpp.

References _lastPollTime, _sensor, sensorConfig, and sysStatus.

◆ onEnterSleep()

void SensorManager::onEnterSleep ( )

Notify the sensor that the device is entering deep sleep.

Definition at line 116 of file SensorManager.cpp.

References _sensor, disableModule, and ledPower.

Referenced by handleSleepingState(), and setup().

◆ onExitSleep()

void SensorManager::onExitSleep ( )

Notify the sensor that the device has woken from deep sleep.

Definition at line 132 of file SensorManager.cpp.

References _sensor.

Referenced by ensureSensorEnabled(), and handleSleepingState().

◆ operator=()

SensorManager & SensorManager::operator= ( const SensorManager & )
protecteddelete

References SensorManager().

◆ readTmp112TemperatureC()

bool SensorManager::readTmp112TemperatureC ( float & tempC)

Read TMP112A temperature (I2C) in degrees Celsius.

Intended for platforms/carriers (like Muon) that include an onboard TMP112A temperature sensor.

Parameters
[out]tempCFilled with temperature in degrees Celsius on success.
Returns
true on success, false on I2C error or missing device.

Definition at line 165 of file SensorManager.cpp.

Referenced by batteryState().

◆ setSensor()

void SensorManager::setSensor ( ISensor * sensor)

Set the concrete ISensor implementation to use.

Parameters
sensorPointer to a concrete ISensor (not owned).

Definition at line 47 of file SensorManager.cpp.

References _sensor, and ISensor::getSensorType().

Referenced by initializeFromConfig().

◆ setup()

void SensorManager::setup ( )

Initialize the active sensor and any manager state.

Definition at line 32 of file SensorManager.cpp.

References _sensor.

◆ tmp36TemperatureC()

float SensorManager::tmp36TemperatureC ( int adcValue)

Convert TMP36 ADC reading to degrees Celsius.

Parameters
adcValueRaw ADC value from the TMP36 input.
Returns
Temperature in degrees Celsius.

Definition at line 144 of file SensorManager.cpp.

Referenced by batteryState().

Member Data Documentation

◆ _instance

SensorManager * SensorManager::_instance
staticprotected

Pointer to the singleton instance.

Definition at line 136 of file SensorManager.h.

Referenced by instance().

◆ _lastPollTime

unsigned long SensorManager::_lastPollTime
protected

Timestamp of the last sensor poll (millis).

Definition at line 142 of file SensorManager.h.

Referenced by loop(), and SensorManager().

◆ _sensor

ISensor* SensorManager::_sensor
protected

Currently active sensor implementation (not owned).

Definition at line 139 of file SensorManager.h.

Referenced by getSensorData(), initializeFromConfig(), isSensorReady(), loop(), onEnterSleep(), onExitSleep(), SensorManager(), setSensor(), and setup().


The documentation for this class was generated from the following files: