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
/tglog.txt
socket
nohup.out

View File

@ -12,7 +12,7 @@ function on_msg_receive (msg)
local message = "Invaild color"
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)
send_msg (msg.from.print_name, "Red", 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)
@ -28,10 +28,10 @@ function on_msg_receive (msg)
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
elseif ((string.lower(msg.text)=='/off') or (string.lower(msg.text)=='/o') 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
elseif ((string.lower(msg.text)=='/white') or (string.lower(msg.text)=='/w') or (string.lower(msg.text)=='w')) then
tcp:send("w")
send_msg (msg.from.print_name, "White", ok_cb, false)
end

15
main.c
View File

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

0
sr.c Normal file → Executable file
View File