Permalink
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
Cannot retrieve contributors at this time.
Cannot retrieve contributors at this time
| #! /usr/bin/perl -w | |
| # Script to watch D-BUS for notify messages and update the ErgoDox Infinity display | |
| # Still very rough | |
| # Dependency: libnet-dbus-perl on Debian | |
| # ================================================================================================= | |
| # Front matter | |
| # ================================================================================================= | |
| use strict; | |
| use v5.12; | |
| # Set this to your ErgoDox serial port (e.g., /dev/ttyACM0, etc.) | |
| my $TTY = "DEFINE-ME"; | |
| use Net::DBus; | |
| use Net::DBus::Reactor; | |
| use Net::DBus::Binding::Bus; | |
| use Time::HiRes qw(usleep); | |
| my $notifications = 0; | |
| # ================================================================================================= | |
| # Main script | |
| # ================================================================================================= | |
| # Need the Binding::Bus type, otherwise can't use add_match() below | |
| my $bus = Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SESSION); | |
| # eavesdrop is required because Notify messages aren't for us | |
| # for some reason, need to filter for Notify here AND check member in notify_filter() | |
| $bus -> add_match("type='method_call',interface='org.freedesktop.Notifications',member='Notify'," . | |
| "eavesdrop='true'"); | |
| # NotificationClosed is broadcast, so don't need to eavesdrop it | |
| $bus -> add_match("type='signal',interface='org.freedesktop.Notifications'," . | |
| "member='NotificationClosed'"); | |
| $bus -> add_filter(\¬ify_filter); | |
| $bus -> add_filter(\&closed_filter); | |
| my $reactor = Net::DBus::Reactor->new(); | |
| $reactor -> manage($bus); | |
| $reactor -> run(); | |
| # End of script | |
| # ================================================================================================= | |
| # Subroutines | |
| # ================================================================================================= | |
| sub notify_filter | |
| { | |
| my $con = shift; | |
| my $msg = shift; | |
| my $type = $msg -> get_member(); | |
| return 0 if (!defined($type)); | |
| return 0 if ($type ne 'Notify'); | |
| # I *think* transients don't show up in notifications applet and shouldn't be counted | |
| # This includes notifications for things like unplugging the ethernet cable | |
| my @vals = $msg -> get_args_list(); | |
| foreach my $v (@vals) | |
| { | |
| return 0 if (ref($v) eq 'HASH' and exists($v->{'transient'}) and $v->{'transient'}); | |
| } | |
| $notifications++; | |
| display_count(); | |
| } | |
| sub closed_filter | |
| { | |
| my $con = shift; | |
| my $msg = shift; | |
| my $type = $msg -> get_member(); | |
| if (defined($type) and $type eq 'NotificationClosed' and $notifications) | |
| { | |
| $notifications--; | |
| display_count(); | |
| } | |
| } | |
| sub display_count | |
| { | |
| system('printf "lcdInit\r" >' . $TTY); | |
| usleep 100_000; | |
| if ($notifications == 0) | |
| { | |
| # Y X 0 1 2 3 4 5 6 7 8 9 A B C D E F | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0x1076 0x0F31 0x0C95\r">' . $TTY); | |
| } | |
| elsif ($notifications == 1) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| elsif ($notifications == 2) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| elsif ($notifications == 3) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| elsif ($notifications == 4) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| elsif ($notifications == 5) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| elsif ($notifications > 5) | |
| { | |
| system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x80 0x80\r">' . $TTY); | |
| system('printf "lcdDisp 0x0 0x70 0x80 0x80 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x1 0x70 0xff 0xff 0xff 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff\r">' . $TTY); | |
| system('printf "lcdDisp 0x2 0x70 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x01 0x01\r">' . $TTY); | |
| system('printf "lcdDisp 0x3 0x70 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY); | |
| system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY); | |
| } | |
| } |