Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions | Variables
user_signals.h File Reference

Output user action signals on the serial and bluetooth links. More...

Go to the source code of this file.

Classes

struct  lampda::logic::user_signals::detail::Slot
 Rate limiting state of one signal. More...
 

Namespaces

namespace  lampda
 Program scope.
 
namespace  lampda::logic
 Handle the main high level logics.
 

Enumerations

enum  SlotId : size_t {
  slotBrightness = 0 , slotMode , slotRamp , slotIndicator ,
  slotCount
}
 

Functions

size_t lampda::logic::user_signals::format (char *buffer, const char *name, const uint32_t *values, const size_t valueCount)
 Format a signal, without the line end.
 
void lampda::logic::user_signals::send (const char *name, const uint32_t *values, const size_t valueCount)
 Format and send a signal immediately (no rate limiting)
 
Slot & lampda::logic::user_signals::detail::slot (const SlotId id)
 
bool lampda::logic::user_signals::detail::same_as_sent (const Slot &s)
 
void lampda::logic::user_signals::detail::flush (Slot &s, const uint32_t nowMs)
 Send the pending value if there is one and the interval since the latest send is over.
 
void lampda::logic::user_signals::detail::submit (const SlotId id, const uint32_t *values, const bool forceSend=false)
 Record the latest value of a signal and send it now if the interval allows.
 
void lampda::logic::user_signals::loop ()
 Send the pending signals whose interval is over Call it regularly, more often than signalIntervalMs.
 
void lampda::logic::user_signals::send_brightness (const uint32_t brightness)
 
void lampda::logic::user_signals::send_mode (const uint8_t groupId, const uint8_t modeId)
 
void lampda::logic::user_signals::send_ramp (const uint32_t ramp, const bool forceSend=false)
 
void lampda::logic::user_signals::send_indicator (const uint32_t level)
 

Variables

static constexpr size_t lampda::logic::user_signals::maxSignalLenght = 32
 Max signal lenght with the "\r\n" end, so that a signal is sent as one uart message (never interleaved with other prints)
 
static constexpr size_t lampda::logic::user_signals::maxFormatLenght = maxSignalLenght - 2
 Max formatted signal lenght, without the "\r\n" end and with the terminating null.
 
static constexpr uint32_t lampda::logic::user_signals::signalIntervalMs = 100
 Minimum time between two sends of the same signal.
 
static constexpr size_t lampda::logic::user_signals::detail::maxValues = 2
 

Detailed Description

Output user action signals on the serial and bluetooth links.

Each signal is a single line: '$' + name + ':' + values separated by ':' + "\r\n". The '$' prefix separates them from timestamped logs ("<time>> ..."). Names are short to avoid saturating slow outputs (BLE). This format is a public interface for external apps: do not change existing signals, only add new ones.

Rate limiting: each signal is sent at most once every signalIntervalMs. A change that arrives while the interval is running is not sent at once, only the latest value is kept and sent when the interval ends.

Call user_signals::loop() regularly (more often than signalIntervalMs) so that pending values get sent.

Function Documentation

◆ format()

size_t lampda::logic::user_signals::format ( char *  buffer,
const char *  name,
const uint32_t *  values,
const size_t  valueCount 
)
inline

Format a signal, without the line end.

Parameters
[out]bufferOutput, of size maxFormatLenght
[in]nameSignal name
[in]valuesSignal values
[in]valueCountNumber of values
Returns
The formatted lenght, 0 if the signal does not fit