Class Encoder

extends Object
An encoder for the RMT controller.
Encoders convert the input data to RMT signals by matching them against patterns.
Example
The following example implements a simple UART encoder at BAUD-RATE baud rate, with the RMT Out running at RESOLUTION Hz.

uart-period := RESOLUTION / BAUD-RATE

uart-start := rmt.Signals 2
// There must always be two signals, and neither must have a period of 0.
uart-start.set 0 --level=0 --period=uart-period - 1
uart-start.set 1 --level=0 --period=1

// A combination of the stop and start signals.
uart-between := rmt.Signals 2
uart-between.set 0 --level=1 --period=uart-period  // A stop bit.
uart-between.set 1 --level=0 --period=uart-period  // A start bit.

uart-stop := rmt.Signals 2
uart-stop.set 0 --level=1 --period=uart-period - 1
uart-stop.set 1 --level=1 --period=1

// Since we must always have two signals, we use a chunk-size of 2.
uart-00 := rmt.Signals 2
uart-00.set 0 --level=0 --period=uart-period
uart-00.set 1 --level=0 --period=uart-period
uart-01 := rmt.Signals 2
uart-01.set 0 --level=1 --period=uart-period
uart-01.set 1 --level=0 --period=uart-period
uart-10 := rmt.Signals 2
uart-10.set 0 --level=0 --period=uart-period
uart-10.set 1 --level=1 --period=uart-period
uart-11 := rmt.Signals 2
uart-11.set 0 --level=1 --period=uart-period
uart-11.set 1 --level=1 --period=uart-period
uart-start := Signals 1
uart-start.set 0 --level=0 --period=uart-period

encoder := Encoder
    --msb=false  // UART is LSB first.
    --start=uart-start
    --between=uart-between
    --stop=uart-stop
    {
      0b00: uart-00,
      0b01: uart-01,
      0b10: uart-10,
      0b11: uart-11,
    }

Class summary


constructor --start/Signals= --between/Signals= --stop/Signals= --msb/bool patterns/Map
Constructs an encoder for the given patterns.

Constructors

constructor --start/Signals=null --between/Signals=null --stop/Signals=null --msb/bool patterns/Map
Constructs an encoder for the given patterns.
The patterns map must have a size of 2, 4, or 16. The keys are the patterns (integers counting from 0 to 1/3/15) and the values are the signals that should be emitted for each pattern.
The start, between, and stop signals are optional.
The start signal is emitted when the transmission starts.
The between signal is emitted between each byte.
The stop signal is emitted when the transmission ends.
The msb parameter indicates whether the patterns are MSB first or LSB first.

Methods

close -> none

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).

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.