Class Signals

extends Object
A collection of signals to be written or read with the RMT controller.
An RMT signal consists of a level (low or high) and a period (the number of ticks the level is sustained).
Advanced
The period is specified in number of ticks, so the actual time the level is sustained is determined by the RMT controller configuration.
At the lower level, a signal consists of 16 bits: 15 bits for the period and 1 bit for the level. Signals must be written as pairs also known as an item. For this reason, the bytes backing a collection of signal is always adjusted to be divisible by 4.

Class summary


constructor size/int --resolution/int=
Creates a collection of signals of the given size.

Constructors

constructor size/int --resolution/int=null
Creates a collection of signals of the given size.
All signals are initialized to 0 period and 0 level.
If a resolution is provided, it is used when signals are specified in us.
Advanced
The underlying RMT peripheral can only work on byte arrays that are divisible by 4 (equivalent to 2 signals).
This constructor always adds an end-marker signal.
In consequence, the size of the backing byte array might be 4 bytes larger than size * BYTES-PER-SIGNAL.

Statics

alternating --first-level/int periods/List -> Signals
Creates signals that alternate between a level of 0 and 1 with the periods given in the periods list.
The level of the first signal is first-level.

alternating --resolution/int --first-level/int --ns-durations/List -> Signals
Creates signals that alternate between a level of 0 and 1 with the periods given in the ns-durations list.
The level of the first signal is first-level.

alternating size/int --first-level/int [block] -> Signals
Creates items that alternate between a level of 0 and 1 with the periods given by successive calls to the block.
The block is called with the signal index and the level it is created with.
The level of the first signal is first-level.

alternating size/int --resolution/int --first-level/int [block] -> Signals
Creates items that alternate between a level of 0 and 1 with the ns-durations given by successive calls to the block.
The block is called with the signal index and the level it is created with.
The level of the first signal is first-level.

Bytes per ESP32 signal.

from-bytes bytes/ByteArray --resolution/int=null -> Signals
Creates a collection of signals from the given bytes.
The bytes size must be divisible by 4.
If a resolution is provided, it is used when signals are specified in us.
Advanced
The bytes must correspond to bytes produced by the RMT primitives. The primitives operate with pairs of signals (called an item) which is the reason the bytes size must be divisible by 4.

MAX-PERIOD -> any
The maximum period of a signal, in ticks.

ZERO -> any
An empty signals instance.
Deprecated. Signals should not be empty.

Methods

do [block] -> none
Invokes the given block on each signal of this signal collection.
The block is invoked with the level, period and ns duration of each signal. If this instance was created without a resolution, then the ns duration is null.

Returns the signal level of the i'th signal.
The given i must be in the range [0..size[.

Returns the signal duration of the i'th signal in nanoseconds.
This instance must have been created with a resolution during construction.
The given i must be in the range [0..size[.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Returns the signal period of the i'th signal.
The given i must be in the range [0..size[.

set i/int --period/int --level/int -> none
Sets the i'th signal to the given period and level.
The given i must be in the range [0..size[.
The given period must be in the range [0..0x7FFF].
The given level must be 0 or 1.

set i/int --ns/int --level/int -> none
Sets the i'th signal to the given ns duration and level.
This instance must have been created with a resolution during construction.
The given i must be in the range [0..size[.
The given ns is used to compute a corresponding period, which then must be in the range [0..0x7FFF].
The given level must be 0 or 1.

Fields

The resolution of the signals in Hz.
If this instance was created without a resolution, resolution is null.

The number of signals in the collection.