Skip to content

Class OpenSkyhawk::AnalogInput

ClassList > OpenSkyhawk > AnalogInput

Continuous analog input — one analog PinRef , normalised to a 16-bit value 0..65535. Emits the smoothed value over CAN (MULTIPOS transport). Self-registers intoPanelGroup 'sInputBase list.More...

  • #include <AnalogInput.h>

Inherits the following classes: OpenSkyhawk::InputBase

Public Static Attributes

Type Name
constexpr uint8_t DEFAULT_EWMA_SHIFT = 3
EWMA α = 1/2^3 = 1/8.
constexpr uint16_t DEFAULT_HYSTERESIS = 128
counts on the 16-bit output.
constexpr uint16_t DEFAULT_POLL_MS = 8
default min interval between ADC reads (ms).
constexpr uint8_t MAX_EWMA_SHIFT = 15
cap: scaled<<shift must fit int32 at full scale.

Public Functions

Type Name
AnalogInput (uint16_t controlId, PinRef pin, bool reverse=false, uint16_t minRaw=0, uint16_t maxRaw=65535, uint16_t hysteresis=DEFAULT_HYSTERESIS, uint8_t ewmaShift=DEFAULT_EWMA_SHIFT, uint16_t pollMs=DEFAULT_POLL_MS)
Construct a continuous analog input.
virtual void configure () override
Configure the pin as an input. Called by PanelGroup::setup() .
virtual void forceReport () override
Sample fresh (bypassing the throttle) and emit the current value as the baseline.
virtual void poll () override
Throttled ADC read + EWMA; emit when the value clears the hysteresis or a rail.

Public Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
virtual void configure ()
Configure hardware pins for this input.
virtual void forceReport () = 0
Read hardware state and emit a CAN EVT unconditionally.
InputBase * next () const
Next input in the list; nullptr at end.
virtual void poll () = 0
Read hardware state and emit a CAN EVT if state changed.
virtual void sampleTick ()
High-rate sample hook — called from a sampling ISR when the node runs one (e.g. ShiftBus timer sampling, -DSHIFTBUS_ISR_HZ). Default no-op.

Public Static Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
InputBase * head ()
Head of the self-registered linked list.

Protected Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
InputBase ()
Registers this instance into the linked list.

Detailed Description

A linear input, not a selector. It shares the MULTIPOS wire transport with the selector family only because DCS-BIOS set_state has no separate "continuous" dispatch — the 16-bit value is the control position, not an index.

Read path (ports DcsBios PotentiometerEWMA): read the ADC (already 16-bit — STM32 ×16 or ADS1115 ×2), clamp to [minRaw, maxRaw], map to 0..65535 (reverse-aware), then apply an integer EWMA low-pass filter (α = 1/2^ewmaShift). A new value is emitted only when the smoothed value moves more than hysteresis counts from the last sent value, or when it reaches a rail (0 / 65535) moving toward it — so a settled pot is silent and the endpoints are always reached.

The ADC is re-read at most every pollMs — a constructor parameter, default DEFAULT_POLL_MS (8 ms). It is per instance, not per node: two AnalogInputs on one board may read at different rates, and PanelGroup owns no analog timer of its own (it calls poll() every iteration and lets each input decide). forceReport() samples fresh (bypassing the throttle) and emits the current value as the baseline. Integer EWMA (a shift, not a divide) keeps it cheap on the FPU-less STM32F103.

pollMs and ewmaShift are coupled: the filter time constant is τ ≈ 2^ewmaShift × pollMs — the defaults give 2^3 × 8 = 64 ms. Halving pollMs halves τ unless ewmaShift rises to match, so the two are chosen together, never one alone.

configure() does not enable internal pull-ups; the wiper drives the pin directly.

Used by: AN/ARC-51A VOL (volume potentiometer).

Public Static Attributes Documentation

variable DEFAULT_EWMA_SHIFT

EWMA α = 1/2^3 = 1/8.

constexpr uint8_t OpenSkyhawk::AnalogInput::DEFAULT_EWMA_SHIFT;

variable DEFAULT_HYSTERESIS

counts on the 16-bit output.

constexpr uint16_t OpenSkyhawk::AnalogInput::DEFAULT_HYSTERESIS;

variable DEFAULT_POLL_MS

default min interval between ADC reads (ms).

constexpr uint16_t OpenSkyhawk::AnalogInput::DEFAULT_POLL_MS;

variable MAX_EWMA_SHIFT

cap: scaled<<shift must fit int32 at full scale.

constexpr uint8_t OpenSkyhawk::AnalogInput::MAX_EWMA_SHIFT;

Public Functions Documentation

function AnalogInput

Construct a continuous analog input.

OpenSkyhawk::AnalogInput::AnalogInput (
    uint16_t controlId,
    PinRef pin,
    bool reverse=false,
    uint16_t minRaw=0,
    uint16_t maxRaw=65535,
    uint16_t hysteresis=DEFAULT_HYSTERESIS,
    uint8_t ewmaShift=DEFAULT_EWMA_SHIFT,
    uint16_t pollMs=DEFAULT_POLL_MS
) 

Parameters:

  • controlId DCSIN_* or CTRL_* constant. Determines PanelBridge routing.
  • pin analog PinRef (STM32 ADC GPIO or ADS1115 channel).
  • reverse false (default): minRaw → 0, maxRaw → 65535. true: inverted.
  • minRaw raw ADC value mapping to 0 (default 0). Readings below are clamped.
  • maxRaw raw ADC value mapping to 65535 (default 65535). Above are clamped.
  • hysteresis output counts of movement required before a new value is emitted.
  • ewmaShift EWMA smoothing strength: α = 1/2^ewmaShift (default 3 → 1/8). Capped to MAX_EWMA_SHIFT (15) — beyond that the int32 accumulator (scaled << shift) would overflow at full scale.
  • pollMs min interval between ADC reads, ms (default 8). Per instance, not per node. Not clamped: 0 means read every loop iteration, which is legal but makes τ track the loop rate — not a controlled quantity. An ADS1115 PinRef blocks ~8 ms per conversion whatever this says, so keep those at the default or higher.

function configure

Configure the pin as an input. Called by PanelGroup::setup() .

virtual void OpenSkyhawk::AnalogInput::configure () override

Implements OpenSkyhawk::InputBase::configure


function forceReport

Sample fresh (bypassing the throttle) and emit the current value as the baseline.

virtual void OpenSkyhawk::AnalogInput::forceReport () override

Implements OpenSkyhawk::InputBase::forceReport


function poll

Throttled ADC read + EWMA; emit when the value clears the hysteresis or a rail.

virtual void OpenSkyhawk::AnalogInput::poll () override

Implements OpenSkyhawk::InputBase::poll



The documentation for this class was generated from the following file Firmware/Libraries/PanelGroup/Inputs/AnalogInput/AnalogInput.h