From 79dd8ce44e363f83429230b0af153c36830b9bca Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 7 Jan 2017 22:37:07 +0000 Subject: [PATCH] Added working telegrm code --- .gitignore | 1 + action.lua | 27 ++++++++++++++++++++------- main.c | 16 +++++++++++----- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 020133c..a67c5f2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /sr /main /tglog.txt +socket diff --git a/action.lua b/action.lua index ec31a7b..cb79578 100644 --- a/action.lua +++ b/action.lua @@ -10,17 +10,30 @@ function on_msg_receive (msg) --local file = io.open("/home/pi/git/lights/tglog.txt", "w") --local timestr = os.date("%Y/%m/%d-%H:%M:%S") local message = "Invaild color" - if ((string.lower(msg.text)=='/purple') or (string.lower(msg.text)=='/p')) then - --message = ("purple|" .. timestr .. "|") - + if ((string.lower(msg.text)=='/red') or (string.lower(msg.text)=='/r')) then + tcp:send("r") + send_msg (msg.from.print_name, "Purple", ok_cb, false) + elseif ((string.lower(msg.text)=='/green') or (string.lower(msg.text)=='/g')) then + tcp:send("g") + send_msg (msg.from.print_name, "Green", ok_cb, false) + elseif ((string.lower(msg.text)=='/blue') or (string.lower(msg.text)=='/b')) then + tcp:send("b") + send_msg (msg.from.print_name, "Blue", ok_cb, false) + elseif ((string.lower(msg.text)=='/purple') or (string.lower(msg.text)=='/p')) then tcp:send("p") send_msg (msg.from.print_name, "Purple", ok_cb, false) - --file:write("purple|", timestr, "\n") - --file:write("p") - --file:close() elseif ((string.lower(msg.text)=='/yellow') or (string.lower(msg.text)=='/y')) then tcp:send("y") - send_msg (msg.from.print_name, "Uh, yella, I guess", ok_cb, false) + send_msg (msg.from.print_name, "Yellow", ok_cb, false) + elseif ((string.lower(msg.text)=='/cyan') or (string.lower(msg.text)=='/c')) then + tcp:send("c") + send_msg (msg.from.print_name, "Cyan", ok_cb, false) + elseif ((string.lower(msg.text)=='/off') or (string.lower(msg.text)=='/o')) then + tcp:send("o") + send_msg (msg.from.print_name, "Off", ok_cb, false) + elseif ((string.lower(msg.text)=='/white') or (string.lower(msg.text)=='/w')) then + tcp:send("w") + send_msg (msg.from.print_name, "White", ok_cb, false) end end diff --git a/main.c b/main.c index bb9dab2..327e99d 100644 --- a/main.c +++ b/main.c @@ -64,16 +64,18 @@ int main(void) { delay(1000); int ch; while((ch = getchar()) != EOF){ - if(ch == 'p') { - changeAllColors(PURPLE); - } else if (ch == 'y') { - changeAllColors(YELLOW); - } else if (ch == 'r') { + if (ch == 'r') { changeAllColors(RED); } else if (ch == 'g') { changeAllColors(GREEN); } else if (ch == 'b') { changeAllColors(BLUE); + } else if(ch == 'p') { + changeAllColors(PURPLE); + } else if (ch == 'y') { + changeAllColors(YELLOW); + } else if (ch == 'c') { + changeAllColors(CYAN); } else if (ch == 'o') { changeAllColors(OFF); } else if (ch == 'w') { @@ -82,6 +84,10 @@ int main(void) { printf("Invalid char"); continue; } + updateColors(); delay(1000); } + changeAllColors(OFF); + updateColors(); } +// vim: ts=2