Skip to content

Commit

Permalink
Standard fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
albus522 committed Mar 10, 2023
1 parent fedf5cd commit aa03a86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pi/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ruby "3.2.1"

gem "action_cable_client"
gem "json"
gem "sd_notify"
gem "sd_notify"
17 changes: 8 additions & 9 deletions pi/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
require "action_cable_client"
require "sd_notify"

$running = true

if ENV["NOTIFY_SOCKET"]
STDOUT.reopen "listener.log", "a"
STDERR.reopen "listener.log", "a"
STDOUT.sync = true
STDERR.sync = true
$stdout.reopen "listener.log", "a"
$stderr.reopen "listener.log", "a"
$stdout.sync = true
$stderr.sync = true
end

class StopLight
Expand All @@ -25,6 +23,7 @@ class StopLight
@yellow = true
@green = true
@blink_state = true
@running = true

def self.startup
export_pin(RED_LED)
Expand Down Expand Up @@ -104,7 +103,7 @@ def self.start_client
EventMachine.run do
client = ActionCableClient.new("wss://#{HOST}/cable", params, true, headers)
client.connected { puts "[#{Time.now}] successfully connected." }
client.received do | message |
client.received do |message|
puts "[#{Time.now}] #{message["message"]["colors"]}"
set_colors(message["message"]["colors"])
end
Expand All @@ -122,12 +121,12 @@ def self.trap_signals

def self.shutdown
SdNotify.stopping
$running = false
@running = false
exit
end

def self.restart
return unless $running
return unless @running

puts "[#{Time.now}] restarting"
SdNotify.reloading
Expand Down

0 comments on commit aa03a86

Please sign in to comment.