Skip to content

Instantly share code, notes, and snippets.

@wararyo
Last active November 20, 2021 04:39
Show Gist options
  • Save wararyo/ccadc218e8c7635d11076188a62dc068 to your computer and use it in GitHub Desktop.
Save wararyo/ccadc218e8c7635d11076188a62dc068 to your computer and use it in GitHub Desktop.
赤外線リモコンコンセント 07-8251 OCR-05W をMoonrakerで使用する
{"printer:off": [2562, 2684, 818, 872, 818, 1912, 818, 872, 818, 872, 818, 1912, 818, 872, 818, 1912, 818, 1912, 818, 54139, 2562, 2684, 818, 872, 818, 1912, 818, 872, 818, 872, 818, 1912, 818, 872, 818, 1912, 818, 1912, 818],
"printer:on": [2562, 2684, 818, 872, 818, 872, 818, 1912, 818, 1912, 818, 1912, 818, 1912, 818, 872, 818, 872, 818, 54139, 2562, 2684, 818, 872, 818, 872, 818, 1912, 818, 1912, 818, 1912, 818, 1912, 818, 872, 818, 872, 818]}
# コピペで実行した方が良いです
# 依存パッケージ等のインストール
sudo apt-get install pigpio
sudo apt-get install python3-pip
sudo pip3 install pigpio
sudo systemctl enable pigpiod.service
sudo systemctl start pigpiod
# 作業ディレクトリにファイルを配置
mkdir moonraker_ir_bridge
cd moonraker_ir_bridge
curl http://abyz.me.uk/rpi/pigpio/code/irrp_py.zip | zcat > irrp.py
# codes.jsonとmoonraker_ir_bridge.pyもこのディレクトリに配置する
# デーモンとして登録
sudo systemctl daemon-reload
sudo systemctl enable moonraker_ir_bridged
sudo systemctl start moonraker_ir_bridged
[power Printer]
type: gpio
pin: gpio25
off_when_shutdown: True
initial_state: on
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pigpio
import time
import subprocess
pi = pigpio.pi()
pi.set_mode(24, pigpio.INPUT)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)
def cb_interrupt(gpio, level, tick):
print (gpio, level, tick)
if level == 0:
subprocess.run('./irrp.py -p -g23 -f codes printer:off', shell=True)
else:
subprocess.run('./irrp.py -p -g23 -f codes printer:on', shell=True)
cb = pi.callback(24, pigpio.EITHER_EDGE, cb_interrupt)
if __name__ == "__main__":
while True:
time.sleep(5)
# /usr/lib/systemd/system/moonraker_ir_bridged.serviceに配置します
[Unit]
Description=sample daemon
[Service]
ExecStart=/home/pi/moonraker_ir_bridge/moonraker_ir_bridge.py
WorkingDirectory=/home/pi/moonraker_ir_bridge
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
[gcode_macro POWER_OFF_PRINTER]
gcode:
{action_call_remote_method("set_device_power",
device="Printer",
state="off")}
[delayed_gcode delayed_printer_off]
initial_duration: 0.
gcode:
{% if printer.idle_timeout.state == "Idle" %}
POWER_OFF_PRINTER
{% endif %}
[idle_timeout]
gcode:
TURN_OFF_MOTORS
TURN_OFF_HEATERS
UPDATE_DELAYED_GCODE ID=delayed_printer_off DURATION=60
timeout: 900
14 GND -> IR_LED Cathode
16 GPIO23 -> IR_LED Anode
18 GPIO24 -> GPIO25
20 GND
22 GPIO25 -> GPIO24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment