You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
4.3 KiB
169 lines
4.3 KiB
4 years ago
|
#include <EEPROM.h>
|
||
|
|
||
|
#define MODES 6
|
||
|
|
||
|
#define pin_K1 8
|
||
|
#define pin_K2 7
|
||
|
#define pin_K3 6
|
||
|
#define pin_K4 5
|
||
|
#define pin_K5 4
|
||
|
#define pin_K6 3
|
||
|
|
||
|
struct state {
|
||
|
char name[4];
|
||
|
bool K1;
|
||
|
bool K2;
|
||
|
bool K3;
|
||
|
bool K4;
|
||
|
bool K5;
|
||
|
bool K6;
|
||
|
};
|
||
|
|
||
|
struct identifier {
|
||
|
char in1[16];
|
||
|
char in2[16];
|
||
|
char in3[16];
|
||
|
char out1[16];
|
||
|
char out2[16];
|
||
|
char out3[16];
|
||
|
};
|
||
|
|
||
|
struct identifier names;
|
||
|
|
||
|
const struct state matrix[] = {
|
||
|
{"123", 0, 0, 0, 0, 0, 0}, // IN1->OUT1 IN2->OUT2 IN3->OUT3
|
||
|
{"213", 1, 0, 1, 0, 0, 0}, // IN1->OUT2 IN2->OUT1 IN3->OUT3
|
||
|
{"312", 1 ,1, 1, 0, 1, 0}, // IN1->OUT3 IN2->OUT1 IN3->OUT2
|
||
|
{"132", 0 ,0, 1, 1, 1, 0}, // IN1->OUT1 IN2->OUT3 IN3->OUT2
|
||
|
{"231", 1 ,0 ,1, 1, 1, 1}, // IN1->OUT2 IN2->OUT3 IN3->OUT1
|
||
|
{"321", 1 ,1 ,0, 0, 1, 1}, // IN1->OUT3 IN2->OUT2 IN3->OUT1
|
||
|
};
|
||
|
|
||
|
void setup() {
|
||
|
pinMode(pin_K1, OUTPUT);
|
||
|
pinMode(pin_K2, OUTPUT);
|
||
|
pinMode(pin_K3, OUTPUT);
|
||
|
pinMode(pin_K4, OUTPUT);
|
||
|
pinMode(pin_K5, OUTPUT);
|
||
|
pinMode(pin_K6, OUTPUT);
|
||
|
|
||
|
EEPROM.get(0, names);
|
||
|
|
||
|
Serial.begin(9600);
|
||
|
}
|
||
|
|
||
|
void storeName(char *s, char *name, char *identifier) {
|
||
|
strncpy(s, name, strlen(name));
|
||
|
s[strlen(name) - 1] = '\0';
|
||
|
|
||
|
/* // FIXME WTF is this ugly crap??
|
||
|
Serial.print("parsing ");
|
||
|
Serial.print(identifier);
|
||
|
Serial.print(": ");
|
||
|
Serial.print(&name[1]);
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
void parseCommand() {
|
||
|
String s;
|
||
|
|
||
|
s = Serial.readString();
|
||
|
Serial.print("got: ");
|
||
|
Serial.println(s);
|
||
|
|
||
|
switch (s[0]) {
|
||
|
case 'i':
|
||
|
switch (s[1]) {
|
||
|
case '1':
|
||
|
storeName(names.in1, &s[1], "IN1");
|
||
|
break;
|
||
|
case '2':
|
||
|
storeName(names.in2, &s[1], "IN2");
|
||
|
break;
|
||
|
case '3':
|
||
|
storeName(names.in3, &s[1], "IN3");
|
||
|
break;
|
||
|
default:
|
||
|
Serial.println("unsupported option");
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case 'o':
|
||
|
switch (s[1]) {
|
||
|
case '1':
|
||
|
storeName(names.out1, &s[1], "OUT1");
|
||
|
break;
|
||
|
case '2':
|
||
|
storeName(names.out2, &s[1], "OUT2");
|
||
|
break;
|
||
|
case '3':
|
||
|
storeName(names.out3, &s[1], "OUT3");
|
||
|
break;
|
||
|
default:
|
||
|
Serial.println("unsupported option");
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
case '1':
|
||
|
case '2':
|
||
|
case '3':
|
||
|
Serial.println("yeah you propably entered another mode ;)");
|
||
|
break;
|
||
|
case 'h':
|
||
|
Serial.println(F("following commands are available:"));
|
||
|
Serial.println(F(" i1mygreatantenna - sets name of IN1 to mygreatantenna"));
|
||
|
Serial.println(F(" i2mygreatantenna - sets name of IN2 to mygreatantenna"));
|
||
|
Serial.println(F(" i3mygreatantenna - sets name of IN3 to mygreatantenna"));
|
||
|
Serial.println(F(" o1mygreatrig - sets name of OUT1 to mygreatrig"));
|
||
|
Serial.println(F(" o2mygreatrig - sets name of OUT2 to mygreatrig"));
|
||
|
Serial.println(F(" o3mygreatrig - sets name of OUT3 to mygreatrig"));
|
||
|
Serial.println(F(" r - print runtime settings"));
|
||
|
Serial.println(F(" w - store runtime settings to EEPROM"));
|
||
|
Serial.println(F(" 312 - switch to matrix IN1->OUT3 IN2->OUT1 IN3->OUT2 (example)"));
|
||
|
Serial.println(F(" h - print this help text"));
|
||
|
break;
|
||
|
case 'w':
|
||
|
EEPROM.put(0, names);
|
||
|
Serial.println("runtime settings stored in EEPROM");
|
||
|
break;
|
||
|
case 'r':
|
||
|
Serial.println(F("current runtime settings:"));
|
||
|
Serial.print(F("IN1: "));
|
||
|
Serial.println(names.in1);
|
||
|
Serial.print(F("IN2: "));
|
||
|
Serial.println(names.in2);
|
||
|
Serial.print(F("IN3: "));
|
||
|
Serial.println(names.in3);
|
||
|
Serial.print(F("OUT1: "));
|
||
|
Serial.println(names.out1);
|
||
|
Serial.print(F("OUT2: "));
|
||
|
Serial.println(names.out2);
|
||
|
Serial.print(F("OUT3: "));
|
||
|
Serial.println(names.out3);
|
||
|
Serial.println(F("REMEMBER to write to EEPROM with 'w'"));
|
||
|
Serial.println();
|
||
|
break;
|
||
|
default:
|
||
|
Serial.println(F("command not found - enter 'h' for help"));
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
for (int i = 0; i < MODES; i++) {
|
||
|
Serial.println(matrix[i].name);
|
||
|
digitalWrite(pin_K1, matrix[i].K1);
|
||
|
digitalWrite(pin_K2, matrix[i].K2);
|
||
|
digitalWrite(pin_K3, matrix[i].K3);
|
||
|
digitalWrite(pin_K4, matrix[i].K4);
|
||
|
digitalWrite(pin_K5, matrix[i].K5);
|
||
|
digitalWrite(pin_K6, matrix[i].K6);
|
||
|
|
||
|
delay(1000);
|
||
|
|
||
|
if (Serial.available() > 0) {
|
||
|
parseCommand();
|
||
|
}
|
||
|
}
|
||
|
}
|