LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
BsdSensor Class Reference

Encapsulates one BSD channel (sense + decision + actuation). More...

#include <BsdSensor.h>

Public Member Functions

 BsdSensor (uint8_t index, int sensePin, int gatePin)
 Construct a sensor. More...
 
void begin (BsdRelay *pRelay)
 Initialize hardware and internal state. More...
 
void update (uint16_t occLow_mA, uint16_t occHigh_mA)
 Advance the sensor state machine and measurements. More...
 
SensorState state () const
 Current state of the channel.
 
bool isShorted () const
 Returns true when the channel is tripped or lockout (rail disconnected).
 
bool isOccupied () const
 Returns true when filtered current exceeds occLow_mA.
 
float currentA () const
 Returns the filtered current estimate in Amps (if ADC_REF_V / ACS_SENS are in SI).
 
void setState (SensorState s)
 Set the channel state and actuate outputs accordingly. More...
 
void setOccupied (bool occ)
 Override the occupancy flag (primarily for tests).
 
void reset ()
 Clear a fault and return to OK (power path enabled, inrush blanking starts).
 

Private Member Functions

bool _inInrush (uint32_t now) const
 True while still in the inrush blanking window. More...
 
float _readCurrentA () const
 Sample ADC three times, average, convert to volts and then Amps. More...
 

Private Attributes

BsdRelay * pRelay_ = nullptr
 Optional relay driver attached via. More...
 
uint16_t occHigh_mA = 0
 Last trip threshold passed to update (see note below).
 
uint8_t idx_ = 0
 Channel index (informational).
 
int sensePin_ = -1
 ADC1 input pin for current sense.
 
int gatePin_ = -1
 MOSFET gate output (HIGH=ON).
 
float current_filtered_A_ = 0.0f
 IIR filtered current (Amps).
 
uint8_t retry_stage_ = 0
 0..RETRY_MAX-1 retry stage.
 
uint32_t last_sample_ms_ = 0
 Last sample timestamp.
 
uint32_t unblank_at_ms_ = 0
 Timestamp when inrush blanking ENDS.
 
uint32_t next_retry_ms_ = 0
 Next retry timestamp.
 
bool isOccupied_ = false
 Occupancy flag (spelling kept for compatibility).
 

Detailed Description

Encapsulates one BSD channel (sense + decision + actuation).

Typical lifecycle:

  1. Construct with channel index, sense pin (ADC1), and gate pin.
  2. Call begin once at startup.
  3. Call update repeatedly (e.g., from loop), passing the short trip threshold.
  4. Read isOccupied and isShorted for host-visible status.

Definition at line 73 of file BsdSensor.h.

Constructor & Destructor Documentation

◆ BsdSensor()

BsdSensor::BsdSensor ( uint8_t  index,
int  sensePin,
int  gatePin 
)
inline

Construct a sensor.

Parameters
indexChannel index (0..7); informational only.
sensePinADC1 pin connected to the current sensor output.
gatePinDigital output pin that drives the MOSFET gate (HIGH=ON).

Definition at line 81 of file BsdSensor.h.

Member Function Documentation

◆ _inInrush()

bool BsdSensor::_inInrush ( uint32_t  now) const
inlineprivate

True while still in the inrush blanking window.

Parameters
nowCurrent millis() value.

Definition at line 262 of file BsdSensor.h.

Here is the caller graph for this function:

◆ _readCurrentA()

float BsdSensor::_readCurrentA ( ) const
inlineprivate

Sample ADC three times, average, convert to volts and then Amps.

Returns
Absolute current in Amps (assumes midpoint ADC_REF_V/2 and sensitivity ACS_SENS).

Definition at line 270 of file BsdSensor.h.

Here is the caller graph for this function:

◆ begin()

void BsdSensor::begin ( BsdRelay *  pRelay)
inline

Initialize hardware and internal state.

Sets gate pin as OUTPUT, initializes state to SensorState OK, zeros filters and timers, and applies an initial inrush blanking window.

Note
If you are not attaching a BsdRelay.h, ensure the gate pin is driven HIGH somewhere (e.g., call setState(SensorState OK)) to connect the rail at power-up.
Parameters
pRelayPointer to a BsdRelay.h for this channel (or nullptr to detach).

Definition at line 95 of file BsdSensor.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setState()

void BsdSensor::setState ( SensorState  s)
inline

Set the channel state and actuate outputs accordingly.

When moving to SensorState OK, the power path is enabled and a new inrush blanking window is started. When moving to TRIPPED/LOCKOUT, the power path is disabled and occupancy is cleared.

Parameters
sDesired state.

Definition at line 194 of file BsdSensor.h.

Here is the caller graph for this function:

◆ update()

void BsdSensor::update ( uint16_t  occLow_mA,
uint16_t  occHigh_mA 
)
inline

Advance the sensor state machine and measurements.

Samples current, updates filters, updates occupancy, and manages short/overcurrent detection and retry/lockout behavior.

Parameters
occLow_mALower threshold for occupancy detection (below this is unoccupied)
occHigh_mAHigh threshold for occupancy detection (above this is a short)
Note
Enforces a minimum sample cadence of SAMPLE_PERIOD_MS.

Definition at line 116 of file BsdSensor.h.

Here is the call graph for this function:

Member Data Documentation

◆ pRelay_

BsdRelay* BsdSensor::pRelay_ = nullptr
private

Optional relay driver attached via.

See also
attachRelay().

Definition at line 224 of file BsdSensor.h.


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