Verified Commit 20dd6e07 authored by Vojtech Myslivec's avatar Vojtech Myslivec
Browse files

Drop support for Turris 1.x

This reverts previous commit and add a justification why it is not
supported on Turris 1.x
parent a6713f84
# Christmas
Shine Turris router like a Christmas tree.
Shine Turris Omnia like a Christmas tree.
## Description
A Python daemon for Turris router to blink its RGB LEDs like a Christmas tree.
A Python daemon for Turris Omnia to blink its RGB LEDs like a Christmas tree.
This script uses `rainbow` command and so it is supported on *Omnia* and
*Turris 1.x* routers at the moment. MOX has only one red diode and so no big
effect can be achieved there.
Only *Omnia* is supported because MOX does not have RGB LED(s) and *Turris 1.x*
LAN leds can not be controlled separately (5 out of 8 diodes must share the
same color).
---
......
......@@ -5,19 +5,19 @@ Christmas main module
from random import random, choice
from time import sleep
from .helpers import usage, trap_signals, cleanup, get_leds_list
from .helpers import usage, trap_signals, cleanup
from .rainbow import disable_leds, set_led
from .default_settings import COLORS, ENABLE_PROBABILITY, SLEEP_MAX
from .default_settings import COLORS, ENABLE_PROBABILITY, LEDS, SLEEP_MAX
def blink(leds):
def blink():
if random() < ENABLE_PROBABILITY:
random_state = "enable"
else:
random_state = "disable"
random_led = choice(leds)
random_led = choice(LEDS)
random_color = choice(COLORS)
set_led(random_led, random_state)
......@@ -26,12 +26,11 @@ def blink(leds):
def main():
usage()
led_list = get_leds_list()
trap_signals()
disable_leds()
while True:
blink(led_list)
blink()
random_sleep = random() * SLEEP_MAX
sleep(random_sleep)
......
......@@ -15,3 +15,19 @@ COLORS = (
"FF6600", # yellow
"FF0000", # red
)
# list of Turris Omnia leds
LEDS = (
'pwr',
'lan0',
'lan1',
'lan2',
'lan3',
'lan4',
'wan',
'pci1',
'pci2',
'pci3',
'usr1',
'usr2',
)
"""
Christmas exceptions
"""
class ChristmasError(Exception):
pass
......@@ -5,8 +5,7 @@ Miscellaneous helpers for christmas
import sys
import signal
from .exceptions import ChristmasError
from .rainbow import restart_leds, device_leds_list
from .rainbow import restart_leds
USAGE = """USAGE:
......@@ -36,11 +35,3 @@ def trap_signals():
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGHUP, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
def get_leds_list():
try:
return device_leds_list()
except (FileNotFoundError, PermissionError, ChristmasError) as e:
errprint("error: Can not determine LED list: {}".format(e))
sys.exit(2)
......@@ -4,33 +4,6 @@ Control LEDs for christmas
from subprocess import call
from .exceptions import ChristmasError
SYSINFO_MODEL_FILE = "/tmp/sysinfo/model"
LEDS_OMNIA = (
'pwr',
'lan0',
'lan1',
'lan2',
'lan3',
'lan4',
'wan',
'pci1',
'pci2',
'pci3',
'usr1',
'usr2',
)
LEDS_TURRIS = (
'wan',
'lan',
'wifi',
'pwr',
)
def restart_leds():
call(["/etc/init.d/rainbow", "restart"])
......@@ -42,20 +15,3 @@ def disable_leds():
def set_led(led_device, led_option):
call(["rainbow", led_device, led_option])
def first_line_of_file(filename):
with open(filename, "r") as f:
line = f.readline()
return line.rstrip("\n")
def device_leds_list():
model_name = first_line_of_file(SYSINFO_MODEL_FILE)
if model_name == "Turris Omnia":
return LEDS_OMNIA
elif model_name == "Turris":
return LEDS_TURRIS
else:
raise ChristmasError("Device not supported")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment