Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions lib/device_recipes/dream_cheeky/webmail_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
module Blinky
module DreamCheeky
module WebmailNotifier
COLOURS = {
:black => "000000",
:white => "ffffff",
:green => "00ff00",
:red => "ff0000",
:blue => "0000ff",
:orange => "ff2a00",
:teal => "00ffff",
:yellow => "ffff00",
:pink => "ff00ff"
}

COLOURS.each do |name, hex_code|
define_method(name) do
colour_hex!(hex_code)
end
end

alias :success! :green
alias :failure! :red
alias :building! :blue
alias :warning! :orange
alias :off! :black

def success!
colour!("\x00\xFF\x00")
end

def failure!
colour!("\xFF\x00\x00")
end

def building!
colour!("\x00\x00\xFF")
def init
send_data "\x1f\x02\x00\x2e\x00\x00\x2b\x03"
send_data "\x00\x02\x00\x2e\x00\x00\x2b\x04"
send_data "\x00\x00\x00\x2e\x00\x00\x2b\x05"
end

def warning!
colour!("\xFF\x2A\x00")
def colour!(colour)
send_data(colour + "\x00\x00\x00\x00\x05")
end

def off!
colour!("\x00\x00\x00")
def colour_rgb!(red, green, blue)
hex_sequence = [red, green, blue].map(&:chr).join
colour!(hex_sequence)
end

def init
send "\x1f\x02\x00\x2e\x00\x00\x2b\x03"
send "\x00\x02\x00\x2e\x00\x00\x2b\x04"
send "\x00\x00\x00\x2e\x00\x00\x2b\x05"
end
def colour_hex!(hex_code)
rgb_values = hex_code.scan(/\h{2}/).take(3).map do |n|
n.to_i(16)
end

def colour!(colour)
send(colour + "\x00\x00\x00\x00\x05")
colour_rgb!(*rgb_values)
end

private
def send(data)

def send_data(data)
@handle.usb_control_msg(0x21, 0x09, (3 << 8) | 1, 0, data, 0)
end

Expand Down