Added working telegrm code

This commit is contained in:
Austen Adler 2017-01-07 22:37:07 +00:00
parent ef0f98688d
commit 79dd8ce44e
3 changed files with 32 additions and 12 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/sr /sr
/main /main
/tglog.txt /tglog.txt
socket

View File

@ -10,17 +10,30 @@ function on_msg_receive (msg)
--local file = io.open("/home/pi/git/lights/tglog.txt", "w") --local file = io.open("/home/pi/git/lights/tglog.txt", "w")
--local timestr = os.date("%Y/%m/%d-%H:%M:%S") --local timestr = os.date("%Y/%m/%d-%H:%M:%S")
local message = "Invaild color" local message = "Invaild color"
if ((string.lower(msg.text)=='/purple') or (string.lower(msg.text)=='/p')) then if ((string.lower(msg.text)=='/red') or (string.lower(msg.text)=='/r')) then
--message = ("purple|" .. timestr .. "|") 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") tcp:send("p")
send_msg (msg.from.print_name, "Purple", ok_cb, false) 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 elseif ((string.lower(msg.text)=='/yellow') or (string.lower(msg.text)=='/y')) then
tcp:send("y") 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
end end

16
main.c
View File

@ -64,16 +64,18 @@ int main(void) {
delay(1000); delay(1000);
int ch; int ch;
while((ch = getchar()) != EOF){ while((ch = getchar()) != EOF){
if(ch == 'p') { if (ch == 'r') {
changeAllColors(PURPLE);
} else if (ch == 'y') {
changeAllColors(YELLOW);
} else if (ch == 'r') {
changeAllColors(RED); changeAllColors(RED);
} else if (ch == 'g') { } else if (ch == 'g') {
changeAllColors(GREEN); changeAllColors(GREEN);
} else if (ch == 'b') { } else if (ch == 'b') {
changeAllColors(BLUE); changeAllColors(BLUE);
} else if(ch == 'p') {
changeAllColors(PURPLE);
} else if (ch == 'y') {
changeAllColors(YELLOW);
} else if (ch == 'c') {
changeAllColors(CYAN);
} else if (ch == 'o') { } else if (ch == 'o') {
changeAllColors(OFF); changeAllColors(OFF);
} else if (ch == 'w') { } else if (ch == 'w') {
@ -82,6 +84,10 @@ int main(void) {
printf("Invalid char"); printf("Invalid char");
continue; continue;
} }
updateColors();
delay(1000); delay(1000);
} }
changeAllColors(OFF);
updateColors();
} }
// vim: ts=2