wareck 3 years ago
parent
commit
4612f4ac73
4 changed files with 122 additions and 1 deletions
  1. 2 1
      rtc.sh
  2. 76 0
      scripts/silly_clock.py
  3. 3 0
      scripts/text.sh
  4. 41 0
      scripts/view_message.py

+ 2 - 1
rtc.sh

@@ -21,7 +21,8 @@ echo -e
 if [ $DietPi_ = "YES" ]
 then
 echo -e "\e[38;5;154mDietpi\e[0m image detected:"
-echo -e "This script will enable /etc/rc.local for AutoStart (disabled by default on Dietpi).\n"
+echo -e "This script will enable /etc/rc.local for AutoStart"
+echo -e "(disabled by default on Dietpi).\n"
 fi
 read -n 1 -r -s -p "Press any key to continue..."
 

+ 76 - 0
scripts/silly_clock.py

@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+import time
+from datetime import datetime
+
+from luma.led_matrix.device import max7219
+from luma.core.interface.serial import spi, noop
+from luma.core.render import canvas
+from luma.core.legacy import text, show_message
+from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT
+
+jours = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"]
+mois = ["Janvier", u"Février", "Mars", "Avril", "Mai", "Juin", "Juillet", u"Août", "Septembtre", "Octobre"]
+
+def minute_change(device):
+    '''When we reach a minute change, animate it.'''
+    hours = datetime.now().strftime('%H')
+    minutes = datetime.now().strftime('%M')
+
+    def helper(current_y):
+        with canvas(device) as draw:
+            text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT))
+            text(draw, (15, 1), ":", fill="white", font=proportional(TINY_FONT))
+            text(draw, (17, current_y), minutes, fill="white", font=proportional(CP437_FONT))
+        time.sleep(0.1)
+    for current_y in range(1, 9):
+        helper(current_y)
+    minutes = datetime.now().strftime('%M')
+    for current_y in range(9, 1, -1):
+        helper(current_y)
+
+
+def animation(device, from_y, to_y):
+    '''Animate the whole thing, moving it into/out of the abyss.'''
+    hourstime = datetime.now().strftime('%H')
+    mintime = datetime.now().strftime('%M')
+    current_y = from_y
+    while current_y != to_y:
+        with canvas(device) as draw:
+            text(draw, (0, current_y), hourstime, fill="white", font=proportional(CP437_FONT))
+            text(draw, (15, current_y), ":", fill="white", font=proportional(TINY_FONT))
+            text(draw, (17, current_y), mintime, fill="white", font=proportional(CP437_FONT))
+        time.sleep(0.1)
+        current_y += 1 if to_y > from_y else -1
+
+
+def main():
+    # Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb)
+    serial = spi(port=0, device=0, gpio=noop())
+    device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=False)
+    device.contrast(16)
+
+    # The time ascends from the abyss...
+    animation(device, 8, 1)
+
+    toggle = False  # Toggle the second indicator every second
+    while True:
+        toggle = not toggle
+        sec = datetime.now().second
+        if sec == 59:
+            # When we change minutes, animate the minute change
+            minute_change(device)
+        else:
+            # Do the following twice a second (so the seconds' indicator blips).
+            # I'd optimize if I had to - but what's the point?
+            # Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores!
+            hours = datetime.now().strftime('%H')
+            minutes = datetime.now().strftime('%M')
+            with canvas(device) as draw:
+                text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT))
+                text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT))
+                text(draw, (17, 1), minutes, fill="white", font=proportional(CP437_FONT))
+            time.sleep(0.5)
+
+
+if __name__ == "__main__":
+    main()

+ 3 - 0
scripts/text.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+python3 view_message.py -t "Ma biche d'amour....je peux avoir un petit café ? merci mamour....tu peut envoyer grosse tete..."
+./text.sh

+ 41 - 0
scripts/view_message.py

@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Commandline Wrapper
+# Thomas Wenzlaff
+# See LICENSE.rst for details.
+
+import time
+import argparse
+
+from luma.led_matrix.device import max7219
+from luma.core.interface.serial import spi, noop
+from luma.core.legacy import show_message
+from luma.core.legacy.font import proportional, CP437_FONT
+
+
+def output(n, block_orientation, rotate, inreverse, text):
+    # create matrix device
+    serial = spi(port=0, device=0, gpio=noop())
+    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,
+                     rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
+    print(text)
+
+    show_message(device, text, fill="white", font=proportional(CP437_FONT), scroll_delay=0.05)
+    time.sleep(1)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='view_message arguments',
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+
+    parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
+    parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
+    parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
+    parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')
+    parser.add_argument('--text', '-t', default='>>> No text set', help='Set text message')
+    args = parser.parse_args()
+
+    try:
+        output(args.cascaded, args.block_orientation, args.rotate, args.reverse_order, args.text)
+    except KeyboardInterrupt:
+        pass