Add working code

This commit is contained in:
Austen Adler 2017-01-27 06:27:47 +00:00
parent 79dd8ce44e
commit 0f260e1d9b
4 changed files with 14 additions and 8 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
/main /main
/tglog.txt /tglog.txt
socket socket
nohup.out

View File

@ -12,7 +12,7 @@ function on_msg_receive (msg)
local message = "Invaild color" local message = "Invaild color"
if ((string.lower(msg.text)=='/red') or (string.lower(msg.text)=='/r')) then if ((string.lower(msg.text)=='/red') or (string.lower(msg.text)=='/r')) then
tcp:send("r") tcp:send("r")
send_msg (msg.from.print_name, "Purple", ok_cb, false) send_msg (msg.from.print_name, "Red", ok_cb, false)
elseif ((string.lower(msg.text)=='/green') or (string.lower(msg.text)=='/g')) then elseif ((string.lower(msg.text)=='/green') or (string.lower(msg.text)=='/g')) then
tcp:send("g") tcp:send("g")
send_msg (msg.from.print_name, "Green", ok_cb, false) send_msg (msg.from.print_name, "Green", ok_cb, false)
@ -28,10 +28,10 @@ function on_msg_receive (msg)
elseif ((string.lower(msg.text)=='/cyan') or (string.lower(msg.text)=='/c')) then elseif ((string.lower(msg.text)=='/cyan') or (string.lower(msg.text)=='/c')) then
tcp:send("c") tcp:send("c")
send_msg (msg.from.print_name, "Cyan", ok_cb, false) send_msg (msg.from.print_name, "Cyan", ok_cb, false)
elseif ((string.lower(msg.text)=='/off') or (string.lower(msg.text)=='/o')) then elseif ((string.lower(msg.text)=='/off') or (string.lower(msg.text)=='/o') or (string.lower(msg.text)=='o')) then
tcp:send("o") tcp:send("o")
send_msg (msg.from.print_name, "Off", ok_cb, false) send_msg (msg.from.print_name, "Off", ok_cb, false)
elseif ((string.lower(msg.text)=='/white') or (string.lower(msg.text)=='/w')) then elseif ((string.lower(msg.text)=='/white') or (string.lower(msg.text)=='/w') or (string.lower(msg.text)=='w')) then
tcp:send("w") tcp:send("w")
send_msg (msg.from.print_name, "White", ok_cb, false) send_msg (msg.from.print_name, "White", ok_cb, false)
end end

15
main.c
View File

@ -2,8 +2,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#define LATCH_PIN 2 #define LATCH_PIN 2
#define CLOCK_PIN 0 #define CLOCK_PIN 3
#define DATA_PIN 3 #define DATA_PIN 0
#define OFF false, false, false #define OFF false, false, false
#define RED true, false, false #define RED true, false, false
#define GREEN false, true, false #define GREEN false, true, false
@ -20,7 +20,7 @@ bool colorField[] = {
false, // Right red false, // Right red
false, // Right green false, // Right green
false, // Right blue false, // Right blue
false, // Unused bit false, // Unused bit
false // Unused bit false // Unused bit
}; };
void write(bool mode) { void write(bool mode) {
@ -49,6 +49,8 @@ void changeColor(Side_t side, bool red, bool green, bool blue) {
colorField[shift] = red; colorField[shift] = red;
colorField[shift + 1] = green; colorField[shift + 1] = green;
colorField[shift + 2] = blue; colorField[shift + 2] = blue;
colorField[6] = red;
colorField[7] = green;
} }
void changeAllColors(bool red, bool green, bool blue) { void changeAllColors(bool red, bool green, bool blue) {
changeColor(LEFT, red, green, blue); changeColor(LEFT, red, green, blue);
@ -63,6 +65,8 @@ int main(void) {
updateColors(); updateColors();
delay(1000); delay(1000);
int ch; int ch;
//ch = 'w';
printf("Starting main loop\n");
while((ch = getchar()) != EOF){ while((ch = getchar()) != EOF){
if (ch == 'r') { if (ch == 'r') {
changeAllColors(RED); changeAllColors(RED);
@ -74,16 +78,17 @@ int main(void) {
changeAllColors(PURPLE); changeAllColors(PURPLE);
} else if (ch == 'y') { } else if (ch == 'y') {
changeAllColors(YELLOW); changeAllColors(YELLOW);
} else if (ch == 'c') { } else if (ch == 'c') {
changeAllColors(CYAN); changeAllColors(CYAN);
} else if (ch == 'o') { } else if (ch == 'o') {
changeAllColors(OFF); changeAllColors(OFF);
} else if (ch == 'w') { } else if (ch == 'w') {
changeAllColors(WHITE); changeAllColors(WHITE);
} else { } else {
printf("Invalid char"); printf("Invalid char\n");
continue; continue;
} }
printf("Changing to color: %c\n", ch);
updateColors(); updateColors();
delay(1000); delay(1000);
} }

0
sr.c Normal file → Executable file
View File