peteshadbolt.co.uk

 

begin remote
  name                        PROJ
  bits                        16
  flags                       SPACE_ENC|CONST_LENGTH
  header                      9000       4500
  one                         568        1704
  zero                        568        568
  gap                         100000
  pre_data_bits               16
  pre_data                    0x20f0
  frequency                   44000
  post_data_bits              1
  post_data                   0x1

  begin codes
      KEY_POWER               0xb54a
  end codes
end remote
"""
A very simple webserver which talks to LIRC
"""

from flask import Flask, request
import subprocess
app = Flask(__name__)

LOOKUP = {}
LOOKUP["amp_standby"] = ["NAD_SR712", "KEY_SLEEP"]
LOOKUP["amp_volumeup"] = ["NAD_SR712", "KEY_VOLUMEUP"]
LOOKUP["amp_volumedown"] = ["NAD_SR712", "KEY_VOLUMEDOWN"]
LOOKUP["proj_standby"] = ["PROJ", "KEY_POWER"]
LOOKUP["input_proj"] = ["NAD_SR712", "Input-Aux"]
LOOKUP["input_cd"] = ["NAD_SR712", "Input-CD"]

@app.route("/")
def main():
    """ Send commands to LIRC """
    cmd = request.args.get("cmd")
    target, command = LOOKUP.get(cmd, (None, None))
    if target:
        subprocess.call(["irsend", "SEND_ONCE", target, command])
        return f"Issued {command} to {target}"

if __name__ == "__main__":
    app.run()
- name: Install LIRC
  ignore_errors: yes
  apt:
      name: lirc
      state: present

- name: Add LIRC configuration file
  template:
    src: lirc_options.conf
    dest: /etc/lirc/lirc_options.conf

- name: Add LIRC remotes
  template:
    src: lircd.conf
    dest: /etc/lirc/lircd.conf

- name: Install LIRC again, this time there should be no errors
  apt:
      name: lirc
      state: fixed

- name: Configure GPIO
  blockinfile:
    path: /boot/config.txt
    block: |
        dtoverlay=gpio-ir,gpio_pin=18
        dtoverlay=gpio-ir-tx,gpio_pin=5

- name: Reboot
  reboot: