# Decoder for Heatilator gas log remotes.
# 
# Heatilator gas logs use OOK_PULSE_PPM encoding. The format is very similar to
# that decoded by 'generic_remote', but seems to differ slightly in timing. The
# device does _not_ use a discrete chip to generate the waveform; it's generated
# in code.
# 
# The packet starts with 380 uS start pulse followed by an eternity (14.3 mS) of silence.
# - 0 is defined as a 1430 uS pulse followed by a 460 uS gap.
# - 1 is defined as a 380 uS pulse followed by a 1420 uS gap.
# 
# Transmissions consist of the start bit followed by 24 data bits. These packets are
# repeated many times.
# 
# Because there's such a long start bit/preamble, the decoder usually creates the first
# row with a single bit, followed by 'n' rows with 25 bits (the 24 data bits and the
# start bit of the following packet), then the last row with the expected 24 bits.
# 
# Packet layout:
# 
#      Bit number
#      0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23
#      - - - - - - - - - - DEVICE SERIAL NUMBER - - - - - - - - - |- COMMAND -
# 
# The device serial number is (presumedly) burned into the device when manufactured.
# The command is further broken down into the following bits:
# 
#     20 21 22 23
#     X  X  S  T
# 
# X bits are unknown in function. S is the 'state' of the gas valve/flame. S = 0
# means 'flame off'. S = 1 means 'flame on'. T indicates whether or not the remote
# is in 'thermo' mode - this is a mode where the remote detects the room temperature
# and commands the gas logs on/off to maintain the temperature selected on the remote.
# 
# There are safety mechanisms afoot - whenever the gas logs are 'on', on with a timer,
# or on in thermo mode, occasional 'keepalive' messages are sent to the gas logs to
# guarantee that the remote is still in range and the batteries are not dead. Generally
# these messages are exactly the same as the last command that the remote sent - that is,
# if you turn the logs 'on' manually, the remote will send the same 'on' command every so
# often.
# 
# The COMMAND S and T bits have these meanings:
#     S  T
#     ----
#     0  0 - Off, Manual mode
#     0  1 - Off, Thermo mode (room is too warm)
#     1  0 - On,  Manual mode.
#     1  1 - On,  Thermo more (room is too cold)

frequency 433.92M

decoder {
    name        = Heatilator-gas-log-remote,
    modulation  = OOK_PWM,
    short       = 380,
    long        = 1420,
    gap         = 0,
    reset       = 1800,
    bits        >= 24,
    bits        <= 25,
    get         = id:@0:{20},
    get         = state:@22:{1}:[0:flame_off 1:flame_on],
    get         = mode:@23:{1}:[0:manual 1:thermo],
}
